ode45 symbolic variable in odefun

9 ビュー (過去 30 日間)
Carci
Carci 2017 年 6 月 16 日
回答済み: Steven Lord 2017 年 6 月 16 日
Hi everybody, I would like to kindly ask for your help. My problem is following: I am trying to solve the system of ODEs, which is represented by the symbolic matrix.
1) I have this odefunction:
function [y] = myFun(~,u)
global input
M=input.M;
v=input.v;
dui = M*u+v;
end
where M is a mentioned symbolic matrix (system of ODEs), v is a vector.
2) Then I have the main script, which calls ODE solvers and plots the results.
function main()
[t,y] = ode45(@myFun, tspan, y0, options);
...
end
Unfortunately, I am receiving this error: "Inputs must be floats, namely single or double."
I know, that ode45 is not designed for symbolic expressions. Of course, I tried to google it, etc., but I still cannot find the right solution. For example, I tried:
f = matlabFunction(myFun(tspan,y0))
[t,y] = ode45(f, tspan, y0, options);
but I am getting another error message: "Error using symengine>@()[-3.048662226349097;-5.801428662968666;-7.984664189221292;.....] Too many input arguments." and "Error in odearguments f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0."
Please, do you have any experience with this kind of problem? Many thanks in advance.

回答 (2 件)

Star Strider
Star Strider 2017 年 6 月 16 日
Note that your anonymous function:
@()[-3.048662226349097;-5.801428662968666;-7.984664189221292;.....]
does not accept any input arguments, so any input argument values passed to it will throw that error.

Steven Lord
Steven Lord 2017 年 6 月 16 日
Use the ODE solvers in MATLAB, like ode45, to numerically solve ODEs represented as a function handle that ode45 can evaluate to return a numeric answer.
Use the ODE solver function dsolve in Symbolic Math Toolbox to solve an ODE symbolically.

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by