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

조회 수: 2 (최근 30일)
Sam d
Sam d 2020년 5월 22일
답변: darova 2020년 5월 22일
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.

채택된 답변

darova
darova 2020년 5월 22일
Try this modification
results

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by