MATLAB: Error in ode45 using odearguments: “Inputs must be floats, namely single or double”

errorhekfkalmanMATLABodeode45

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

Best Answer

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.