Blank graph? Attempting to plot velocity vs. time

2 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 3 Feb 2016
Edited: Image Analyst on 3 Feb 2016
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);
  1 Comment
mwentz92
mwentz92 on 3 Feb 2016
That worked! I figured it was something small like that. Thank you so much!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!