# Matlab - Numerical Analysis

1. Homework Statement

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. Homework Equations

m*dv/dt = mg - cv^2

3. The Attempt at a Solution

clear
clc
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

%Runge-Kutta
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);
end