• 大小: 4KB
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签: adams算法  

资源简介

使用四阶龙格库塔法起步,用adams算法进行数值求解。可求解四阶微分方程。

资源截图

代码片段和文件信息

#include
#include

double functionA(double tdouble wdouble xdouble ydouble z);

double functionB(double tdouble wdouble xdouble ydouble z);

double functionC(double tdouble wdouble xdouble ydouble z);

double functionD(double tdouble wdouble xdouble ydouble z);

int main()
{


//int RungeKutta(double timedouble y0double z0double hdouble *tdouble *ydouble *zdouble functionA(tyz)double functionB(tyz))
{

double k11k21k31k41k12k22k32k42k13k23k33k43k14k24k34k44;
double timew0=0x0=0y0=0z0=0httawwaxxayyazzawcawpaxcaxpaycaypazcazpawcxcyczcM[4]N[4]O[4]P[4]T[4]w1w2w3w4x1x2x3x4y1y2y3y4z1z2z3z4t1t2t3t4;
int ij;
    time=10;
t=0;
w=w0;
x=x0;
y=y0;
z=z0;
h=0.01;
FILE *fpWrite=fopen(“adams.txt““w“);//创建数据存储文件 
if(fpWrite==NULL)
{
return 0;
}
fprintf(fpWrite“ t w x y z \n“);//文件标题 


for(i=0;i<4;i++)//龙格库塔法起步 
{


M[i]=w;
N[i]=x;
O[i]=y;
P[i]=z;
T[i]=t;
ta=t+h; 
k11=h*functionA(twxyz); 
k21=h*functionB(twxyz);
k31=h*functionC(twxyz);
k41=h*functionD(twxyz);

k12=h*functionA(t+h/2w+k11/2x+k21/2y+k31/2z+k41/2);
k22=h*functionB(t+h/2w+k11/2x+k21/2y+k31/2z+k41/2);
k32=h*functionC(t+h/2w+k11/2x+k21/2y+k31/2z+k41/2);
k42=h*functionD(t+h/2w+k11/2x+k21/2y+k31/2z+k41/2);

k13=h*functionA(t+h/2w+k12/2x+k22/2y+k32/2z+k42/2);
k23=h*functionB(t+h/2w+k12/2x+k22/2y+k32/2z+k42/2);
k33=h*functionC(t+h/2w+k12/2x+k22/2y+k32/2z+k42/2);
k43=h*functionD(t+h/2w+k12/2x+k22/2y+k32/2z+k42/2);

k14=h*functionA(t+hw+k13x+k23y+k33z+k43);
k24=h*functionB(t+hw+k13x+k23y+k33z+k43);
k34=h*functionD(t+hw+k13x+k23y+k33z+k43);
k44=h*functionC(t+hw+k13x+k23y+k33z+k43);

wa=y+(k11+2*k12+2*k13+k14)/6;
xa=y+(k21+2*k22+2*k23+k24)/6;
ya=y+(k31+2*k32+2*k33+k34)/6;
za=z+(k41+2*k42+2*k43+k44)/6;

t=ta;
w=wa;
x=xa;
y=ya;
z=za;
printf(“M[%d]=%f N[%d]=%

评论

共有 条评论

相关资源