I have a simple m file that I created as a recursive function:
function[velocity] = terminal(m,c,t,vi)
%inputs:
% m = mass
% c = coeffcient of drag
% t = time
% vi = initial velocity
if t==18, velocity = vi+(9.8-c/m*(vi))*2;
return
end
velocity = vi+(9.8-c/m*(vi))*2;
velocity %used to print out velocity for debugging
terminal(m,c,t+2,velocity);
end
The speed calculation is done correctly when it outputs each recursion. However, the "ans" that returns at the end is the first calculated recursion value. My question is: how to configure matlab function correctly recursively? Or can this be done, and is it better to use a loop?
source
share