Problem 45411. Compute the missing quantity among P, V, T for an ideal gas
Consider 100 mol of helium gas at a certain pressure (P), volume (V), and temperature (T). Assuming that the ideal gas law applies, can you compute one of the 3 quantities given the other two?
Recall that, with SI units, the ideal gas law is given by:
P x V = n x R x T where: P = pressure [Pa] or [kg/m/s^2] V = volume [m^3] n = number of moles [mol] R = gas constant, 8.314 [J/mol/K] or [kg.m^2/K/mol/s^2] T = temperature [K]
Write a function that takes a MATLAB variable, x, which is always a 3-element row vector containing the values of P, V, T in that order. However, exactly one of these values will be NaN, which you must solve using the ideal gas law equation above, given the other two values. All inputs are given in SI units, hence, you can use the given value of R above. Note that n = 100 mol. You are ensured that P, V, and/or T are floating-point numbers with 2 decimal places that satisfy the following constraints:
- 1 x 10^5 <= P <= 3 x 10^5
- 1 <= V <= 10
- 300 <= T <= 500
Output the value of the missing quantity rounded to 2 decimal places, followed by a space, and then the correct units, either Pa, m^3, or K. For this, you can use sprintf. See sample test cases:
>> idealgas([233424.06 NaN 435.02]) ans = '1.55 m^3' >> idealgas([109238.31 2.76 NaN]) ans = '362.64 K' >> idealgas([NaN 1.19 411.97]) ans = '287825.09 Pa'
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers150
Suggested Problems
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1828 Solvers
-
Back to basics 11 - Max Integer
785 Solvers
-
711 Solvers
-
840 Solvers
-
535 Solvers
More from this Author19
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!