Equation of motion of Non linear pendulum

30 次查看(过去 30 天)
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 个评论
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