《龍格庫(kù)塔算法解微分方程組c語(yǔ)言》由會(huì)員分享,可在線(xiàn)閱讀,更多相關(guān)《龍格庫(kù)塔算法解微分方程組c語(yǔ)言(2頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、文檔供參考,可復(fù)制、編制,期待您的好評(píng)與關(guān)注!
/***************************************************************************
This program is to solve the initial value problem of following system
of differential equations:
dx/dt=x+2*y,x(0)=0,
dy/dt=2*x+y,y(0)=2,
x(0.2) and y(0.2) are to be calculated
***********
2、*****************************************************************/
#include
#include
#define steplength 0.1 //步?長(zhǎng)?è可¨|根¨′據(jù)Y需¨¨要°a調(diào)ì??整?;
#define FuncNumber 2 //FuncNumber為a微?é分¤?方¤?程¨?的ì?數(shù)oy目?;
void main()
{
float x[200],Yn[20][200],reachpoint;int i;
x[0]=0;Yn[0][0]=0;Yn[1
3、][0]=2; //初?值|ì條??件t;
reachpoint=0.2; //所¨′求¨?點(diǎn)ì?可¨|根¨′據(jù)Y需¨¨要°a調(diào)ì??整?;
void rightfunctions(float x ,float *Auxiliary,float *Func);
void Runge_Kutta(float *x,float reachpoint, float(*Yn)[200]);
Runge_Kutta(x ,reachpoint, Yn);
printf("x ");
for(i=0;i<=(reachpoi
4、nt-x[0])/steplength;i++)
printf("%f ",x[i]);
printf("\nY1 ");
for(i=0;i<=(reachpoint-x[0])/steplength;i++)
printf("%f ",Yn[0][i]);
printf("\nY2 ");
for(i=0;i<=(reachpoint-x[0])/steplength;i++)
printf("%f ",Yn[1][i]);
getchar();
}
void rightfunctions(float x ,float *Auxiliary,flo
5、at *Func)//當(dāng)ì?à右?¨°方¤?程¨?改?變à?時(shí)o?à,ê?需¨¨要°a改?變à?;
{
Func[0]=Auxiliary[0]+2*Auxiliary[1];
Func[1]=2*Auxiliary[0]+Auxiliary[1];
}
void Runge_Kutta(float *x,float reachpoint, float(*Yn)[200])
{
int i,j;
float Func[FuncNumber],K[FuncNumber][4],Auxiliary[FuncNumber];
for(i=0;i<=(reachpo
6、int-x[0])/steplength;i++)
{
for(j=0;j
7、j=0;j