# 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 日間)
Peter Meyers 2021 年 10 月 10 日

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)

サインインしてコメントする。

### 回答 (1 件)

Kshitij Chhabra 2021 年 10 月 13 日
You can check the following link to learn some of the best practices for writing comments in your code

サインインしてコメントする。

### カテゴリ

Find more on L*a*b* Color Space in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by