记录一下MATLAB中ode45函数求解非刚性微分方程
首先看一下MATLAB的官方例子
vdp1.m:
function dydt = vdp1(t,y)
%VDP1 Evaluate the van der Pol ODEs for mu = 1
%
% See also ODE113, ODE23, ODE45.% Jacek Kierzenka and Lawrence F. Shampine
% Copyright 1984-2014 The MathWorks, Inc.dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];
主程序:
%%
% Solve the ODE using the |ode45| function on the time interval |[0 20]|
% with initial values |[2 0]|. The resulting output is a column vector of
% time points |t| and a solution array |y|. Each row in |y| corresponds to
% a time returned in the corresponding row of |t|. The first column of |y|
% corresponds to $y_1$, and the second column to $y_2$.
[t,y] = ode45(@vdp1,[0 20],[2; 0]);%%
% Plot the solutions for $y_1$ and $y_2$ against |t|.
plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
画出来的图像:
对比一下另一个例子:
mycode.m:
function dydt = myode(t,y,ft,f,gt,g)
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt = -f.*y + g; % Evaluate ODE at time t
主函数:
ft = linspace(0,5,25);
f = ft.^2 - ft - 3;gt = linspace(1,6,25);
g = 3*sin(gt-0.25);
tspan = [1 5];
ic = 1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, ic, opts);
plot(t,y)
画出来的结果:
总结:
函数主体:[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, ic, opts);这一句中,myode(t,y,ft,f,gt,g)为需要解的函数,可以自己再修改,就是注意需要把参数对应上,tspan是t的范围,ic其实可以有很多记号表示,也就是上面第一个例子那个[2;0],因为第一个例子有y1,y2两个初值,opts则是一个可选项,有一部分参数在里面调整
后面还有一个关于画完之后继续拓展的,备注一下万一用上
Evaluate and Extend Solution Structure
The van der Pol equation is a second order ODESolve the van der Pol equation with using ode45. The function vdp1.m ships with MATLAB® and encodes the equations. Specify a single output to return a structure containing information about the solution, such as the solver and evaluation points.
tspan = [0 20];
y0 = [2 0];
sol = ode45(@vdp1,tspan,y0)Use linspace to generate 250 points in the interval [0 20]. Evaluate the solution at these points using deval.
x = linspace(0,20,250);
y = deval(sol,x);Plot the first component of the solution.
plot(x,y(1,:))Extend the solution to using odextend and add the result to the original plot.
sol_new = odextend(sol,@vdp1,35);
x = linspace(20,35,350);
y = deval(sol_new,x);
hold on
plot(x,y(1,:),'r')
记录一下MATLAB中ode45函数求解非刚性微分方程相关推荐
- matlab pdepe函数边界,科学网-使用MATLAB中pdepe函数求解一维偏微分方程-邓浩鑫的博文...
由于自己科研水平较低,记录的各种体会更多的是给自己做个小结,错误之处,欢迎大家指正. 使用MATLAB求解偏微分方程或者方程组,大致有三类方法.第一种是使用MATLAB中的PDE Toolbox,PD ...
- 【matlab中ode45函数使用的说明】
matlab使用ode45解微分方程组 官方文档链接 使用方式: [t,y] = ode45(odefun,tspan,y0) 功能为:求微分方程组 y′=f(t,y) 从 t0 到 tf 的积分(y ...
- matlab中ode45函数的用法_带你理解Excel中COUNTIF函数的简单用法
每天5分钟,每天学一点. COUNTIF函数是Excel中最常用的统计函数之一,它的作用主要是用于根据特定条件对数据进行统计.假如,你想统计一下本周总共做了几次健身/瑜伽,或者统计上了几次培训课,那么 ...
- MATLAB 数学应用 微分方程 常微分方程 求解非刚性ODE
本文介绍两个使用 ode45 来求解非刚性常微分方程的示例.MATLAB拥有三个非刚性 ODE 求解器. ode45 ode23 ode113 对于大多数非刚性问题,ode45 的性能最佳.但对于允许 ...
- matlab中ode45用法,ode45(ode45用法举例)
ode45是用4阶方法提供候选解,5阶方法控制误差,是一种自适应步长的方法.而我们平时用的4阶和5阶龙格库塔法的公式中步长是给定的.具体算法和原理你可以看. ode45的初始条件是否必须是在x=0处 ...
- matlab中linprog函数不能用,matlab中linprog函数
§15. 利用 Matlab 求解线性规划问题 线性规划是一种优化方法,Matlab 优化工具箱中有现成函数 linprog 对如 下式描述的 LP 问题求解: % min f'x % s.t ... ...
- C++内点法求解大规模线性规划问题——对标MATLAB中linprog函数
C++内点法求解大规模线性规划问题--对标MATLAB中linprog函数 文章目录 C++内点法求解大规模线性规划问题--对标MATLAB中linprog函数 1. 项目场景 2. 约束的规范化 3 ...
- 极大似然函数求解_关于极大似然估计的学习(附Matlab中mle函数的求解)
冒泡~是新的一周辣~温故而知新一下极大似然估计(真是很不容易了) 极大似然估计的基本思想 什么是极大似然?官方上的较清楚的解释是:利用已知的样本的结果,在使用某个模型的基础上,反推最有可能导致这样结果 ...
- MATLAB中ode45()和Runge-Kutta算法(4阶)的比较
文章目录 引言 ode45() Runge-Kutta 算法 RK 算法程序 仿真 仿真代码 不同终端时间下的算法对比 不同步长下的算法对比 结论 引言 写这篇博客目的是自己在求解微分方程的时候,考虑 ...
最新文章
- 问题解决:jmeter+java+beanshell : org.apache.jorphan.util.JMeterException: Error invoking bsh method: eva
- python3代码转python2_Python2代码转成Python3代码
- 【科普】OSS存储的基本操作
- 什么时候告白最合适?
- XP下修改IIS连接数
- jira7.12.1安装与破解
- pythondict函数_Python的dict()函数
- .html() 与.text() 获取值、取值 区别
- 13.高性能MySQL --- 云端的MySQL
- 暨南大学锐捷校园网路由器教程
- python snap7 plc_Python-Snap7获取西门子PLC 300数值
- 非线性控制1.0——自适应控制和鲁棒控制
- 计算机怎么打开网络共享,windows电脑如何开启wifi网络共享呢
- 优秀开源云原生工具推荐——系列3
- 康特EPON OLT开局配置
- mysql安装包msi_win10系统,mysql-installer-community-5.7.19.0.msi安装
- 屏幕篇—如何最快速驱动LCD屏
- matlab 星厉,卫星 | 利用matlab根据星历读取卫星位置
- qpsk的映射过程_QPSK实验报告
- 2021Mathorcup B题团簇预测部分