You are on page 1of 1

MBE2036 Engineering Computing, part 3, version 4, Dr.

Yajing SHEN 5

M-File for calculating the velocity profile


c
v (t i +1) = v (t i ) + g v (t i )(t i +1 t i ) Eq 1.33
m
function vel = velocity_profile(dt, ti, tf, vi, m, c)
% velocity_profile(dt, ti, tf, vi, m , c)
% Calculate the velocity of an free-falling object
% using Euler's method

t = ti;
v(1) = vi;
i=2; Infinite loop
while (1)
if t+dt > tf break out from the loop
if t + dt > tf, break, end
dvdt = deriv(v(i-1), m, c);
v(i)=v(i-1) + dvdt * dt;
t=t+dt;
i=i+1;
end

vel = v;
Department of Mechanical and
Biomedical Engineering City University of Hong Kong

You might also like