不懂哦,这东西真是无聊
#include "stdio.h"
#include "math.h"
#define A 0 /*定义初值和步长*/
#define B 0.002
#define C 1
#define D 1
#define E 1
double f(double,double,double,double); /* 定义函数*/
double g(double,double,double,double);
double e(double,double,double,double);
main()
{
double x0=A, h=B, y01=C, u01=D, v01=E,
double jn[4], kn[4], ln[4]; /* j01 -- j04 k01 -- k04 l01 -- l04 */
int i,n=10000;
FILE *cfPtr;
if((cfPtr=fopen("luolunzi.dat","w"))==NULL) /*数据要写入的文件*/
printf("File could not be opened\n");
else
{
for (i=1;i <=n;i++)
{ /*套用公式开始计算*/
x0=x0+h;
jn[0]=f(x0,y01,u01,v01);
kn[0]=g(x0,y01,u01,v01);
ln[0]=e(x0,y01,u01,v01);
jn[1]=f(x0+h/2.0,y01+h/2.0*jn[0],u01+h/2.0*kn[0],v01+h/2.0*ln[0]);
kn[1]=g(x0+h/2.0,y01+h/2.0*jn[0],u01+h/2.0*kn[0],v01+h/2.0*ln[0]);
ln[1]=e(x0+h/2.0,y01+h/2.0*jn[0],u01+h/2.0*kn[0],v01+h/2.0*ln[0]);
jn[2]=f(x0+h/2.0,y01+h/2.0*jn[1],u01+h/2.0*kn[1],v01+h/2.0*ln[1]);
kn[2]=g(x0+h/2.0,y01+h/2.0*jn[1],u01+h/2.0*kn[1],v01+h/2.0*ln[1]);
ln[2]=e(x0+h/2.0,y01+h/2.0*jn[1],u01+h/2.0*kn[1],v01+h/2.0*ln[1]);
jn[3]=f(x0+h,y01+h*jn[1],u01+h*kn[1],v01+h*ln[1]);
kn[3]=g(x0+h,y01+h*jn[1],u01+h*kn[1],v01+h*ln[1]);
ln[3]=e(x0+h,y01+h*jn[1],u01+h*kn[1],v01+h*ln[1]);
y01=y01+h/6.0*(jn[0]+2.0*jn[1]+2.0*jn[2]+jn[3]);
u01=u01+h/6.0*(kn[0]+2.0*kn[1]+2.0*kn[2]+kn[3]);
v01=v01+h/6.0*(ln[0]+2.0*ln[1]+2.0*ln[2]+ln[3]);
printf("%15.7f\t%15.7f\t%15.7f\t\n",x0,y01,u01,v01);
fprintf(cfPtr,"%15.7f\t%15.7f\t%15.7f\t\n",x0,y01,u01,v01);
}
fclose(cfPtr);
}
}
double f(double s1,double q1,double u1,double r1) /*定义的微分方程*/
{
double z1;
z1=-10*q1+(10*u1);
return z1;
}
double g(double s2,double q2,double u2,double r2)
{
double z2;
z2=28*q2-u2-q2*r2;
return z2;
}
double e(double s3,double q3,double u3,double r3)
{
double z3;
z3=(-8/3)*r3+q3*u3;
return z3;
}