1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Second Order Non linear ode matlab

  1. Oct 2, 2015 #1
    1. The problem statement, all variables and given/known data

    Okay the problem is of a free swinging pendulum with dampening which is modelled 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

    2. Relevant equations

    3. 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);


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

  2. jcsd
  3. Oct 6, 2015 #2


    User Avatar
    Science Advisor
    Homework Helper
    2017 Award

    Did you try to google something ? I found several matlab RK4 integrator codes in no time at all !
  4. Oct 6, 2015 #3
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted