#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. 30个关于Shell脚本的经典案例(下)

    本文目录 21.从FTP服务器下载文件 22.连续输入5个100以内的数字,统计和.最小和最大 23.将结果分别赋值给变量 24.批量修改文件名 25.统计当前目录中以.html结尾的文件总大 26. ...

  2. Kubernetes第十一章--部署微服务电商平台

  3. python关于try except的使用方法

    一.常见错误总结 AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性x IOError 输入/输出异常;基本上是无法打开文件 ImportError 无法引入 ...

  4. php在虚拟机和windows上的应用

    学习目标:linux+apache+php合在一起的应用                在windows中三者的的关联及应用 php是apache的一个外挂程序,必须依靠web服务器才可以运行.当客户 ...

  5. 编程风格统一配置EditorConfig

    EditorConfig 以纯原生无需任何插件支持 EditorConfig 代码风格配置的编辑器: Visual Studio 2017 开始添加了对 EditorConfig 的原生支持.Visu ...

  6. 缓存注解@Cacheable、@CacheEvict、@CachePut使用及注解失效时间

    从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...

  7. linux下的 c 和 c++ 开发工具及linux内核开发工具

    https://opensource.com/article/18/6/embedded-linux-build-tools https://github.com/luong-komorebi/Awe ...

  8. rsa公钥和私钥到底哪个才是用来加密,哪个用来解密?

    本文转自:91博客:原文地址:http://www.9191boke.com/138589019.html 公钥和私钥在一些银行系统.第三方支付系统SDK中经常会遇到,刚接触公钥私钥的朋友们估计很难区 ...

  9. java代码转python代码

    (1)安装工具(windows 环境下面) 先下载antlr: http://www.antlr3.org/download/antlr-3.1.3.tar.gz 链接:http://pan.baid ...

  10. python测试开发django-rest-framework-63.基于函数的视图(@api_view())

    前言 上一篇讲了基于类的视图,在REST framework中,你也可以使用常规的基于函数的视图.它提供了一组简单的装饰器,用来包装你的视图函数, 以确保视图函数会收到Request(而不是Djang ...