# Trying to do calculations for density

13 views (last 30 days)
Sean St Cyr on 1 Jul 2020
Commented: Sean St Cyr on 1 Jul 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]
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?

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