h1

Notebook 1.3: Properties of Real Gases from the Ideal Gas Law

January 15, 2010

Real molecules attract and repel each other. Ideal gas molecules don’t. That’s what causes nearly all deviations from ideality.

The ideal gas law is derived by ignoring attractions and repulsions between molecules. It doesn’t work at all for solids and liquids, which have very strong intermolecular forces. It generally isn’t accurate for real gases, either.

We can still apply the ideal gas law in the limit of low pressure for real gases. At low pressure, the gap between molecules widens, weakening the forces acting between molecules until they are essentially negligible, so the equation applies.

The Euler notebook posted below asks students to connect data for real gases collected at several different pressures with the ideal gas law by extrapolating to zero pressure. It introduces linear regression with Euler.

To use the notebook:

* Download and install the Euler Math Toolbox.
* Cut and paste the code below into a plain text file.
* Save the file with an .en file extension.
* Double-click the file. It should open up in the Toolbox.

I used this in my Fall ‘09 PChem class (it’s the fourth notebook in the series). Italics mark the items students had to fill in themselves. They seemed to have little trouble with this one.

All of the notebooks in this series are specifically keyed to Atkins’ Physical Chemistry, 8th edition.

—————————-snip here———————————————
% Notebook 1.3: Extrapolation to zero pressure
%
% In this notebook, we’ll calculate properties of real gases from the
% ideal gas law by extrapolating to zero pressure.
%
% Consider the following experimental data collected for gaseous
% dimethyl ether at 25 degrees Celsius. The pressures P are in pascals,
% and the densities d are in kg m^-3. R is in Pa m^3/mol K and T is
% K.
%
>P = [12.223,25.20,36.97,60.37,85.23,101.3]*1000;
>d = [0.225,0.456,0.664,1.062,1.468,1.734];
>R = 8.314;
>T = 25 + 273.15;
%
% Let’s find the molar mass of dimethyl ether from this data.
%
% The molar mass M of an ideal gas is mass per mole. The mass of the gas
% is its density times its volume, so
%
% M = dV/n
%
% For an ideal gas, PV=nRT or V/n = RT/P, so
%
% M = dRT/P
%
% The ideal gas law holds when P approaches zero, so for a real gas,
%
% M = lim dRT/P
% P->0
%
% This is called a limiting law. How can we apply the limiting law with the
% pressure and density measurements in P and d?
%
% First, calculate an array of dRT/P values.
%
>dRToverP = d*R*T/P;
%
% Let’s plot these values against P to see if we can linearly extrapolate
% them to zero.
% * When plotting experimental data, it is good practice to show
% the points on the graph (use the points=1 option).
%
>plot2d(P,dRToverP,points=1,style=”[]”);
>title(“Determining the Molar Mass of Dimethyl Ether”);
>xlabel(“Pressure, in Pa”);
>ylabel(“dRT/P, in kg/mol”);
>insimg;

%
% The data looks reasonably linear. It’s worth trying to fit a
% line to it. We can use Euler’s polyfit() function to do this. The
% call looks like
% a = polyfit(x,y,n)
% where:
%
% a is an array of coefficients in the fitted polynomial
% a[1] + a[2]*x + a[3]*x^2 + … + a[n+1]*x^n
% x and y are the arrays of x and y data
% n is the degree of the polynomial to fit (1 for a line)
%
>fit = polyfit(P,dRToverP,1)
0.04587503092209 -3.583072735655e-008
%
% The first number is the intercept; the second is the slope.
%
% To calculate an array of points along the regression line, use the
% polyval() function. The call looks like
% y = polyval(a,x)
% where x, y, and a have been defined above.
%
>x = [0,max(P)];
>y = polyval(fit,x);
%
% Now insert the plot, with the raw data points marked as boxes,
% and the regression line displayed as a solid line.
%
>plot2d(x,y);
>plot2d(P,dRToverP,points=1,style=”[]”,add=1);
>title(“Determining the Molar Mass of Dimethyl Ether”);
>xlabel(“Pressure, in Pa”);
>ylabel(“dRT/P, in kg/mol”);
%
% The y-intercept is M, the value of dRT/P at P=0.
%
>M = fit[1]
0.04587503092209
%
% We can label the y-intercept using the label function. The call
% looks like label(text,x,y,offset). You can play around with the
% offset parameter until the label is where you want it.
%
>label(“M”,0,M,0);
>insimg;

% —————————————————————–
%
% Apply these techniques to solve problem 1.3 in the text, which
% finds absolute zero on the Celsius temperature
% scale from experimental data.
%
% Enter the P and alpha data in the space below.
% (HINT: look carefully at the units.)
%
>P = [749.7, 599.6, 333.1, 98.6];
>alpha = [3.6717, 3.6697, 3.6665,3.6643]*1e-3;

%
% It will be easiest to find alpha for an ideal gas first.
% Do this with the polyfit() function in the space below.
% Call the alpha value for an ideal gas ‘alphaideal’.
>fit = polyfit(P,alpha,1)
0.003662977448051 1.139259281072e-008
>alphaideal = fit[1];

%
% In the space below, insert a plot that extrapolates alpha to zero
% pressure. Mark the data on the line as circles (use style=”o”) and
% add a regression line to the plot. The y-intercept should be shown
% and labeled as “alpha ideal”.
%
>x = [0,max(P)];
>y = polyval(fit,x);
>plot2d(x,y);
>plot2d(P,alpha,points=1,style=”o”,add=1);
>title(“Determining alpha for an ideal gas”);
>xlabel(“Pressure, in torr”);
>ylabel(“alpha, in deg. C^-1″);
>label(” alpha ideal”,20,fit[1],-25);
>insimg;


%
% Now solve Charles’ Law in the form V=Vo(1+alpha*theta) for
% absolute zero. Call the solution ‘absolutezero’.
% HINT: You won’t need an actual value for Vo, if you do your
% algebra correctly.
% HINT: At V=0, theta is absolute zero on the Celsius scale.
% HINT: Charles’ Law applies exactly only to ideal gases.
%
>absolutezero = -1/alphaideal
-273.0019537882

%
% ———————————————————————–
%
% Apply these techniques again to solve problem 1.7(b) in the text,
% which estimates the value of the ideal gas law constant R from
% experimental data.
%
% Enter the P, V, and density(d) data in the space below.
%
>P = [0.750000, 0.500000, 0.250000];
>V = [29.9649, 44.8090, 89.6384];
>d = [1.07144, 0.714110, 0.356975];

%
% Calculate an array of R values calculated at each of the three points.
% Call it RP (for “R at pressure P”).
%
>M = 2*15.9994;
>T = 273.15;
>RP = P*M/(d*T);

%
% In the space below, insert a plot of the RP values as a function
% of pressure. Show the data points as boxes (use style=”[]”). Draw
% the regression line on the plot. AS ALWAYS title the plot and
% label the axes. The axis labels should include the units.
%
>fit = polyfit(P,RP,1)
0.08206187029697 -7.886858741291e-005
>x = [0,max(P)];
>y = polyval(fit,x);
>plot2d(x,y);
>plot2d(P,RP,points=1,style=”[]”,add=1);
>title(“Determination of R”);
>xlabel(“Pressure, in atm”);
>ylabel(“P*M/(density*T), in dm^3 atm/mol K”);
>label(“R”,0,fit[1],0);
>insimg;


%
% In the space below, print your calculated R value.
>R = fit[1]
0.08206187029697

h1

Notebook 1.2 – Solving Equations of State (Molar Volumes of Model Gases)

January 14, 2010

The Euler notebook posted below asks students to solve various gaseous equations of state for molar volume. This is a common task that’s quite easily done with a computer algebra system, but difficult and tedious to do with pencil and paper.

To use the notebook:

  • Download and install the Euler Math Toolbox.
  • Cut and paste the code below into a plain text file.
  • Save the file with an .en file extension.
  • Double-click the file. It should open up in the Toolbox.

I used this in my Fall ‘09 PChem class (the third in the series). Italics mark the items students had to fill in themselves. They had less trouble with this one, although command line syntax was still a source of confusion and frustration. They wanted to type something like root(R*T/V-P,V) or root(RT/V-P,V) instead of root(“R*T/V-P”,V).

All of the notebooks in this series are specifically keyed to Atkins’ Physical Chemistry, 8th edition.


----------------------------snip here---------------------------------------------
Notebook 1.2 - Molar Volume of Model Gases (Solving Equations of State)

%
% In this task, we'll use Euler to numerically solve equations of state.
% Study Example 1.4 on page 18 of Atkins, which estimates the molar
% volume of CO2 at 500 K and 100 atm by treating CO2 as a van der Waals
% gas.
%
% To solve this problem in Euler, set up constants in any convenient
% units (in this case, dm^3 for volume, atm for pressure, and K for
% temperature:
>R = 0.082059;
>a = 3.592;
>b = 4.267e-2;
>T = 500;
>P = 100;
%
% Now cast the equation into a form that looks like f(x) = 0.
% Atkins rearranges the van der Waals equation into polynomial
% in V:
% V^3-(b+R*T/P)*V^2 + (a/P)*V - a*b/P = 0.
% but that really isn't necessary. *Any* rearrangement of the equation
% we want to solve that puts zero on one side of the equation will work.
%
% To solve the equation in Euler, we'll need an initial guess for V.
% The ideal gas volume will do.
>V = R*T/P
0.410295
%
% Now use Euler's 'root' function, which looks like
% root("expression",x)
% where expression (enclosed in double quotes) is the nonzero side of the
% equation we want to solve, and x is the variable in that expression we
% want to solve for.
%
>root("V^3-(b+R*T/P)*V^2 + (a/P)*V - a*b/P",V)
0.3663332616871
%
% Note that root has reset the value of V:
%
>V
0.3663332616871
%
% Atkins started with the equation
% P = R*T/(V-b) - a/V^2
% We could have subtracted P from both sides of this equation to more
% simply cast it into the f(x) = 0 form:
%
>root("R*T/(V-b)-a/V^2-P",V)
0.3663332616871
%
% Atkins claims that a perfect gas under these conditions has a molar
% volume of 0.410 dm^3/mol. We can verify this by typing
%
>root("R*T/V - P", V)
0.4102949999999
% ---------------------------------------------------------------------
% TASK 3. Use this second approach to calculate the molar volume of
% argon in dm^3 per mole at 100 degrees Celsius and 100 atm, on the
% assumption that it's
% A) an ideal gas;
% B) a hard sphere gas (assuming that each molecule is a
% sphere with radius of 0.15 nm);
% C) a van der Waals gas;
% D) a Dieterici gas;
% E) a virial gas (ignoring all virial coefficients beyond B).
%
>T = 100+273.15;
>P = 100;
%
% 3A) The molar volume as an ideal gas:
%
>V = R*T/P
0.3062031585

%
% 3B) The molar volume as a hard sphere gas, with radius 0.15 nm:
% HINT: In Euler, the constant pi is written as %pi
% HINT: What units should you put b into
% if V is in dm^3/mol?
%
>r = 0.15*1e-9/1e-1;
>NA = 6.022e23;
>b = 4*(4/3)*%pi*r^3*NA;
>root("R*T/(V-b)-P",V)
0.3402567662277

%
% 3C) The molar volume as a van der Waals gas:
%
>a = 1.337;
>b = 3.20e-2;
>root("(P+a/V^2)*(V-b)-R*T",V)
0.2981759820445

%
% 3D) The molar volume as a Dieterici gas:
% HINT: See Table 1.7 in Atkins.
% HINT: a and b for the Dieterici gas are NOT the same as
% a and b for a van der Waals gas!
% HINT: All of the expressions in the Critical Constants columns
% in Table 1.7 are equal.
% HINT: In Euler, the constant e is written as %e
% HINT: In Euler, e^x can be written as exp(x)
%
>B = 3*b/2;
>A = 4*%e^2*B^2*a/(27*b^2);
>root("R*T*exp(-A/(R*T*V))/(V-B)-P",V)
0.245635997406

%
% 3E) The molar volume as a virial gas (with all virial coefficients
% beyond B ignored)
% HINT: Watch your units; what should the units of B be, if V
% should be in dm^3/mol?
% HINT: B varies with temperature.
%
>B = -4.2/1000;
>root("(R*T/V)*(1+B*P)-P",V)
0.17759783193

----------------------------snip here---------------------------------------------

h1

Filling in HTML attributes with XSL

January 14, 2010

Problem: I want to transform some XML that looks like

<flash href="drill-1-scientific-notation" width="550" height="400"/>

into browser-independent HTML, using XSL. The output code has to copy the XML attributes into HTML attributes. I can’t use xsl:value-of tags to do that, because I can’t put tags inside of tags.

Solution: use {@attribute} wherever the value of an attribute has to be inserted. The XSL template for my flash tag looks like

<xsl:template match="flash">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="{@width}" height="{@height}" id="{@href}" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="{@href}.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="{@href}.swf" quality="high" bgcolor="#ffffff" width="{@width}" height="{@height}" name="{@href}" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</xsl:template>

h1

Notebook 1.1: Atmospheric Modeling

January 14, 2010

Famous right-wing radio personality Rush Limbaugh claims that chlorofluorocarbons can’t possibly deplete ozone in the stratosphere, because they’re heavier than air. They’ll settle close to the ground, says Rush, where they can’t do any harm.

The Euler notebook posted below asks students to apply the barometric equation to see whether or not gases really stratify in the atmosphere based on their molar masses. To use it, download the Euler Math Toolbox. After installing the toolbox, just cut and paste the following code into a plain text file, save it with an .en file extension, and double-click the file. It should open up in the Toolbox.

I used this in my Fall ‘09 PChem class (the second in the series). Italics mark the items students had to fill in themselves. Some of my students struggled with this assignment because they couldn’t fathom doing calculations with arrays. I really should have had a notebook before this one that focused exclusively on arithmetic with arrays.

All of the notebooks in this series are specifically keyed to Atkins’ Physical Chemistry, 8th edition.


---------------------------------snip here-----------------------------
Notebook 1.1 - Atmosphere Modeling
%
% As before, hit return on each line to execute the calculation on that
% line. Use ALT-Insert to insert a new line, and ALT-Delete to remove a
% line.
%
% -----------------------------------------------------------------------
%
% In this notebook, we'll compare two models for describing the
% change in air pressure with altitude. Both models are based on the
% barometric formula
% P = Po*exp(-h*M*g/(R*T))
% where P is the pressure, Po is the pressure at altitude 0, h is the
% altitude, M is the molar mass, g is the acceleration due to gravity,
% R is the ideal gas constant, and T is the temperature in kelvins.
% * MODEL A assumes that air behaves like an ideal gas with a
% single molar mass, Mo.
% * MODEL B assumes that each gas in air behaves as an ideal
% gas, and each gas develops its own separate altitude
% profile. In this model, we should see that air is richer in
% heavy gases at lower altitudes.
%
% TASK 2A. Let's begin with model A by using the barometric formula to plot
% air pressure (in atm, on the x-axis) against altitude (on the y-axis).
%
% First, we need to know how temperature varies with altitude.
% We can put the temperature vs. altitude data into lists called
% 'arrays'. Arrays can be entered into Euler notebooks by using
% square brackets. For example, here are the data arrays for altitude
% (h, in meters) and temperature (t, in degrees Celsius).

>h=[-1000,0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,15000,20000,25000,30000,40000,50000,60000,70000,80000];
>t=[21.50,15.00,8.50,2.00,-4.49,-10.98,-17.47,-23.96,-30.45,-36.94,-43.42,-49.90,-56.50,-56.50,-51.60,-46.64,-22.80,-2.5,-26.13,-53.57,-74.51];

% Each altitude in h corresponds to a temperature in t.
%
% We can plot arrays and show the data as separate
% points using plot2d's 'points=1' option. We can choose the style of the
% points using the 'style' option. Style can be set to "o", ".", "x",
% or "[]" with points=1.
%
>plot2d(t,h);
>plot2d(t,h,points=1,add=1,style="o");
%
% Always title your plots, and label the axes. Include units in the
% axis labels.
%
>title("Variation of Temperature with Altitude");
>xlabel("temperature (degrees Celsius)");
>ylabel("altitude (m)");
>insimg;

%
% Next, we need the average molar mass of air at sea level, Mo (in
% kg/mol). The molecule fractions in air are 78.09% N2, 20.95%
% O2, 0.93% Ar, and 0.03% CO2 at sea level, with negligible
% amounts of other gases in dry air. We can use arrays again, with
% each separate gas as an 'element' in the array (N2 is element 1,
% O2 is element 2, Ar is element 3, and CO2 is element 4):
%
>percent = [78.09, 20.95, 0.93, 0.03];
>abundance = percent/100;
>mass = [2*14.0067, 2*15.9994, 39.948, 12.0107+2*15.9994];
%
% If we're going to do our calculations in SI units, we need the
% masses in kg/mol, not g/mol. Note that we can do the conversion
% on all elements of the array at once.
%
>mass = mass/1000;
%
% We can access the i-th element of array x by writing x[i].
% For example, the mass of N2 is mass[1]. The abundance of Ar is
% abundance[3].
%
>Mo = abundance[1]*mass[1] + abundance[2]*mass[2] + abundance[3]*mass[3] + abundance[4]*mass[4]
0.02896413191
%
% It's much easier to use the sum function, which adds up all of the
% elements of an array.
%
>Mo = sum(abundance * mass)
0.02896413191
%
% We also need the acceleration due to gravity (g, in m/s^2). We can't
% get accurate results by just plugging g=9.8 into the barometric
% equation because g decreases with altitude. Each number in the
% following array gives g at the corresponding altitude in the h array.
%
>g=[9.810,9.807,9.804,9.801,9.797,9.794,9.791,9.788,9.785,9.782,9.779,9.776,9.761,9.745,9.730,9.715,9.684,9.654,9.624,9.594,9.564];
%
% Also assume that the pressure Po at sea level is 1 atm.
%
>Po=1;
%
% Now calculate an array P that contains the pressures predicted
% by the barometric formula at each altitude h.
%
>R=8.314;
%
% Remember that names in Euler are case sensitive. We can use T
% for the kelvin temperature, and t for the Celsius temperature.
%
>T = t+273.15;
%
% Now use the barometric equation to calculate the total pressure,
% assuming that the average molar mass of air is the same at every
% altitude.
%
>P=Po*exp(-h*Mo*g/(R*T));
>plot2d(P,h);
>plot2d(P,h,points=1,add=1,style="o");
>title("MODEL A: Barometric Pressure Profile with Fixed Air Molar Mass");
>xlabel("Barometric Pressure (atm)");
>ylabel("altitude (m)");
>insimg;


%
% ----------------------------------------------------------------------
%
% TASK 2B. In MODEL A, we assumed that the average molar mass of air
% is the same at every altitude. However, each separate gas might
% have its own altitude profile, with heavier gases being more
% abundant at lower altitudes than light gases.
%
% On a second plot, use the barometric equation to show
% the partial pressures for each of the four gases as a function of
% altitude. Put the four curves on the same plot, in different colors.
%
% Call the arrays holding the partial pressures of each gas
% PN2, PO2, PAr, and PCO2.
%
>PN2 = (Po*abundance[1])*exp(-h*mass[1]*g/(R*T));
>plot2d(PN2,h,color=1);
>PO2 = (Po*abundance[2])*exp(-h*mass[2]*g/(R*T));
>plot2d(PO2,h,add=1,color=2);
>PAr = (Po*abundance[3])*exp(-h*mass[3]*g/(R*T));
>plot2d(PAr,h,add=1,color=3);
>PCO2 = (Po*abundance[4])*exp(-h*mass[4]*g/(R*T));
>plot2d(PCO2,h,add=1,color=4);

%
% Then use Dalton's Law to get a fifth curve,
% the total pressure profile. Call it Ptot.
%
>Ptot = PN2 + PO2 + PAr + PCO2;
%
% Plot the curve for the total pressure with a heavier line using
% 'thickness'. For example, to plot y as a function of x with a
% heavier curve, you could type plot2d(x,y,thickness=2).
%
>plot2d(Ptot,h,add=1,thickness=2,color=5);
>title("MODEL B: Barometric Pressure Profile with Variable Molar Mass");
>xlabel("Pressure (atm)");
>ylabel("Altitude (m)");
>insimg;


%
% ----------------------------------------------------------------------
%
% TASK 2C. Calculate the variation in average molar mass with altitude
% for MODEL B. You can do this by solving the barometric equation
% for average molar mass M, using pressure Ptot (from Task 2B).
% HINT: You may run into some practical difficulties in your calculation
% of M at h = 0, because
% * division by zero is not allowed
% * ln (Ptot/Po) = 0 when h=0, so you may get molar mass = 0 at
% altitude zero.
% The average molar mass at h=0 should be Mo. You can set the second
% element of M to Mo by typing M[2] = Mo.
%
>h[2]=1; M = -R*T/(h*g)*ln(Ptot/Po);
>M[2]=Mo;
>M
Column 1 to 3:
0.02897184063066 0.02896413191 0.02895617819929
Column 4 to 6:
0.02894796718375 0.02893948906187 0.02893072545567
Column 7 to 9:
0.02892166297037 0.02891228549505 0.02890257572915
Column 10 to 12:
0.02889251507121 0.0288820868212 0.02887126708741
Column 13 to 15:
0.02882661789134 0.02878778498486 0.02875566381133
Column 16 to 18:
0.02872691182118 0.02868986042015 0.02865867484957
Column 19 to 21:
0.02859332001119 0.02852196225203 0.02845761067037

% Insert a plot the average molar mass M for model B as a function of
% altitude.
%
>plot2d(M,h);
>title("MODEL B: Variation of Molar Mass with Altitude");
>xlabel("Average Molar Mass (kg/mol)");
>ylabel("Altitude (m)");
>insimg;


%
% ----------------------------------------------------------------------
%
% TASK 2D. Assess the accuracy of the two methods for calculating
% the absolute error in total pressure for the two methods against
% altitude, using measured pressures in the array Ptrue for the
% altitudes in h. Ptrue is in atmospheres.
%
>Ptrue = [1.1229908, 1.000000, 0.885790, 0.780201, 0.683079, 0.594156, 0.513204, 0.439950, 0.374090, 0.315296, 0.263226, 0.217485, 0.0949375, 0.0435330, 0.0218130, 0.0113010, 0.00455875, 0.00200189, 0.000290389, 2.35653e-5, 1.48565e-6];
>plot2d(Ptrue - Ptot, h, color=2, thickness=1);
>plot2d(Ptrue - P, h, add=1, color=3, thickness=5);
>title("Absolute Error in Model B (thinner curve) and Model A (thicker curve)");
>xlabel("Pressure (atm)");
>ylabel("Altitude (m)");
>insimg;


%
% Which of the two models is more accurate? Explain.
%
>"Model A is more accurate. This suggests that the gases in air don't develop separate altitude profiles.";
>"A reasonable hypothesis is that winds remix the gases that gravity would separate.";
>

h1

Notebook 1.0: Basic calculations and plotting with Euler

January 14, 2010

Here is the first draft of the symbolic math notebooks I used in my Fall ’09 PChem class. You’ll need the free, open source Euler Math Toolbox to execute it. After you install the toolbox, just cut and paste the following code into a plain text file, save it with an .en file extension, and double-click the file. It should open up in the Toolbox.

All of the notebooks in this series are specifically keyed to Atkins’ Physical Chemistry, 8th edition.

As you can see, Euler makes decent graphs, and saves them as png files that are easily pasted into other documents and web pages. The syntax is clumsy. I’ve used Unix since I was a kid, so I’ve always been most comfortable with command line interfaces, but it’s tough sledding for some students. I wish Euler had a graph-making wizard.

---------------------------------snip here-----------------------------
Notebook 1.0: Basic calculations and plotting with EULER
%
% Please read Sections 1.1-1.2 in Atkins before working through
% this notebook.
%
% This notebook will introduce basic features of EULER that will help
% you complete Task 1. You can execute the commands in this notebook
% one by one by pressing the return key, when the cursor is on the
% command line. You can also travel from command to command using the
% cursor keys.
%
% EULER (pronounced 'oiler') works like a calculator. You enter an
% expression or command, press return, and the expression or command
% is evaluated.
%
% For example, the pressure P caused by a column of fluid with density
% d and height h can be calculated from
%
% P = dgh
%
% where g is the acceleration due to gravity. You can calculate the
% pressure in Pascals at a depth of 10 m under seawater with a density of
% 1020 kg/m3 as follows:

>1020*9.8*10
99960

% We can write the expression a little more clearly by using named
% variables:

>d=1020;
>g=9.8;
>h=10;
>P = d*g*h
99960

% If a command is followed by a semicolon (;), EULER does not print
% its output. We can enter more than one command in a line. To get
% the pressure at 20 m in atm, we can write:

>h=20; P=d*g*h
199920

% To generate a table of pressures at 0.1 m intervals from 0 to 20 m,
% we can make an array of heights as follows:

>h=0:0.1:20;

% where we've put a semicolon on the end of the line to suppress
% the output of the array of heights 0, 0.1, 0.2, ..., 20. The :
% command has the form
%
% x = start : increment : last
%
% where start is the first value in the array, increment is the space
% between points in the array, and last is the last value in the array.
%
% We can use the array of h values now to make an array of P values:

> P = d*g*h;

% We can plot the pressure values as a function of h using the plot2d()
% function. The call looks like plot2d(x,y,options) where x and
% y are data arrays. We'll look at the different options for plot2d
% later.
%

> plot2d(h,P);

% The plot is drawn in a separate window. You can press the TAB key to
% toggle between the two windows.
%
% You can give the plot a title:

> title("Dive pressure as a function of depth");

% You can also add x and y axis labels:

> xlabel("depth (m)");
> ylabel("pressure (Pa)");

% So that you don't have to keep tabbing back and forth between the text
% and plot windows, you can insert the plot right into the notebook with
% the 'insimg' (insert image) command:

> insimg;
Dive pressure as a function of depth

% Now let's use Euler to show how pressure, temperature, and molar volume of
% an ideal gas are related. Let's try to look at molar volumes from 0
% to 1 L/mol:
>V = 0:0.01:1;
>R = 0.082059;
>T = 250;
% When we try to calculate P from R, T, and V, we run into a problem (try it):
>P = R*T/V;
Floating point error!
error in :
P = R*T/V;
^
% The trouble is that one of the V values is zero, and division by zero
% is not allowed. We'll have to start with a small (but nonzero) volume:
>V = 0.001:0.01:1;
>plot2d(V,R*T/V);
% We can add curves for different temperatures to the same plot using
% plot2d's add=1 option. We can make each curve a different color using
% the color option:
>T = 500; plot2d(V,R*T/V,add=1,color=10);
>T = 1000; plot2d(V,R*T/V,add=1,color=11);
>T = 2000; plot2d(V,R*T/V,add=1,color=12);
% We can add titles and axis labels, and insert the image into this
% notebook:
>title("Boyle's Law Isotherms");
>xlabel("Volume (L)");
>ylabel("Pressure (atm)");
>insimg;
Boyle's Law Isotherms

% It's tough to see the curves with the full range of pressures shown
% on the y axis. The plot2d function can redraw the plot with any fixed
% range for the x and y values. The parameters a and b set the minimum
% and maximum x axis values; c and d set the minimum and maximum y axis
% values.
>Pmax = 1000;
>Vmax = 1;
>T=250; plot2d(V,R*T/V,a=0,b=Vmax,c=0,d=Pmax);
>T=500; plot2d(V,R*T/V,a=0,b=Vmax,c=0,d=Pmax,add=1,color=11);
>T=1000; plot2d(V,R*T/V,a=0,b=Vmax,c=0,d=Pmax,add=1,color=12);
>T=2000; plot2d(V,R*T/V,a=0,b=Vmax,c=0,d=Pmax,add=1,color=13);
>title("Boyle's Law Isotherms");
>xlabel("Volume (L)");
>ylabel("Pressure (atm)");
>insimg;

Boyle's Law Isotherms

% Compare this graph to Figure 1.4 on page 7 of Atkins.
%
% In the space below, reproduce textbook figures 1.5, 1.6, and 1.7
% as closely as possible. Be sure to title each graph and label
% all axes, and set the axis minima and maxima so that the curves
% can be clearly seen. Display the graphs within the notebook, using
% the insimg function.
%
% Finally, save the notebook (by choosing File->Save Notebook) and
% upload it to the website before the due date.
>
---------------------------------snip here-----------------------------

That’s it.

You can see the key below the cut.

---------------------------------snip here-----------------------------
Notebook 1.0 Key
%
>R = 0.082059;
%
% Figure 1.5
%
>V = 0.01:0.01:5;
>T=250; plot2d(1/V,R*T/V); label("T = 250",80,2000);
>T=500; plot2d(1/V,R*T/V,add=1,color=1); label("T = 500",50,2000);
>T=1000; plot2d(1/V,R*T/V,add=1,color=2); label("T = 1000",25,2000);
>T=2000; plot2d(1/V,R*T/V,add=1,color=3); label("T = 2000",0,2000);
>title("Figure 1.5. Pressure depends linearly on 1/V at constant T");
>xlabel("1/Molar Volume (mol/L)");
>ylabel("Pressure (atm)");
>insimg;

Atkins 8e Figure 1.5

%
% Figure 1.6
%
>T = 0:5:1000;
>P = 1; plot2d(T,R*T/P);
>P = 2; plot2d(T,R*T/P,add=1,color=1);
>P = 4; plot2d(T,R*T/P,add=1,color=2);
>P = 8; plot2d(T,R*T/P,add=1,color=3);
>P = 16; plot2d(T,R*T/P,add=1,color=4);
>title("Figure 1.6. Volume depends linearly on temperature at constant pressure");
>xlabel("Temperature (K)");
>ylabel("Volume (L)");
>insimg;

%
% Figure 1.7
%
>V = 1; plot2d(T,R*T/V);
>V = 2; plot2d(T,R*T/V,add=1,color=1);
>V = 4; plot2d(T,R*T/V,add=1,color=2);
>V = 8; plot2d(T,R*T/V,add=1,color=3);
>V = 16; plot2d(T,R*T/V,add=1,color=4);
>title("Figure 1.7. Pressure depends linearly on temperature at constant volume");
>xlabel("Temperature (K)");
>ylabel("Pressure (atm)");
>insimg;

h1

Open Source Symbolic Math Software for Teaching Physical Chemistry

September 17, 2009

If you teach physical chemistry, you’ve probably browsed the nice collection of symbolic math documents Theresa Zielinsky maintains at http://bluehawk.monmouth.edu/~tzielins/mathcad/. I like the approach and design philosophy but I haven’t used them in my course for a few reasons:

  • Mathcad, Mathematica, and Maple are too pricey for most of my students. (And for me).
  • I don’t want to be locked into using (and developing) materials for a proprietary symbolic math package. I prefer open source software for practical reasons: it keeps costs for students down and makes the materials I develop accessible to everyone. And it’s important to walk the walk, when we talk to students about reproducibility and full disclosure of procedures in science. See this editorial(pdf) from Notices of the American Mathematical Society (linked here).
  • The documents in the collection are written by different authors, so the style and level of presentation isn’t consistent.
  • Most of the documents are essentially isolated case studies and enrichment activities. They don’t refer or relate to each other.

Before I commit to using a set of symbolic math documents in my physical chemistry courses, I’d like to see the following:

  • Comprehensive coverage. Each document should be brief, and fine-grained- roughly one for each lecture, so they can provide complete coverage of the course material.
  • Continuity. I’d like a set of documents that build on each other. They should introduce numerical techniques and new features of the software as needed, referring to previous documents for review. They should be keyed to the textbook.
  • Powerful but easy-to-use open source software. I want an easy way to do interval arithmetic so that I can have students do some error and sensitivity analysis, without a lot of effort. I need basic statistical, linear algebra, and symbolic math capability. It should be easy to make good-looking 2D, 3D, and contour plots. I don’t want to spend much time teaching syntax. Students should be able to concentrate on concepts and problem-solving rather than debugging.

    There are quite a few free, open source symbolic math packages out there. I spent some time learning Octave, SciLab, and straight Maxima, but about a year ago I finally settled on René Grothmann’s
    excellent Euler Math Toolbox. Euler is very similar to Matlab in flavor; it uses Maxima and Yacas as backends for doing the symbolic math. You can read about its many features here. It meets my requirements, though I think the learning curve is a little steeper for students than I’d like. I’ll post a complete review of it sometime.

I’ve written a set of Euler notebooks keyed to Peter Atkin’s Physical Chemistry. I’ll post my initial drafts here as my students finish them up.

h1

Moodle vs. Blackboard: Equation Input & Graphing

September 10, 2009

Moodle’s equation input and interactive graphing facilities make it a better choice than Blackboard for teaching chemistry or math online. Jacek Polewczak and Carol Shubin at CSU Northridge compare the two:

Scientific input in Moodle and WebCT8/Blackboard9 (April 6, 2009)