1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! 作者:Hou Fenglin
//! 程序名:euler.cpp
//! euler预测-校正法解微分方程
#include <iostream>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
class euler
{
    private:
        int n;
        double f, h, x0, x_last, yc, yp;
    public:
        double func(double z, double t)
        {
            f = (1+z) * t * t / 2;
            return f;
        }
        void pc();
};
 
//主函数
int
main()
{
    euler predictor_corrector;
    predictor_corrector.pc();
}
 
//Euler 预测-校正法
void euler::pc()
{
    cout<<"输入初始条件:"<<endl;
    cout<<"\n输入 x0 ";
    cin>>x0;
    cout<<"\n输入y0 ";
    cin>>yc;
    cout<<"\n输入y需要的x值 ";
    cin>>x_last;
    cout<<"\n输入等分数";
    cin>>n;
    h = (x_last - x) / n;
    for(int i = 0; i < n; i++)
    {
        yp = yc + h * func(x0, yc);
        yc += 0.5 * h * (func(x0, yc) + func((x0+h), yp));
        x0 += h;
        cout.precision(10);
        cout<<x0<<setw(15)<<yc<<endl;
    }
}
Tags: .
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Home

Be the first to comment on this entry.

Name(required)
Mail (required),(will not be published)

RFC: Request For Comments. Orz..

Website(recommended)