Error - Inputs must be floats 'ode45'

2 views (last 30 days)
I am trying to solve two odes using ode45 and getting the same error everytime and i cant seem to work out why..
any help would be appreciated, thanks!
syms u v
a = 0.2;
c = 1;
b = (2*c/(1-a));
s(1) = u;
s(2) = v;
inital(1)=1;
inital(2)=1;
l = @(t,y) [s(1)*(1-s(1))*(a+s(1))-s(1)*s(2); b*s(1)*s(2)-s(2)];
[t,x] = ode45(l, [0, 200], inital)

Accepted Answer

Alan Stevens
Alan Stevens on 24 Nov 2020
Edited: Alan Stevens on 24 Nov 2020
Like so (Note: no need for syms):
a = 0.2;
c = 1;
b = (2*c/(1-a));
inital(1)=1;
inital(2)=1;
l = @(t,s) [s(1)*(1-s(1))*(a+s(1))-s(1)*s(2); b*s(1)*s(2)-s(2)]; % Note: l = @(t,s) ...etc
[t,s] = ode45(l, [0, 200], inital); % Note [t, s] = ...etc.
u = s(:,1);
v = s(:,2);
plot(t,u,t,v),grid

More Answers (0)

Categories

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

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!