#include<iostream>

#include<iomanip>

using
namespace std;

int main()

{

double
x,y,h,temp,f;

x
=
0;      //对x赋初值

y
=
1;      //对y赋初值

h
=
0.1;      //步长设置为0.1

cout << setiosflags(ios::left);

cout << setw(20)
<< "y的计算值";

cout << setw(20)
<< "y的理论值";

cout << setw(20)
<< "x的值";

cout << setw(20)
<< "误差"
<< endl;

cout << setw(20)
<< y;

cout << setw(20)
<< y;

cout << setw(20)
<< x;

cout << setw(20)
<< 0
<< endl;

for
(int i = 0; i < 10; i++)

{

temp=y;

f
= y - (2 * x /
y);      //保存未改变的f(x,y)的值

y
= y + h*(y - (2 * x /
y));      //得到预估值

x
+=
h;      //迭代得到最新的x值

y=temp
+ h / 2 *(f + (y - (2 * x / y) ) );

cout << setw(20)
<<
y;      //输出y的新值

cout << setw(20)
<< sqrtf(1 + 2 *
x);      //计算y的理论值

cout << setw(20)
<<
x;      //输出x的新值

cout << setw(20)
<< y - sqrtf(1 + 2 * x)
<< endl;      //计算误差

}

return
0;

}

改进欧拉公式求解常微分方程(c++)的更多相关文章

  1. MATLAB求解常微分方程:ode45函数与dsolve函数

    ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1.      ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...

  2. 欧拉法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h;   ...

  3. 梯形法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...

  4. 后退欧拉法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...

  5. 欧拉法求解常微分方程(c++)【转载】

    摘自<c++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...

  6. ODEINT 求解常微分方程(4)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  7. ODEINT 求解常微分方程(3)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  8. ODEINT 求解常微分方程(2)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  9. ODEINT 求解常微分方程(1)

    An example of using ODEINT is with the following differential equation with parameter k=0.3, the ini ...

随机推荐

  1. 小div在大div中垂直居中方式

    代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  2. js函数(续)

    一.全局变量和局部变量全局变量:当前js页面中均可使用的变量[声明在函数外面的变量],整个js页面中均可以使用.局部变量:声明在函数内部的变量,只能在函数内部使用.eg: var a = 1; con ...

  3. JAVA项目之注册

    public class RegisterServlet extends HttpServlet { private UsersService usersService = new UsersServ ...

  4. 冠捷显示成功的信息化建设(MES应用案例)

    企业介绍 冠捷科技集团是驰誉全球的大型高科技跨国企业,产品包括彩色显示器( CRT monitor ).液晶显示器( LCD monitor ).液晶电视( LCD-TV )与等离子电视( PDP ) ...

  5. eclipse如何为java项目生成API文档

    文章转载自: https://www.cnblogs.com/wdh1995/p/7705494.html 当我们的项目很大,编写了很多代码的时候,就需要生成一个标准的API文档,让后续的开发人员,或 ...

  6. 给 linux redis 设置密码

    在redis.conf 找到 下面添加一行: 这样的话,密码就可以设置成123456,然后重启redis就可以了.

  7. MySQL Disk--MySQL磁盘问题排查

    存储问题排查 1.检测磁盘空间使用率 df -lh 注意系统目录的可用空间 2.检查磁盘inode使用 df -i 参考:https://www.cnblogs.com/gaogao67/p/1088 ...

  8. NULLIF(EXPR1,EXPR2)

    --NULLIF(EXPR1,EXPR2):给定两个参数EXPR1和EXPR2,如果两个参数相等,则返回NULL:否则就返回第一个参数.

  9. maven学习笔记三(依赖特性,作用域)

    上一章中  我们看到了添加了个junit的依赖包.那么maven中想添加依赖的jar包我们只需要配置相应的dependency就行.例如: <dependency> <groupId ...

  10. 基于kubeamd初始化安装kubernetes集群

    环境:master,etcd 172.16.1.5node1 172.16.1.6node2 172.16.1.7前提:1.基于主机名通信,/etc/hosts 2.时间同步3.关闭firewalld ...