How to solve this 4th order linear ODE with ode45?

4 views (last 30 days)
initial conditions
This is what I have so far:
x_1_0 = [2; 1/2; 0; 0;];
[t_1,x_1] = ode45(@f, tspan, x_1_0);
function dxdt = f(t,x)
m_1 = 0.549;
m_2 = 0.510;
b_1 = 2;
b_2 = 2;
k_1 = 332;
k_2 = 332;
dxdt = [
x(2);
x(3);
x(4);
((-1)*(m_1*b_1 + m_2*b_2).*x(4) - (m_2*k_1 + k_2*(m_1+m_2) + b_1*b_2).*x(3) - (k_1*b_2 + k_2*(b_1 + b_2)).*x(2) - (k_1*k_2).*x(1)) / (m_1*m_2)];
end

Answers (1)

Alan Stevens
Alan Stevens on 4 Aug 2021
You need to define tspan
x_1_0 = [2; 1/2; 0; 0];
tspan = [0 10]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[t_1,x_1] = ode45(@f, tspan, x_1_0);
plot(t_1,x_1(:,1)),grid
function dxdt = f(~,x)
m_1 = 0.549;
m_2 = 0.510;
b_1 = 2;
b_2 = 2;
k_1 = 332;
k_2 = 332;
dxdt = [
x(2);
x(3);
x(4);
((-1)*(m_1*b_1 + m_2*b_2).*x(4) - (m_2*k_1 + k_2*(m_1+m_2) + b_1*b_2).*x(3) - (k_1*b_2 + k_2*(b_1 + b_2)).*x(2) - (k_1*k_2).*x(1)) / (m_1*m_2)];
end

Tags

Community Treasure Hunt

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

Start Hunting!