改进欧拉公式求解常微分方程(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 ...
随机推荐
- C++STL—map的使用
最近写的一道题用到了STL中的map,这部分内容之前没有系统学过,这里就简单归纳一下吧. 资料来源: https://www.w3cschool.cn/cpp/cpp-fu8l2ppt.html ht ...
- 必须掌握的Linux用户组
在 Linux 系统中用户组起着重要作用.用户组提供了一种简单方法供一组用户互相共享文件.用户组也允许系统管理员更加有效地管理用户权限,因为管理员可以将权限分配给用户组而不是逐一分配给单个用户. 尽管 ...
- Filter DSL 常用语法 -- 基本查询语法,必会
转发自:https://www.cnblogs.com/ghj1976/p/5293250.html term 过滤 term主要用于精确匹配哪些值,比如数字,日期,布尔值或 not_analyzed ...
- 两种方法实现在HTML页面加载完毕后运行JS
JS默认方法: <script type=”text/javascript”> window.onload=function (){ /*代码区域*/ } </script> ...
- vue+element 按钮来回切换
需求很简单,实现很容易,日常记录一下 templace代码: data数据声明: me'thods方法:
- Java实现在线预览--openOffice实现
简介 之前有写了poi实现在线预览的文章,里面也说到了使用openOffice也可以做到,这里就详细介绍一下. 我的实现逻辑有两种: 一.利用jodconverter(基于OpenOffice服务)将 ...
- Koa2 和 Express 中间件对比
koa2 中间件 koa2的中间件是通过 async await 实现的,中间件执行顺序是"洋葱圈"模型. 中间件之间通过next函数联系,当一个中间件调用 next() 后,会将 ...
- MySQL优化——MySQL 生产环境下 my.cnf 优化配置
MySQL 5.6/5.7 参数文件优化配置[client]port = 3306socket = /data/mysql/tmp/mysql.sockdefault-character-set = ...
- 从零搭建consul
从零搭建consul 原文链接:https://blog.csdn.net/weixin_42107541/article/details/87640807#2linux_25 从零搭建consul1 ...
- linux设备驱动程序-i2c(1):i2c总线的添加与实现
linux设备驱动程序-i2c(1):i2c总线的添加与实现 (基于4.14内核版本) 在上一章节linux设备驱动程序-i2c(0)-i2c设备驱动源码实现中,我们演示了i2c设备驱动程序的源码实现 ...