# Graphing a nonlinear 2nd order differential equation?

3 views (last 30 days)
Daniel Keith on 19 Oct 2020
Commented: Ameer Hamza on 19 Oct 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

Ameer Hamza on 19 Oct 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

Daniel Keith on 19 Oct 2020
Thank you!
Ameer Hamza on 19 Oct 2020
I am glad to be of help!!!