フィルターのクリア

Integrating 2nd order differential equation with ode45

1 回表示 (過去 30 日間)
Ryan Bowman
Ryan Bowman 2018 年 12 月 9 日
コメント済み: madhan ravi 2018 年 12 月 9 日
I'm trying to complete this assignment but I am having trouble with my code and I'm not sure why. Here is my assignment
Screen Shot 2018-12-09 at 12.33.03 AM.png
Here is my code I have written:
ti = 0;
tf = 10;
x0 = [1 0];
mass = 0;
b = 2.5;
k = 0;
for ii = 1:3
mass = mass + 1;
b = b-0.5;
k = k+2;
[time,position] = ode45(@(t_p2,x)odeMSD(t_p2,x,mass,b,k),[ti tf], x0);
figure(2), hold on
subplot(1,3,ii), hold on
plot(time,position(:,1), 'm') , plot(time,position(:,2), 'k')
legend('X Position (m)', 'Velocity (m/s)')
xlabel('Time (s)')
end
subplot(1,3,1)
title('1st Parameter')
subplot(1,3,2)
title('2nd Parameter')
subplot(1,3,3)
title('3rd Parameter')
hold off
function xde = odeMSD(t_p2,x,m,b,k)
xde = zeros(2,1);
xde(1) = x(1);
xde(3) = -(b./m).*x(2) - (k./m)*x(1);
end

採用された回答

madhan ravi
madhan ravi 2018 年 12 月 9 日
xde(2) = -(b./m).*x(2) - (k./m)*x(1);
^----------should be 2 not 3!
  2 件のコメント
Ryan Bowman
Ryan Bowman 2018 年 12 月 9 日
Thank you!! I think also my initial conditions might be entered in wrong. Is this true?
madhan ravi
madhan ravi 2018 年 12 月 9 日
Anytime :) , yes it should be
x0 = [1 1];
^----should be 1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by