Graphing a nonlinear 2nd order differential equation?

16 visualizaciones (últimos 30 días)
Daniel Keith
Daniel Keith el 19 de Oct. de 2020
Comentada: Ameer Hamza el 19 de Oct. de 2020
I've searched around for a similar solution to what I'm looking for but I'm terrible at debugging. I need to graph this nonlinear 2nd order differential equation:
g = 9.81
m = 15000/g
L = 1.5 meters
J = m*L^2
J*theta_dd + m*L*g*sin(theta) = 0

Respuestas (1)

Ameer Hamza
Ameer Hamza el 19 de Oct. de 2020
See ode45(): https://www.mathworks.com/help/matlab/ref/ode45.html espically the example titled "Solve Nonstiff Equation".
IC = [1; 0]; % initial condition
tspan = [0 10];
[t, theta] = ode45(@odefun, tspan, IC);
plot(t, theta);
legend({'$\theta$', '$\dot\theta$'}, 'FontSize', 16, 'Interpreter', 'latex');
function dtheta = odefun(t, theta)
% theta(1) = theta, theta(2) = theta_dot
g = 9.81;
m = 15000/g;
L = 1.5;
J = m*L^2;
dtheta1 = theta(2);
dtheta2 = -m*L*g*sin(theta(1))/J;
dtheta = [dtheta1; dtheta2];
end

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by