Код программы для диф. уравнения 1-ого порядка:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <time.h>
using namespace std;
float func(float x, float y)
{
return y*y-2*x/(2*x*y);
}
int main()
{
clock_t start = clock();
int i=0, m=50, a, b, c;
const int n=100;
float k1, k2, k3, k4, x, yi, h=0.001, f[n];
const float x0=1;
float yy0=3;
yi=yy0;
f[0]=func(x0,yy0);
i=1;
for (x=x0; x<=x0+3*h;)
{
k1=h*func(x,yi);
k2=h*func(x+h/2,yi+k1/2);
k3=h*func(x+h/2,yi+k2/2);
k4=h*func(x+h,yi+k3);
yi+=(k1+2*k2+2*k3+k4)/6;
f[i]=func(x+h,yi);
i+=1;
x+=h;
printf("x=%3.4f ", x);
printf("yi=%3.4f ", yi);
printf("yt=%3.4f ", sqrt(9*x-2*x*log(x)));
printf("|yt-yi|=%3.10f", fabs(sqrt(9*x-2*x*log(x))-yi));
printf("\n");
}
x+=h;
a=1;
b=2;
c=3;
for(i=0; i<m; i++)
{
yi=yi+(h/24)*(55*f[i+3]-59*f[i+2]+37*f[i+1]-9*f[i]);
printf("x=%3.4f ", x);
printf("yi=%3.4f ", yi);
printf("yt=%3.4f ", sqrt(9*x-2*x*log(x)));
printf("|yt-yi|=%3.10f", fabs(sqrt(9*x-2*x*log(x))-yi));
printf("\n");
f[i+1]=f[a];
a+=1;
f[i+2]=f[b];
b+=1;
f[i+3]=f[c];
c+=1;
f[i+4]=func(x, yi);
x+=h;
}
printf("Work time = %.11Lf", (long double)((clock() - 1.0L*start)/CLOCKS_PER_SEC));
system("pause");
return 0;
}
Результаты: