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 view (last 30 days)
Peter Meyers
Peter Meyers on 10 Oct 2021
Answered: Kshitij Chhabra on 13 Oct 2021
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
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)

Community Treasure Hunt

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

Start Hunting!

Translated by