Borrar filtros
Borrar filtros

2nd Order Diff Equation

3 visualizaciones (últimos 30 días)
bugatti79
bugatti79 el 15 de Jul. de 2014
Comentada: Star Strider el 15 de Jul. de 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

Respuesta aceptada

Star Strider
Star Strider el 15 de Jul. de 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 comentarios
bugatti79
bugatti79 el 15 de Jul. de 2014
Ah ok! Great, thanks for your help. Appreciated.
Star Strider
Star Strider el 15 de Jul. de 2014
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by