HW2

advertisement
Computer Science 106: MATLAB
HW 2, due 2/5
Build a table
The ideal gas law is
pV = nRT
R = 8.31446 J/mol K for pressure in Pascals, volume in cubic meters, T Kelvin, n
moles. (1 atm = 101325 Pa = 101.325 Bar, 1 Pa = 1 N/m2) (try the calculation for
standard temperature and pressure: 101325 Pa (1 atm) and 273 K for 1 mole and
find that the volume is .0224 m3 or 22.4 liters)
If one takes into account, the finite size of molecules instead of treating molecules as
points, and the van der Waals attraction between neutral molecules, one derives the
van der Waals gas equation:
(p+ a n2/V2) (V- nb) = nRT
You can find tables of van der Walls constants for a number of small molecules at
http://en.wikipedia.org/wiki/Van_der_Waals_constants_%28data_page%29
These constants, a and b assume units of liters, bar = 100 000 Pa (a bit less than 1
atm), K and moles; R is 8.31446 x 10-2 in these units.
Solve the van der Waals and ideal gas equations for p. For both, compute p for n = 1
mol, V = 22.4 L, T = 273 K, using the R value 8.31446 x 10-2. For the van der Waals
equation use a = 23.11 and b = .1424 (cyclohexane). Just use Matlab interactively to
compute these. The results should be close to 1. Then, for both, compute the
pressure if the temperature is raised to 373 K and volume is squeezed to 2.24 L.
After these preliminaries, write a function vdwP that computes the pressure of a van
der Waals gas given a,b, n,V,T. Vectorize this function but vectorize it in a and b,
not n,V,T. We are going to build a table showing the effect of a and b on pressure.
Finally, use the matrix method and the loop method to build a table of p for a
varying from 0 to35 in steps of 5 and b varying from .01 to .16 in steps of .03. Round
to .1 Use n = 1, V = 2.24 and T = 373.
Bundle all of the work into a script, with comments.
Download