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

2 vues (au cours des 30 derniers jours)
Sam d
Sam d le 22 Mai 2020
Réponse apportée : darova le 22 Mai 2020
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.

Réponse acceptée

darova
darova le 22 Mai 2020
Try this modification
results

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by