Trying to do calculations for density

9 visualizzazioni (ultimi 30 giorni)
%% 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?

Risposta accettata

James Tursa
James Tursa il 1 Lug 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 Commento
Sean St Cyr
Sean St Cyr il 1 Lug 2020
Oh my gosh, Thank you, I was completely overlooking those, just needed a another set of eyes

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Historical Contests in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by