Second Order Non linear ode matlab

Click For Summary
SUMMARY

The discussion centers on solving a second-order nonlinear ordinary differential equation (ODE) for a damped pendulum using MATLAB. The parameters include a damping coefficient of c=1 s-1, mass m=1 kg, gravity g=9.81 m/s2, and a link length l=0.5 m. The equation is solved over the interval from t=0 to t=10 seconds with a time step of 0.01 seconds using methods such as Euler, Heun, and the 4th order Runge-Kutta. The user seeks guidance on implementing the Euler and Heun methods and understanding the 4th order Runge-Kutta technique.

PREREQUISITES
  • Understanding of second-order nonlinear ordinary differential equations (ODEs)
  • Familiarity with MATLAB programming and function creation
  • Knowledge of numerical methods for ODEs, specifically Euler and Runge-Kutta methods
  • Basic physics concepts related to pendulum motion and damping
NEXT STEPS
  • Research the implementation of the Euler method in MATLAB
  • Study the Heun method and its application for solving ODEs
  • Learn about the 4th order Runge-Kutta method and its MATLAB implementation
  • Explore additional resources on numerical methods for solving differential equations
USEFUL FOR

This discussion is beneficial for students and professionals in physics, engineering, and applied mathematics who are working on numerical solutions for differential equations, particularly in the context of mechanical systems like pendulums.

SteliosVas
Messages
70
Reaction score
0

Homework Statement



Okay the problem is of a free swinging pendulum with dampening which is modeled using the following equation:

Damping coefficient: c=1 s−1
Mass: m=1 kg
Gravity: g=9.81 ms−1
Link length: l=0.5 m

We know
θ(0)=90° and θ′(0)=0, solve this equation from t = 0 to t = 10 with a time interval of 0.01s The equation is:

d2θ/dt2+(c/m)*(dθ/dt)+(g/l)*sin (θ)=0

So we need to use Euler,Heun and 4th order Runge-Kutta method

Homework Equations

The Attempt at a Solution



Okay so my idea was to create a function as so:

function xdot=pendemo(t,x)
% PENDEMO Pendulum ODE derivative evaluation

xdot(1,1) = x(2,1);

xdot(2,1) = -1/(1*1)*x(2,1) - 9.81/1*sin(x(1,1));

% End of pendemo.m

and than an m.file giving the above information:

xphi = [pi/2;0];

tphi = 0; 5 %start time

tfin = 10; %end time

[t,x] = ode45('pendemo',[tphi tfin],xphi);

plot(t,x(:,1))

The only thing is how do I implement a euler/heun method? What is a 4th order Runga Kata??

thanks
 
Physics news on Phys.org
Did you try to google something ? I found several MATLAB RK4 integrator codes in no time at all !
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
15
Views
3K
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K