Filter löschen
Filter löschen

2nd Order Diff Equation

3 Ansichten (letzte 30 Tage)
bugatti79
bugatti79 am 15 Jul. 2014
Kommentiert: Star Strider am 15 Jul. 2014
Hi Folks,
I get the following error when I attempt to run this bit of code
"Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in ode45 "
function yp = unforced1(t,y)
m=1;
k=100;
%s=.1;
c=2*m*0.1*(k/m)^(1/2);
y(2)=0 ;
y(1)=0.02;
yp = [y(2);(-((c/m)*y(2))-((k/m)*y(1)))];
tspan=0:0.01:4;
y0=[0.02;0];
[t,y]=ode45('unforced1',tspan,y0);
plot(t,y(:,1));
grid on
xlabel('time')
ylabel('Displacement')
title('Displacement Vs Time')
hold on;
end
Any ideas? Regards Bugatti

Akzeptierte Antwort

Star Strider
Star Strider am 15 Jul. 2014
You are calling ode45 inside your ODE function. This is likely the reason for the recursion limit warning.
Delete the function statement at the start, change the yp line to be an anonymous function:
unforced1 = @(t,y) [y(2);(-((c/m)*y(2))-((k/m)*y(1)))];
and change the call to ode45 to:
[t,y]=ode45(unforced1,tspan,y0);
When I made those changes it worked for me without errors (R2014a).
  6 Kommentare
bugatti79
bugatti79 am 15 Jul. 2014
Ah ok! Great, thanks for your help. Appreciated.
Star Strider
Star Strider am 15 Jul. 2014
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by