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

7 visualizaciones (últimos 30 días)
Andy Zhao
Andy Zhao el 4 de Ag. de 2021
Respondida: Alan Stevens el 4 de Ag. de 2021
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

Respuestas (1)

Alan Stevens
Alan Stevens el 4 de Ag. de 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

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by