简体   繁体   English

Matlab ODE求解器的多个输出

[英]Multiple outputs of Matlab ODE solver

I have the following Matlab ODE code: 我有以下Matlab ODE代码:

[t,y,~,~,ie] = ode23tb(@(t,y) RHSODE(t,y),[0,t_end], [i0;v0],options);

I want the ODE solver could also give me the result z, which is a function of y and dy/dt, such that z = f(y,dy/dt). 我希望ODE求解器也可以给我结果z,它是y和dy / dt的函数,因此z = f(y,dy / dt)。

Does anyone know how to add such z into the output of the solver? 有谁知道如何将这样的z加到求解器的输出中?

There are two ways to do this. 有两种方法可以做到这一点。 The most common, and usually fastest, way is to take advantage of your integration function ( RHSODE in your case) and evaluate your function f after performing the integration. 最常见且通常最快的方法是利用集成功能(在您的情况下为RHSODE )并在执行集成后评估功能f You haven't provided many details with your code but it might look something like this: 您的代码中并未提供许多详细信息,但可能看起来像这样:

ydot = RHSODE(t,y);
z = f(y,ydot);

where t and y are the outputs from ode23tb . 其中tyode23tb的输出。 This requires that both RHSODE and f be vectorized (or you can wrap the above in a for loop). 这要求将RHSODEf进行向量化(或者可以将以上内容包装在for循环中)。

The other way requires that you create an additional equation (or equations if z is a vector) inside of your integration function, RHSODE . 另一种方法要求您在积分函数RHSODE内创建一个附加方程式(如果z是矢量,则创建方程式)。 Normally ode23tb integrates anything in this function so f must be multiplied by a factor of t to cancel this out. 通常, ode23tb在此函数中集成了任何内容,因此必须将f乘以t才能取消此功能。 Again, your code might look something like this: 同样,您的代码可能看起来像这样:

function ydot = RHSODE(t,y)
ydot0 = ... % Your original ODE(s)
z = f(y,ydot);
ydot = [ydot0;z*t]; % Make column vector

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

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