求解常微分方程初值问题之改进Euler法:预报-校正公式
2013-08-13 11:05
1171 查看
//实现Euler预报_校正法
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
class euler
{
private:
int i, n;
double f, h, x, x_last, yc, yp;
public:
double func(double z, double t)
{
f = (1 + z) * t * t / 2;
return f;
}
void pc();
};
void main()
{
euler predictor_corrector;
predictor_corrector.pc();
}
void euler::pc()
{
cout << "\n输入初始条件:" << endl;
cout << "\n输入x0:";
cin >> x;
cout << "\n输入y0:";
cin >> yc;
cout << "\n输入y需要的x值:";
cin >> x_last;
cout << "\n输入等分数:";
cin >> n;
h = (x_last - x) / n;
for (i = 0; i < n; i++)
{
yp = yc + h * func(x, yc);
yc += 0.5 * h * (func(x, yc) + func((x + h), yp));
x += h;
cout.precision(10);
cout << x << setw(15) << yc << endl;
}
}
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
class euler
{
private:
int i, n;
double f, h, x, x_last, yc, yp;
public:
double func(double z, double t)
{
f = (1 + z) * t * t / 2;
return f;
}
void pc();
};
void main()
{
euler predictor_corrector;
predictor_corrector.pc();
}
void euler::pc()
{
cout << "\n输入初始条件:" << endl;
cout << "\n输入x0:";
cin >> x;
cout << "\n输入y0:";
cin >> yc;
cout << "\n输入y需要的x值:";
cin >> x_last;
cout << "\n输入等分数:";
cin >> n;
h = (x_last - x) / n;
for (i = 0; i < n; i++)
{
yp = yc + h * func(x, yc);
yc += 0.5 * h * (func(x, yc) + func((x + h), yp));
x += h;
cout.precision(10);
cout << x << setw(15) << yc << endl;
}
}
相关文章推荐
- 求解常微分方程初值问题之多步Euler预报-校正法
- 求解常微分方程初值问题之Milne预报-校正法
- 亚当姆斯预报_校正系统解一阶微分的初值问题
- 改进的欧拉格式求解一阶微分的初值问题
- 欧拉法、预估校正法(改进的欧拉法)与四阶龙格库塔法求解常微分方程的数值解C++程序
- 全区间积分的阿当姆斯预报校正法(常微分方程组的求解)
- 快速排序的两种改进方法算法及topK问题求解
- 用显式欧拉格式和改进的欧拉格式求解常微分初值问题
- 求解常微分方程初值问题之Runge_Kutta法
- 动态规划算法求解硬币找零问题改进与优化(Java)
- 求解常微分方程初值问题之Runge_Kutta_Fehlberg法
- 背包问题的各种求解方法
- 遗传算法求解one_max问题
- 关于数学公式输入中括号的换行问题 的两种常用方法
- 用递归算法求解汉诺塔问题
- 转 基于贪心算法求解TSP问题(JAVA)
- 第12周项目4利用遍历思想求解图问题3
- 最大子数组问题-暴力求解-c++代码实现及运行实例结果
- 2、Logistic Regression求解classification问题 c代码
- 关于推箱子自动求解源码的若干问题