Error using odearguments (line 113) Inputs must be floats, namely single or double.

1 view (last 30 days)
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled3 (line 6)
[t,y] = ode45(@(t,y)dynamics(t,y), tspan, y0)
The function is
function dydx = dynamics(x,y)
dydx = [ y(2); -0.3*y(2)+ y(1)-(y(1))^3+ 0.2*cos(5.2360*t)];
The code is
syms t
u=1.2;
T=2*pi/u;
tspan = [0 300*T];
y0 = [0; 0];
[t,y] = ode45(@(t,y)dynamics(t,y), tspan, y0)
Please let me know how to solve this issue.

Answers (1)

Daniel M
Daniel M on 8 Oct 2019
Edited: Daniel M on 8 Oct 2019
Your function dynamics takes as inputs x and y, but instead uses t and y. So fix that.
You are also passing in a symbolic value for t. So just delete the line
syms t
Otherwise, if you would like to solve this ode symbolically, I suggest reading the existing doc on how to do so:
(But actually, I do not get an error running it with 'syms t' once the function dynamics is fixed. Version R2019a).

Tags

Community Treasure Hunt

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

Start Hunting!