ode45 Set of 3 second order ODE not solving correctly
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!