ode45 symbolic variable in odefun
9 views (last 30 days)
Show older comments
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.
0 Comments
Answers (2)
Star Strider
on 16 Jun 2017
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.
0 Comments
Steven Lord
on 16 Jun 2017
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.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!