필터 지우기
필터 지우기

2nd Order Diff Equation

조회 수: 3 (최근 30일)
bugatti79
bugatti79 2014년 7월 15일
댓글: Star Strider 2014년 7월 15일
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

채택된 답변

Star Strider
Star Strider 2014년 7월 15일
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
bugatti79
bugatti79 2014년 7월 15일
Ah ok! Great, thanks for your help. Appreciated.
Star Strider
Star Strider 2014년 7월 15일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by