How to apply time varying input with dlode45?

3 次查看(过去 30 天)
Hi all,
I wan to solve the NODE model
function y = NodeModel(tspan,y,theta,inputftrs)
y = tanh(theta.fc1.Weights_state*y+theta.fc1.Weights_input,inputftrs(:,:,tspan.*2)+theta.fc1.Bias);
y = pagemtimes(theta.fc2.Weights,y) + theta.fc2.Bias;
end
Where inputftrs is the input matrix. I called the dlode45 function like this
function X = model(tspan,X0,inputftrs,neuralOdeParameters)
odeModel=@(tspan,X0,neuralOdeParameters)NodeModel(tspan,X0,neuralOdeParameters,inputftrs);
X = dlode45(@odeModel,tspan,X0,neuralOdeParameters,DataFormat="CB");
end
However there comes an error "Unable to apply ODE function."

采纳的回答

Walter Roberson
Walter Roberson 2022-11-11
X = dlode45(@odeModel,tspan,X0,neuralOdeParameters,DataFormat="CB");
remove the @ there. odeModel is already a function handle.
  2 个评论
Emebet Gedlu
Emebet Gedlu 2022-11-11
Thank you. I found also I have to interpolate the input matrix to the ode time step.
Walter Roberson
Walter Roberson 2022-11-11
If you have to interpolate something to use it with any of the ode*() functions, then typically that means that you are violating the mathematical contraints for the ode*() functions. The mathematics of Runge-Kutta is only valid if the equations you give and their first two derivatives are continuous. In most cases, when people interpolate they use linear interpolation, but linear interpolation between lists of points has discontinuous first derivatives.
In order to use interpolation with the ode*() functions you need to use 'cubic' or 'spline' method so that the derivatives get matched up piecewise. This will, of course, only be valid for situations in which you can say that the data values are the results of processes that are continuous, that it is valid for a point between A and B to be influenced both by A and by B. You would not be able to use this kind of interpolation for impulses such as drug dosing, or for road height measurements that reflect stones and other sharp transitions.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by