Trying to do calculations for density

11 vues (au cours des 30 derniers jours)
Sean St Cyr
Sean St Cyr le 1 Juil 2020
Commenté : Sean St Cyr le 1 Juil 2020
%% Variables
% Input
% P_t - Total pressure [atm]
% P_s - Surface pressure [atm]
% H - Height [ft]
% Output
% rho - Density [kg/m^3]
% Other
% g - Gravity [m/s^2]
% Write your entire function code below here (Including header)
function [Rho] = RQ16_18(P_t,P_s,H) % The order of input variables should be Total Pressure, Surface Pressure, and Height
% Constants
P_t=4;
P_s=3;
H=25;
% Calculations
H = H/3.281; %Convert Ft to Meters
Tp = P_t * 101325; %Convert Atm to Pascals
Sp = P_s * 101325; %Convert Atm to Pascals
g = 9.8; %gravity
Rho = (Tp - Sp)/(g*H); %Density
end
I am trying to get the density and its defined as Rho however when matlab grader grades it it says the value is wrong. Am I missing a conversion? or Caluclation?

Réponse acceptée

James Tursa
James Tursa le 1 Juil 2020
Why do you have these lines in your function:
P_t=4;
P_s=3;
H=25;
Aren't these variable supposed to be input arguments? Seems like you should delete these lines since they overwrite the input arguments.
  1 commentaire
Sean St Cyr
Sean St Cyr le 1 Juil 2020
Oh my gosh, Thank you, I was completely overlooking those, just needed a another set of eyes

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Historical Contests dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by