How do I plot acceleration from my ODE45 function?
古いコメントを表示
Hey guys, I'm doing a simple spring mass damper problem using ODE45 and I'd like to generate plots of the acceleration, along with the displacement and velocity plots I already have. This is my main code:
[t,y]=ode45(@(t,y) func(t,y),[0,100],[10,0]);
figure(1)
plot(t,y(:,1));
xlabel('Time (s)')
ylabel('Displacment (m)')
figure(2)
plot(t,y(:,2));
xlabel('Time (s)')
ylabel('velocity (m/s)')
%figure(3)
%plot(t,ydot(:,2))
%xlabel('Time (s)')
%ylabel('Acceleration (m/s/s)')
With this function being called:
function ydot=func(t,y)
k=1000;
c=1200;
m=7000;
ydot(1)=y(2);
ydot(2)=((-k*y(1))/m) + ((-c*y(2))/m);
ydot=ydot';
end
What I'd like to plot is ydot(2) versus time but it doesn't stay in the work space when I run it without using the debugger and I get an error that tells me my ydot is not defined.
Any help would be appreciated.
Thanks, Conor.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!