Equation of motion of Non linear pendulum
9 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!