Error in ode45 using odearguments: "Inputs must be floats, namely single or double"

49 views (last 30 days)
Hello everyone. I am trying to use the ode45 function to solve a system of differential equations to solve for the first process of a Kalman Filter estimator, but after looking up for the error in other forum posts and also trying to understand a bit more of the ode45 solver, I really can't seem to find what is the cause of the error I am getting:
Error using odearguments (line 110)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Estimator (line 130)
[t,estx] = ode45(odefun1,[estState.tm estState.tm+dt],estState.xm');
These are the pieces of code I believe are relevant to the error in question:
syms p_x p_y s_x s_y phi b u_r u_t vr vd vb wa wb wc wg wn
...
estState.q=[s_x;s_y; cos(phi)*(tanh(u_t)-estState.C_d*(s_x^2+s_y^2)*(1+vd)); sin(phi)*(tanh(u_t)-estState.C_d*(s_x^2+s_y^2)*(1+vd)); estState.C_r*u_r*(1+vr); vb];
....
odefun1 = @(t,estx) xder(t,estx,estState.q,actuate);
[t,estx] = ode45(odefun1,[estState.tm estState.tm+dt],estState.xm');
xp=estx(end,:)';
...
function dxdt = xder(t,estx,q,actuate)
syms p_x p_y s_x s_y phi b u_r u_t vr vd vb
q1=subs(q, [vr vd vb], [0 0 0]);
q1=subs(q1, [u_t u_r], [actuate(1) actuate(2)]);
dxdt = subs(q1, [p_x p_y s_x s_y phi b], estx');
end
And before getting to the ode45 call, the variables have the following values:
estState.xm' =
0
0
0
0
0
0
ans =
0.1000
dt =
0.1000
actuate =
0.0623 0.0078
Any ideas, help or suggestions would be extremely welcome of course. Thank you

Accepted Answer

Steven Lord
Steven Lord on 17 May 2018
The function you pass into ode45 must return a single or double precision array, not a symbolic array. It may internally use symbolic variables created by the sym or syms functions, but if it does it must convert those symbolic results into numeric results before it returns them to ode45. The easiest way to perform that conversion would be to call the double function on the symbolic result.
  1 Comment
Miguel Ángel
Miguel Ángel on 17 May 2018
That was amazingly fast! Thank you very much Steven.
Yep, after analyzing the inner variables of the ode function I see that even thought dxdt has numeric values, it technically remains being a symbolic variable so the solution to the problem is just to do the following:
dxdt = double(subs(q1, [p_x p_y s_x s_y phi b], estx'));

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!