How to Plot multiple things?

Hi, For some reason when I run this code I can't get the plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3], 0.5, 'r-') right. Does anyone know why? Thanks in advance. Here is my code
% case 1
w_speed = [1; 1.1; 1.5; 2.5; 3; 4; 4.3; 5; 5.9; 6.1]; %in mph
d_force = [.05; .06; .09; .1; .11; .15; .21; .25; .3; .35]/10
w_speed = w_speed*0.44704 % converts mph to meters per second
speed_force=[w_speed d_force] % wind speed and its corresponding drag force
% USV DATA
l_usv = 0.45; % lenght of usv (metric)
w_usv= .18; % width of usv
h_usv = .09; % height of usv
% NAVY BOAT DATA
l_boat = 12; % length of the navy boat in m
v_boat = 5; % velocity of the boat m/s
% for air at atmospheric pressure and T = 25 degrees centigrade we have:
ro = 1.184; % air density in kg/m^3
mu = 1.849*(10^-5); % air viscosity in kg/m.s
% calculating drag coeff and reynolds number for the model
a = w_usv*h_usv;
c_d = 2*d_force./(ro*(w_speed.^2)*a) % drag Coeff
re_m = ro*w_speed*w_usv/mu % reynolds number
subplot(2,1,1)
p1 = polyfit(w_speed, d_force, 1); % returns 2 coefficients fitting r = a_1 * x + a_2
r2 = p1(1).* w_speed + p1(2);
plot(w_speed, d_force, 's', w_speed, r2)
xlabel 'Wind Speed (m/s)'
ylabel 'Drag Force (N)'
legend ('Measured data', 'Best fit curve')
subplot(2,1,2)
p2= polyfit(re_m, c_d, 6);
f = polyval(p2,re_m);
% table = [re_m c_d f c_d-f]
plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3], 0.5, 'r-')
%plot([0:.01:3], 0.5, 'r-')
xlabel 'Reynolds number'
ylabel 'C_D'
legend ('Measured data', 'Best fit curve')

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 19 日

0 投票

check the value of re_m. It's much larger than [0:.01:3]. That's why you didn't see the red line. Try:
figure;
plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3]*1e4, 0.5, 'r-')

3 件のコメント

Villanova
Villanova 2011 年 8 月 19 日
Thank you very much Fangjun. I just noticed what I had been wrong since this morning. You are a life saver!
Walter Roberson
Walter Roberson 2011 年 8 月 19 日
Also, you might have to make 0.5 to be same size as the [0:.01:3]
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 19 日
@Walter. No, not needed! figure;plot(1:100,1) shows the curve. Something I learned too!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by