How to Form Continuous Curve Plot

7 visualizaciones (últimos 30 días)
Matthew
Matthew el 10 de Mzo. de 2015
Comentada: Star Strider el 11 de Mzo. de 2015
I have the following code. At the end, I issue the plot command. The resulting figure shows hundreds of discrete points along the plot. Is there someway to tell Matlab to connect those points to form a continuous curve, simply so the end product looks more like a curve instead of many tiny little dots?
I'm new, so please provide answers in simple terms with clear explanation, since I'm trying to learn and get a better understanding.
Thanks,
M Ridzon
%Define ratio of specific heats
gamma=1.4;
%Define gas constant
R=287; %(J/Kg/K)
%Define reservoir properties
P_Res=500; %(kPa)
T_Res=500; %(Kelvin)
%Define nozzle exit area
NozArea=50; %(cm^2)
%Find pressure ratio when nozzle exit plane becomes choked.
P_Ch=((1+((gamma-1)./2).*((1.0).^2)).^(gamma./(gamma-1))).^-1;
%From critical pressure ratio, find actual back pressure which causes choke
P_Crit=P_Res.*P_Ch; %(kPa)
%Find density of fluid in reservoir
rho_Res=P_Res.*1000./R./T_Res;
%***********************************
%Calculate m-dot for choked case
%***********************************
%Find temperature of air exiting nozzle
T_Exit_Ch=T_Res./(1+((gamma-1)./2).*((1.0).^2)); %(K)
%Find speed of sound for the given temperature
a_Exit_Ch=(gamma.*R.*T_Exit_Ch).^0.5; %(m/s)
%Find fluid density from equation of state
rho_Exit_Ch=(P_Crit.*10.^3)./R./T_Exit_Ch; %(kg/m^3)
%Find m-dot
m_dot_Ch=rho_Exit_Ch*a_Exit_Ch*NozArea*((1/100)^2); %(kg/s)
%***********************************
%Begin FOR loop
%***********************************
for i=0:P_Res/500:P_Res
if i<=P_Crit
m_dot=m_dot_Ch;
else
%Find mach speed of fluid exiting nozzle
M=((2./(gamma-1)).*((P_Res./i).^((gamma-1)./gamma)-1)).^0.5;
%Find temperature of air exiting nozzle
T_Exit_Norm=T_Res./(1+((gamma-1)./2).*(M.^2)); %(K)
%Find density of air exiting nozzle
rho_Exit_Norm=rho_Res./((1+((gamma-1)./2).*(M.^2)).^(1./(gamma-1))); %(kg/m^3)
%Find speed of sound for the given temperature
a_Exit_Norm=(gamma.*R.*T_Exit_Norm).^0.5; %(m/s)
%Find exit velocity
V_Exit_Norm=M.*a_Exit_Norm; %(m/s)
%Find m-dot
m_dot=rho_Exit_Norm*V_Exit_Norm*NozArea*((1/100)^2); %(kg/s)
end
P_Ratio=i./P_Res;
plot(P_Ratio,m_dot,'Color','k');
hold on %Hold plotting until the conclusion
end
title('Ratio of Back Pressure to Reservoir Pressure vs. Mach Number')
xlabel('Pb / Pr')
ylabel('Mach Number')
hold off

Respuesta aceptada

Star Strider
Star Strider el 11 de Mzo. de 2015
Create ‘i’ as a vector, and then subscript it and your variables where necessary:
%***********************************
%Begin FOR loop
%***********************************
i=0:P_Res/5000:P_Res;
for k1 = 1:length(i)
if i(k1)<=P_Crit
m_dot(k1)=m_dot_Ch;
else
%Find mach speed of fluid exiting nozzle
M=((2./(gamma-1)).*((P_Res./i(k1)).^((gamma-1)./gamma)-1)).^0.5;
%Find temperature of air exiting nozzle
T_Exit_Norm=T_Res./(1+((gamma-1)./2).*(M.^2)); %(K)
%Find density of air exiting nozzle
rho_Exit_Norm=rho_Res./((1+((gamma-1)./2).*(M.^2)).^(1./(gamma-1))); %(kg/m^3)
%Find speed of sound for the given temperature
a_Exit_Norm=(gamma.*R.*T_Exit_Norm).^0.5; %(m/s)
%Find exit velocity
V_Exit_Norm=M.*a_Exit_Norm; %(m/s)
%Find m-dot
m_dot(k1)=rho_Exit_Norm*V_Exit_Norm*NozArea*((1/100)^2); %(kg/s)
end
P_Ratio(k1)=i(k1)./P_Res;
end
plot(P_Ratio,m_dot,'Color','k');
hold on %Hold plotting until the conclusion
title('Ratio of Back Pressure to Reservoir Pressure vs. Mach Number')
xlabel('Pb / Pr')
ylabel('Mach Number')
hold off
Every instance of ‘i’ in your original code should now be ‘i(k1)’. Check this in the event I missed any.
Also, it’s best not to use ‘i’ or ‘j’ as variables, including loop counters, because MATLAB uses them as its imaginary operators. Using them otherwise causes confusion.

Más respuestas (1)

Matthew
Matthew el 11 de Mzo. de 2015
Star Strider,
Perfect! Got it! Thanks!
M Ridzon

Categorías

Más información sobre Fluid Dynamics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by