ode45 Set of 3 second order ODE not solving correctly
1 回表示 (過去 30 日間)
古いコメントを表示
Attempting to solve 3 2nd order ODE's (broken down into 6 1st orders here) using ode45. My answer does not appear to come out correctly and am not sure what I am doing wrong.
CODE:
tspan=[0 60]; %Time Boundaries
x0=[0 0 0 0 0 0]; %Inital Values of disp and vel
[t,x]=ode45(@output,tspan, x0) %Implement ode45 solver
plot(t,x)
xlabel('time')
ylabel('displacement/velocity')
title('Problem 25.18')
legend('Displacement','Velocity')
function dxdt=output(t,x) %Create system of equations
m1=60;
m2=70;
m3=80;
k1=50;
k2=100;
k3=50;
g=9.81;
dxdt=zeros(6,1);
dxdt(1)=x(1);
dxdt(2)=x(2);
dxdt(3)=x(3);
dxdt(4)=g+(k2/m1)*(x(2)-x(1))-(k1/m1)*x(1);
dxdt(5)=g+(k3/m2)*(x(3)-x(2))+(k2/m2)*(x(1)-x(2));
dxdt(6)=g+(k3/m3)*(x(2)-x(3));
end
0 件のコメント
採用された回答
David Goodmanson
2020 年 4 月 20 日
Hi William,
you are close on this. x1,x2,x3 are postions and x4,x5,x6 are velocities so the appropriate lines of code are
dxdt(1)=x(4);
dxdt(2)=x(5);
dxdt(3)=x(6);
in which case you get oscillations.
g is positive which makes positive x in the direction of down. That's all right as long as you acknowledge the fact in a picture or something. g = -9.81 would put positive x up which is more common.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!