Help storing values for Ma and Cd so I can create a plot for them.

1 次查看(过去 30 天)
% initializing variables
h = 0.0001; %delta t [s]
k = 1.4; %specific heat ratio for air
R = 1716.5; %gas constant [(ft*lbf)/(slugs*R)]
g = 32.174; %acceleration due to gravity [ft/s^2]
W = 55; %weight [lbf]
m = W/g; %mass [slugs]
d = 3/12; %diameter [ft]
A = pi*1/4*d^2; %Area [ft^2]
N = 55000; % number of iterations
xf = 5280*7.1; % final distance [ft]
x = zeros(1,N); % distance [ft]
y = zeros(1,N); % height [ft]
Vx = zeros(1,N);
Vy = zeros(1,N);
V = zeros(1,N);
%Accelx = zeros(1,N);
%Accely = zeros(1,N);
mach = 7*1125; %conversion Ma units
theta(1) = 89.165031*(pi/180); % initial angle [rad] | can't assume it's constant, needed to find x_o, y_o, V_o
Vx(1) = mach*cos(theta(1)); % first step of velocity in x-dir [ft/s]
Vy(1) = mach*sin(theta(1)); % first step of velocity in y-dir {ft/s]
V(1) = sqrt((Vx(1))^2 + (Vy(1))^2);
x(1) = 0; % first step of position[ft]
y(1)= 0;
for n = 2:N
[T, p, rho] = atmos_funEE (y(n-1)); %calling function given to find rho, p, T at y
c = sqrt(k*R*T);
V = sqrt((Vx(n-1))^2 + (Vy(n-1))^2); %V = velocity [ft/s]
Ma = V/c; % Ma number
[Cd] = Ma_Cd_curvefit (Ma); %Curve fit of Ma vs. Cd
x(n) = x(n-1) + h*Vx(n-1);
Vx(n) = Vx(n-1) + h*(-1/2*1/m*rho*A*Cd*V*Vx(n-1));
y(n) = y(n-1) + h*Vy(n-1);
Vy(n) = Vy(n-1) + h*(-g-(0.5*(1/m)*rho*A*Cd*V*Vy(n-1)));
end
plot(x,Cd)
plot(x,Ma)
  1 个评论
Dennis Williams
Dennis Williams 2020-7-31
Whenever I plot (x,Cd) and (x,Ma), I get a blank screen without a line as I was expecting as if only a point is being plotted and and not all the points from all the iterations

请先登录,再进行评论。

回答(1 个)

Sudheer Bhimireddy
The problem is inside the for loop.
Change this
V = sqrt((Vx(n-1))^2 + (Vy(n-1))^2); %V = velocity [ft/s]
Ma = V/c; % Ma number
to
V(n) = sqrt((Vx(n-1))^2 + (Vy(n-1))^2); %V = velocity [ft/s]
Ma(n) = V(n)/c; % Ma number
and try again to plot. Similarly check the size and values of Cd. Also when you have two plots and if you want both of them to be on the same plot. use 'hold on', otherwise the latest plot() will overwrite the previous one.
plot(x,Cd);
hold on;
plot(x,Ma);

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by