MATLAB: Blank graph? Attempting to plot velocity vs. time

for loopsincrementsplotting

I am trying to calculate the terminal velocity of a bicyclist, and I cannot for the life of me figure out how to plot it. This is the code I've got so far:
%% Sets the parameters
P = 400; % Watts
A = 0.4; % Squared meters
m = 65; % Kilograms
rho = 1.3; % Kilograms per cubic meter
C = 0.5; % Air resistance constant
%% Sets the initial conditons
v1 = 1; % (m/s)
v = v1; % (m/s)
tau = 0.1; % (s)
%% Calculates the terminal velocity
for i = 1:100
t = (i - 1)*tau;
v = v + ((P/(m*v)))*t - ((C*rho*A*v^2)/(2*m))*t;
end
plot(t,v);
Now what I think is happening is the loop calculates the time value, saves it, uses it for the velocity, saves that, and repeats. But when I go to generate the plot, I just get a blank graph. Any insight into how to get the nice shape the graph should have would be appreciated.

Best Answer

v and t are just single numbers. You need to index them to make them arrays. Try this:
% Sets the parameters
P = 400; % Watts
A = 0.4; % Squared meters
m = 65; % Kilograms
rho = 1.3; % Kilograms per cubic meter
C = 0.5; % Air resistance constant
% Sets the initial conditons
v1 = 1; % (m/s)

v(1) = v1; % (m/s)
tau = 0.1; % (s)
% Calculates the terminal velocity
for i = 2:100
t(i) = (i - 1)*tau;
v(i) = v(i-1) + ((P/(m*v(i-1))))*t(i) - ((C*rho*A*v(i-1)^2)/(2*m))*t(i);
end
plot(t,v, 'b*-', 'LineWidth', 2);