老师让做一个课题 用欧拉公式求解常微分方程算法实现 谁会 求高手帮忙啊 谢谢 20
1个回答
展开全部
改进的欧拉公式算法求解常微分方程初值问题
#include<stdio.h>
#include<math.h>
#define f(x,y) (y*y)//dy/dx=y*y(即f(x,y)=y*y)
int main()
{
int m,i;
double a,b,y0;
double xn,yn,xnl,ynl,ynlb;
double h;
printf("\nInput the begin and end of x:");
scanf("%lf%lf",&a,&b);
printf("Input the y value at %f:",a);
scanf("%lf",&y0);
printf("\nInput m value [divide(%f,%f)]:",a,b);
scanf("%d",&m);
if(m<=0)
{
printf("Please input a number larger than 1.\n");
return 1;
}
h=(b-a)/m;
xn=a;
yn=y0;
for(i=1;i<=m;i++)
{
xnl=xn+h;
ynlb=yn+h*f(xn,yn);
ynl=yn+h/2*(f(xn,yn)+f(xnl,ynlb));
printf("x%d=%f,y%d=%f\n",i,xnl,i,ynl);
xn=xnl;
yn=ynl;
}
return 0;
}
#include<stdio.h>
#include<math.h>
#define f(x,y) (y*y)//dy/dx=y*y(即f(x,y)=y*y)
int main()
{
int m,i;
double a,b,y0;
double xn,yn,xnl,ynl,ynlb;
double h;
printf("\nInput the begin and end of x:");
scanf("%lf%lf",&a,&b);
printf("Input the y value at %f:",a);
scanf("%lf",&y0);
printf("\nInput m value [divide(%f,%f)]:",a,b);
scanf("%d",&m);
if(m<=0)
{
printf("Please input a number larger than 1.\n");
return 1;
}
h=(b-a)/m;
xn=a;
yn=y0;
for(i=1;i<=m;i++)
{
xnl=xn+h;
ynlb=yn+h*f(xn,yn);
ynl=yn+h/2*(f(xn,yn)+f(xnl,ynlb));
printf("x%d=%f,y%d=%f\n",i,xnl,i,ynl);
xn=xnl;
yn=ynl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询