常微分方程的查分方法——改进的欧拉方法

程序流程图如下:
在这里插入图片描述

//常微分方程的差分方法——改进的欧拉方法——求解初值问题
 /************Analysis**************
 *1.h:步长,N:步数,迭代次数,x0,y0为老值,x1,y1为新值
 *f(x)=y-2x/y
 *y(0)=1
 **************************/
#include<iostream>
using namespace std;
double f(double x,double y)
{
	return y-2*x/y;
}
int main()
{
	double x0,y0;
	double h;//step
	unsigned N;
	unsigned n=0;
	cout<<"-------------Inproved Eular Method----------"<<endl;
	cout<<"Please input initial value of x0 :"<<endl;
	cin>>x0;
	cout<<"Please input initial value of y0:"<<endl;
	cin>>y0;
	cout<<"Please input step value h:"<<endl;
	cin>>h;
	cout<<"Please input iterative times H:"<<endl;
	cin>>N;
	cout<<"------------------Output------------------"<<endl;
	
	double x1,y1;
	double yp;
	double yc;
	
	n=1;
	while(true)
	{
		x1=x0+h;
		yp=y0+h*f(x0,y0);
	    yc=y0+h*f(x1,yp);
		y1=(yp+yc)/2;	
		cout<<"x1:"<<x1<<"    "<<"y1:"<<y1<<endl;

		if(n!=N)
		{
			n=n+1;
			x0=x1;
			y0=y1;
		}
		else
			break;
	}


	cout<<"Hello,Boker..."<<endl;
	system("pause");
	return 0;
}

运行结果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值