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:
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'