Ode45 I get wrong results.

조회 수: 11 (최근 30일)
Arda Nova
Arda Nova 2018년 12월 31일
댓글: Arda Nova 2019년 1월 1일
function dydt = idn (t, y)
dydt = zeros(2,1);
dydt(1)=y(2);
dydt(2)=-((9.81*sin(y(1)))/0.5);
dydt = [0.78 0];
[t1,y1] = ode45(@idn, [0 20], dydt);
plot(t1,y1(:,2));
grid on;
This is a code for simple pendulum. When I use this code group, acceleration comes out wrong(it goes between max 3.. when it should be 13.). What am I doing wrong? When I use sind and put 45 degrees instead of sin and 0.78 radia, this time I get 30 ish something as a max result when it shouldn't change.
Original Eqn: Theta''=-g*sin(Theta)/ l
  댓글 수: 2
madhan ravi
madhan ravi 2018년 12월 31일
why 13 any reason?
Arda Nova
Arda Nova 2018년 12월 31일
편집: Arda Nova 2018년 12월 31일
dydt(2)=-((9.81*sin(y(1)))/0.5);
At the bottom, acceleration is maximum. If you put 270 degrees acceleration comes 19.62 rad/sec^2 (Sorry I had made a mistake at taking the degree. Tried it too, wrong result). One think is for sure, acceleration should not be affected from me using radian or degrees. I don't even know where does the program gets the 3.something. If I knew then I would maybe solve the issue but, couldn't figure it out.

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

채택된 답변

Stephan
Stephan 2019년 1월 1일
편집: Stephan 2019년 1월 1일
Hi,
ode45 integrates your second order ode two times. So the result of ode45 will be angle and velocity over time. To get acceleration you have to calculate it seperatly:
% initial conditions of angle and velocity
dydt = [pi/2; 0];
% integrat ode to get angle an velocity
[t1,y1] = ode45(@idn, [0 20], dydt);
% calculate acceleration
y1(:,3) = -9.81.*sin(y1(:,1))./0.5;
% plot results
plot(t1,y1(:,1),t1,y1(:,2),t1,y1(:,3));
grid on;
function dydt = idn(t, y)
dydt = zeros(2,1);
dydt(1)=y(2);
dydt(2)=-((9.81*sin(y(1)))/0.5);
end
Best regards
Stephan
  댓글 수: 1
Arda Nova
Arda Nova 2019년 1월 1일
I am very thankful to you, good sir. You have no idea how much you have helped.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by