改进欧拉公式求解常微分方程(c++)

#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++)的更多相关文章
- MATLAB求解常微分方程:ode45函数与dsolve函数
ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1. ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...
- 欧拉法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h; ...
- 梯形法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...
- 后退欧拉法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...
- 欧拉法求解常微分方程(c++)【转载】
摘自<c++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...
- ODEINT 求解常微分方程(4)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- ODEINT 求解常微分方程(3)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- ODEINT 求解常微分方程(2)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- ODEINT 求解常微分方程(1)
An example of using ODEINT is with the following differential equation with parameter k=0.3, the ini ...
随机推荐
- vue插件(还真是第一次接触)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 采用__call__ 实现装饰器模式
装饰器模式在实现中也是很常见的:比如手机贴膜,手机壳 都是为了给手机增加一些额外功能 增加耐操 装饰器模式的本质就是对对象二次包装,赋额外功能 __call__ __call__是python魔术方法 ...
- JS基础理论相关知识
1.XHTML和HTML有什么区别 HTML是一种基本的WEB网页设计语言,XHTML是一个基于XML的置标语言最主要的不同:XHTML 元素必须被正确地嵌套.XHTML 元素必须被关闭.标签名必须用 ...
- Node.js实现用户评论社区(体验前后端开发的乐趣)
前面 接着上一节的内容来,今天我们要完成一个用Node开发后台服务器,实现一个简单的用户评论社区.可以先看下效果图: 开始 建立项目文件夹comment-list,在里面新建一个public文件夹,p ...
- Building Objective-C static libraries with categories
Q: How do I fix "selector not recognized" runtime exceptions when trying to use category m ...
- WPF应用打包流程
1,安装工程模板插件Microsoft Visual Studio Installer Projects https://marketplace.visualstudio.com/items?item ...
- RabbitMq 消息队列 在Python端的应用
https://www.cnblogs.com/Xuuuuuu/p/10895552.html rabbit_server持久化,消费者端手动确认保证消息不会丢失.具体代码如下: 1对1生产者端代码: ...
- js 数组 深拷贝 复制 (汇总)
https://www.cnblogs.com/zhoupengyi/p/6048955.html https://www.cnblogs.com/racyily/p/3532176.html htt ...
- 基于gtk的imshow:用gtk读取并显示图像
gtk实现imshow,最naive的做法是用gtk的组件去读取图像,然后show出来:后续再考虑用GTK显示用别的方式例如stb image读取的图像.先前基于GDI实现imshow时也是这一思路, ...
- 常用docker管理UI
1. HumpBacks 特性 Web UI Supporting, Easy to use. Container Grouping and Isolation. Container Upgrades ...