Graphing a nonlinear 2nd order differential equation?

4 ビュー (過去 30 日間)
Daniel Keith
Daniel Keith 2020 年 10 月 19 日
コメント済み: Ameer Hamza 2020 年 10 月 19 日
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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 19 日
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
  2 件のコメント
Daniel Keith
Daniel Keith 2020 年 10 月 19 日
Thank you!
Ameer Hamza
Ameer Hamza 2020 年 10 月 19 日
I am glad to be of help!!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by