Equation of motion of Non linear pendulum

조회 수: 35 (최근 30일)
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS 2020년 11월 4일
댓글: Bjorn Gustavsson 2020년 11월 4일
tspan=[0,2*pi];
u0=[pi/4;0];
[t,u]=ode45(@pendulum,tspan,u0,[]);
plot(t,u(:,1),'b-', 'LineWidth', 2)
xlabel('time')
ylabel('angle')
function zdot = pend (t,z)
wsq = 1.56; % specify a value of w"2
t = time;
z = [z (l) ; z ( 2)] = [theta; thetadot]
zdot = [z (2) ; -wsq* sin (z(l))];
end
This doesn't seem to be working. I'm trying to plot the discplacement versus time and velocity versus time. Any idea as to what the problem mightbe?
I got this from Rudra pratap. I've attached a link to the book, it's on page 159 (173 by docs)

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 11월 4일
Note that the function you use for the input-argument to ode45 is pendulum while the function you implemented for the pendulum has the name pend. They should be the same. When that's fixed there seems to be no major problems with your code:
u0=[pi/4;0];
pend = @(t,z) [z(2);-1.56*sin(z(1))];
figure
tspan=[0,12*pi]; % just a slightly longer time-span
[t,u]=ode45(pend,tspan,u0,[]);
plot(t,u)
HTH
  댓글 수: 3
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS 2020년 11월 4일
i got this error
Bjorn Gustavsson
Bjorn Gustavsson 2020년 11월 4일
Ok, that is because your script is named pend.m and then matlab doesn't like the naming-confusion with a variable with that name in the script. You should be fine if you rename the variable to someting like pendODE for example.
HTH

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

추가 답변 (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