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: Matlab - Numerical Analysis

  1. Oct 7, 2011 #1
    1. The problem statement, all variables and given/known data

    An object of mass m falls from rest at a point near the earth's surface. If the air resistance is proportional to the velocity v^2, the differential equation for the velocity as a function of time is given by m*dv/dt = mg - cv^2

    For the given paraments g = 9.81 m/s^2. m = 68.1 kg and c = 1.5 kg/m. plot the exact solution and the numerical solution v(t) obtained from the 4th order predictor-corrector runge kutta methods using an interval of dt = 0.25 seconds in the domain of 0<t<6

    (I need help with the code of runga kutta, im horrible at matlab

    2. Relevant equations

    m*dv/dt = mg - cv^2

    3. The attempt at a solution

    g = 9.81
    m = 68.1
    c = 1.5
    tmax = 6
    dt = 0.25
    t = [0:dt:tmax]
    v(1) =1;

    %Exact Solution
    vs = sqrt(m*g/c)*tanh(t*sqrt(g*c/m));
    plot(t,vs,'s'), hold on

    for i = 1:length(t)-1
    f= g - c*v(i).^2/m;
    k1= f(v(i));
    k2= f(t(i)+(dt/2), v(i) + (dt/2)*k1);
    k3 =f(t(i)+(dt/2), v(i) + (dt/2)*k2);
    k4 =f(t(i)+ dt, + v(i) + dt*k3);
    v(i+1) = v(i) + (dt/6)*(k1+2*k2+2*k3+k4);
  2. jcsd
  3. Oct 7, 2011 #2
    If you look in the first row of the for loop, the vector v is not defined so the code dosen't make sense.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook