Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Cannot plot time vs displacement graph

2 ビュー (過去 30 日間)
Gazza Dazzle
Gazza Dazzle 2014 年 9 月 5 日
閉鎖済み: Steve Miller 2022 年 12 月 21 日
Hi I am struggling to plot time vs displacement graph for my pendulum program, i can only plot the animation of the pendulum but not a graph of it. Any ideas?
thanks
l=0.4;
m=0.5;
g=9.81;
b=0.05;
sampling=0.01;
runningstep=200;
timespan=sampling*runningstep;
x0=[pi/4
0];
%main program for numberical solution
k=1;
while(k<1000)
[t,y]=ode45(@pendulum,[0 sampling],x0,[],l,b,m);
if k==1
yp(1,:)=y(1,1:2);
tp(1,:)=t(1,1);
else
yp(k,:)=y(size(y,1),1:2);
tp(k,1)=sampling*k;
end
%update date
x0=y(size(y,1),1:2); %change initial value
k=k+1;
end
%Time Displacement Graph
plot(t,y)
title('time displacement graph')
%animation
xa=l*sin(yp(:,1));
ya=-l*cos(yp(:,1));
hp=plot([0,0],[xa(1),ya(1)],'linewidth',2,'Marker','o','Erasemode','xor');
axis([-l-0.1 l+0.1 -l-0.1 l+0.1]);
title('Pendulum problem');
xlabel('Displacement (degrees)');
ylabel('Angular velocity (radians/sec.)');
for i=1:size(tp)
set(hp,'xdata',[0,xa(i)],'ydata',[0,ya(i)]);
drawnow
pause(0.01);
grid on
mov(i)=getframe;
end
movie2avi(mov,'pendulum.avi')
funtion file
function dy=pendulum(t,y,l,m,b)
dy(1,1)=y(2,1);
dy(2,1)=-9.81/l*sin(y(1,1)-b/(m*l^2)*y(2,1));
  1 件のコメント
Jan
Jan 2014 年 10 月 5 日
I do not understand what kind of "graph" you are looking for.

回答 (0 件)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by