Please Help: "Error in odearguments (line 90)" and "Error in ode45 (line 115)"?

2 views (last 30 days)
I'm trying to model a damped spring and have created the following code
clear all;
m=1;
k=4;
c=1;
omega0=sqrt(k/m);p=c/(2*m);
y0=.01;v0=0;
[t,Y]=ode45(@f,[0,10],[y0,v0],[],omega0,p);
y=Y(:,1);v=Y(:,2);
figure(1);plot(t,y,'b+-',t,v,'ro-');
grid on; axis tight;
%------------------------------------
function dYdt=f(t,Y,omega0,p);
y=Y(1);v=Y(2);
dYdt=[v;-(omega0*omega0)*y-p*v];
end
When I run it I get the following errors.
Unrecognized function or variable 'f'.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options,
varargin);
I've seen others code which are basically the same and they seem to get out put, so am I missing a plug in or have I made a mistake? Thanks for any help.

Accepted Answer

darova
darova on 22 May 2020
Try this modification
results

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!