Borrar filtros
Borrar filtros

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 visualización (últimos 30 días)
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)

Respuestas (1)

Kshitij Chhabra
Kshitij Chhabra el 13 de Oct. de 2021
You can check the following link to learn some of the best practices for writing comments in your code


Más información sobre Foundation and Custom Domains en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by