Just need a quick answer on whether this function and script make sense or if I need to make it more clear so that it is easier to understand
1 次查看(过去 30 天)
显示 更早的评论
Im trying to write a function and script to determine the pressure in a sealed container with a volume of 5 gallons containing 25 moles of methane at a temperature of 155*C
This is the function that I wrote
function [P] = Pressure_Conversion(n, v, t)
% Determine the pressure given volume, temperature, and number of moles of
% methane
%
% Variables
%
% P = Pressure in atm
% n = Number of moles of methane
% r = Ideal Gas Constant
% v = Volume in Liters
% t = temperature in kelvin (*C+ 273.15)
%
% Calculations
%
r = 8.314; % L kPaK^-1
P = n*r*t/v; % atm
end
And this is the script I wrote
% Script for determining the pressure given the volume, temperature and
% number of moles of methane
%
% Inputs
%
n = input('Number of moles of Methane=');
v = input('Volume in Gallons=');
t= input('Temperature in Celcius=');
%
%Convert variables to correct units
%
v = v*3.785;
t = t+273.15;
%
%Call in Function
%
P = Pressure_Conversion(n, v, t);
%
%Print Function
%
fprintf('The pressure is %.3f atm\n',P)
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oil, Gas & Petrochemical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!