⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 euler.txt

📁 By the proof of Lemma 2 of Section 5.2, this accomplished as follows:
💻 TXT
字号:
# include <iostream>
# include <iomanip>
# include <cmath>
using namespace std;
class Euler{
private:
	int n;
	double a,b,h;
	double *x,*y;
public:
	Euler();
    ~Euler();
	void cal();
	double f(double x,double y);
};
Euler::Euler()
{
	cout<<"input the range (a,b):";
    cin>>a>>b;
	cout<<"input the length of step:";
	cin>>h;
	n=int((b-a)/h)+1;
	x=new double[n];
	y=new double[n];
	cout<<"input the initial value of y:";
	cin>>y[0];
	x[0]=a;
}
Euler::~Euler()
{
	delete []x;
	delete []y;
}
void Euler::cal()
{
	int i;
	for(i=1;i<n;i++)
	{
		x[i]=x[i-1]+h;
		y[i]=y[i-1]+h*f(x[i-1],y[i-1]);
		y[i]=y[i-1]+h*(f(x[i-1],y[i-1])+f(x[i],y[i]))/2;
	}
	cout.setf(ios::fixed);
	cout<<setprecision(6);
	for(i=0;i<n;i++)
	cout<<"x"<<i<<"="<<x[i]<<" "<<"y"<<i<<"="<<y[i]<<endl;
}
double Euler::f(double x,double y)
{
	return x+y;
}
void main()
{
Euler a;
a.cal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -