简体   繁体   English

MatLab ode45 解释

[英]MatLab ode45 explanation

For a project I need to understand a matlab code, but as I am quite new I dont really understand what is happening.对于一个项目,我需要了解 matlab 代码,但由于我很新,我不太明白发生了什么。 I have a function file and a script file.我有一个函数文件和一个脚本文件。

Function:功能:

function dxdt = sniffer_ode(t,x,par,tu)

X = x(1);

R = x(2);


k1 = par(1);

k2 = par(2);

k3 = par(3);

k4 = par(4);


S = interp1(tu(:,1),tu(:,2),t); 


dxdt(1) = k3*S-k4*X;

dxdt(2) = k1*S-k2*X*R;


dxdt = dxdt(:); %dxdt should be column

and the script file:和脚本文件:

%sniffer
close all

%initial conditions:
X0=0; R0=0;
x0=[X0 R0];
%parameters:
k1=1; k2=1; k3=1; k4=1;
par=[k1 k2 k3 k4];
%input:
tu=[ 0   , 0
     1   , 0
     1.01, 1
    20   , 1];

[t,x] = ode45(@sniffer_ode,[0 20],x0, [],par,tu);

plot(t,x); 

So the question is: What is happening?所以问题是:发生了什么? I also need to plot S in the same figure as X and R. How do I do this?我还需要在与 X 和 R 相同的图形中绘制 S。我该怎么做?

I appreciate your help!我感谢您的帮助!

This is a really basic Matlab question.这是一个非常基本的Matlab问题。 There is tons of information about your requested topic .大量关于您请求的主题的信息 I think theseslides will help you on the right path.我认为这些幻灯片将帮助您走上正确的道路。

However, a quick explanation;但是,快速解释一下; the first code you provide is the function which describes your ordinary differential equation.您提供的第一个代码是描述常微分方程的函数。 This function always has to be of the form x' = f(t,x,...) .此函数必须始终采用x' = f(t,x,...) Herein t is the time and x is the state.其中t是时间, x是状态。 After the state (on the place of the dots ... ) you can define other input parameters, such as is being done in your ode function.在状态之后(在点的位置... ),您可以定义其他输入参数,例如正在您的 ode 函数中完成。 Furthermore, the interp1 function interpolates the data provided.此外, interp1函数对提供的数据进行插值

The second code you provide is the code you start within Matlab.您提供的第二个代码是您在 Matlab 中启动的代码。 Parameters are defined, after which the ordinary differential equation is solved and plotted.定义参数,然后求解和绘制常微分方程。

If you have any further questions I would recommend that you first try to find your answer using a search engine .如果您有任何其他问题,我建议您首先尝试使用搜索引擎找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM