<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Mathematica Journal</title>
	<atom:link href="http://www.mathematica-journal.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mathematica-journal.com</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 11:26:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Relativistic Motion of a Charged Particle and Pauli Algebra</title>
		<link>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/</link>
		<comments>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/#comments</comments>
		<pubDate>Wed, 09 May 2012 17:55:49 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=25514</guid>
		<description><![CDATA[We introduce some key formulas of special relativity and apply them to the motion of a spinless, charged point particle of unit mass, subject to the Lorentz force due to an external electromagnetic field. 
Pauli Algebra
An element of Pauli algebra consists of a complex scalar, say , and a three-dimensional complex vector , denoted , [...]]]></description>
			<content:encoded><![CDATA[<p>We introduce some key formulas of special relativity and apply them to the motion of a spinless, charged point particle of unit mass, subject to the Lorentz force due to an external electromagnetic field. <span id="more-25514"></span></p>
<h3>Pauli Algebra</h3>
<p>An element of Pauli algebra consists of a complex scalar, say <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_1.gif" alt="" width="8" height="12" />, and a three-dimensional complex vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_2.gif" alt="" width="6" height="12" />, denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_3.gif" alt="" width="52" height="12" />, which thus has eight real dimensions. In effect, this is a generalization of quaternion algebra, but with complex instead of real components. In this article, we call these elements &#8220;spinors.&#8221;</p>
<p>A product of two spinors is a spinor defined by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_1.gif" alt="" width="236" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/CenterDot.gif" alt="" width="3" height="19" /> and <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Cross.gif" alt="" width="6" height="19" /> are the dot and cross products, respectively. Note that this multiplication is associative, implying that we do not need parentheses when multiplying three or more spinors. But multiplication is not commutative (the result depends on the order of factors).</p>
<p>There are two important unary (single-argument) operations on spinors: the first is called a reflection (denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_4.gif" alt="" width="16" height="12" />), which changes the sign of the vector part, that is, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_5.gif" alt="" width="68" height="12" />; the second takes the complex conjugate of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_6.gif" alt="" width="8" height="12" /> and of each component of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_7.gif" alt="" width="6" height="12" />; it is denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_8.gif" alt="" width="14" height="12" />. Finally, just for convenience, we let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_9.gif" alt="" width="16" height="14" /> denote the combination of both of these, that is, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_10.gif" alt="" width="75" height="12" /> Note that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_2.gif" alt="" width="124" height="45" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>which are quite easy to verify.</p>
<p>The corresponding <em>Mathematica</em> routines look and work like this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_1.gif" alt="" width="415" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_1.gif" alt="" width="256" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_2.gif" alt="" width="213" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_2.gif" alt="" width="215" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_3.gif" alt="" width="364" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_3.gif" alt="" width="207" height="12" /></p>
<p>From now on we consider a three-dimensional vector to be a special case of a spinor, meaning that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_11.gif" alt="" width="6" height="12" /> is shorthand for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_12.gif" alt="" width="27" height="12" />. We can easily compute various functions of spinors (and of three-dimensional vectors, as a special case). Thus, for example, assuming that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_13.gif" alt="" width="6" height="12" /> is a three-dimensional vector with real components, we find</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_3.gif" alt="" width="580" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_14.gif" alt="" width="6" height="12" /> is the length of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_15.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_16.gif" alt="" width="29" height="24" /> is a unit vector in the same direction.</p>
<p>Similarly, for a three-dimensional vector with pure imaginary components (which we express in the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_17.gif" alt="" width="12" height="12" /> to keep the elements of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_18.gif" alt="" width="7" height="12" /> real), the same kind of expansion yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_4.gif" alt="" width="580" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>again where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_19.gif" alt="" width="7" height="12" /> is the length of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_20.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_21.gif" alt="" width="32" height="21" /> is a unit vector in the same direction.</p>
<p>This can be easily extended to a complex-vector argument, as follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_4.gif" alt="" width="423" height="35" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_4.gif" alt="" width="400" height="40" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_5.gif" alt="" width="125" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_5.gif" alt="" width="419" height="40" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_6.gif" alt="" width="214" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_6.gif" alt="" width="580" height="12" /></p>
<h3>Special Relativity</h3>
<p>The basic idea of Einstein&#8217;s theory is to unite space and time into a single entity of spacetime, whose &#8220;points&#8221; (or events) can then be represented by <em>real</em> spinors of type <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_22.gif" alt="" width="48" height="12" />. The separation between any two such events constitutes a so-called 4-vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_23.gif" alt="" width="81" height="12" /> that, when multiplied (in the spinor sense) by its own reflection, yields a pure scalar <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_24.gif" alt="" width="149" height="15" />. It is now postulated that this quantity must be invariant (having the same value) in all inertial coordinate systems (i.e. those that differ from each other by a fixed rotation and/or a boost&#8212;a motion at constant velocity). For simplicity, our choice of units sets the speed of light (which must be the same in all inertial systems) equal to 1.</p>
<p>The question is: how do we transform 4-vectors from one inertial frame to another, while maintaining this invariance? The answer is provided by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_5.gif" alt="" width="85" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_25.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_26.gif" alt="" width="12" height="12" /> represent a 4-vector in the old and new frame of reference, respectively, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_27.gif" alt="" width="7" height="12" /> is a spinor such that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_28.gif" alt="" width="104" height="12" />. It is obvious that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_29.gif" alt="" width="12" height="12" /> remains real whenever <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_35.gif" alt="" width="9" height="12" /> is real, and that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_6.gif" alt="" width="488" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_30.gif" alt="" width="59" height="12" /> (the scalar invariant of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_31.gif" alt="" width="9" height="12" />). This shows that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_32.gif" alt="" width="6" height="12" /> has the same value in all inertial frames of reference. Requiring reflection to be a frame-independent operation (meaning that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_33.gif" alt="" width="68" height="12" /> for every 4-vector) leads to</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_7.gif" alt="" width="204" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>From this, we can see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_34.gif" alt="" width="16" height="12" /> transforms differently from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_35.gif" alt="" width="9" height="12" />, being an example of a four-dimensional <em>covector</em> (a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_36.gif" alt="" width="13" height="12" />-vector, in our notation). Another important example of a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_37.gif" alt="" width="13" height="12" />-vector is the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_38.gif" alt="" width="34" height="12" /> operator, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_39.gif" alt="" width="8" height="12" /> stands for the usual three-dimensional (spatial) gradient (the collection of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_40.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_41.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_42.gif" alt="" width="5" height="12" /> partial derivatives).</p>
<p>One can show that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_43.gif" alt="" width="55" height="12" /> if and only if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_44.gif" alt="" width="55" height="24" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_2.gif" alt="" width="6" height="12" /> is a &#8220;pure&#8221; vector (i.e. three dimensional, but potentially complex valued). This is a fully general but rather inconvenient form of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_45.gif" alt="" width="7" height="12" />; fortunately, one can prove that any such <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_46.gif" alt="" width="7" height="12" /> can be expressed as a product of an ordinary three-dimensional rotation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_47.gif" alt="" width="40" height="24" /> and a boost <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_48.gif" alt="" width="34" height="24" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_49.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_50.gif" alt="" width="6" height="12" /> are real-valued vectors. To see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_51.gif" alt="" width="40" height="24" /> results in an ordinary rotation of the vector part of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_52.gif" alt="" width="9" height="12" /> (where the magnitude of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_53.gif" alt="" width="8" height="12" /> specifies the angle and the direction of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_54.gif" alt="" width="8" height="12" /> defines the axis of rotation), consider</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_8.gif" alt="" width="460" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_Math_56.gif" alt="" width="60" height="15" /> is the decomposition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_56.gif" alt="" width="7" height="12" /> into components parallel and perpendicular to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_57.gif" alt="" width="8" height="12" />, respectively. Note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_Math_59.gif" alt="" width="37" height="19" /> commutes with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_60.gif" alt="" width="8" height="12" /> (and any function thereof); consequently, it remains unchanged by this transformation. On the other hand, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_59.gif" alt="" width="14" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_60.gif" alt="" width="8" height="12" /> anticommute (i.e. <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_61.gif" alt="" width="94" height="12" />), implying</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_9.gif" alt="" width="172" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>and, consequently, the rest of (<a href="#Eq:8">8</a>). One can thus see that this transformation leaves the scalar part of a 4-vector intact, and rotates the vector part using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_62.gif" alt="" width="8" height="14" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_63.gif" alt="" width="7" height="12" /> as the axis and angle of rotation (of the old frame, with respect to the new one), respectively.</p>
<p>Similarly, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_64.gif" alt="" width="55" height="24" />, we get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_10.gif" alt="" width="533" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:10">(10)</a></td>
</tr>
</tbody>
</table>
<p>Here, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_65.gif" alt="" width="6" height="12" /> can be replaced by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_66.gif" alt="" width="50" height="15" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_67.gif" alt="" width="6" height="15" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_68.gif" alt="" width="45" height="12" /> represent the unit direction and the magnitude of a three-dimensional vector (a velocity of the old frame with respect to the new one), respectively. This leads to the following simplified (and physically more meaningful) result of such a boost, applied to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_69.gif" alt="" width="9" height="12" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_11.gif" alt="" width="146" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:11">(11)</a></td>
</tr>
</tbody>
</table>
<h4>Electromagnetic Fields</h4>
<p>A 4-vector field of central significance is the electromagnetic potential <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_70.gif" alt="" width="31" height="12" />, where <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/CurlyPhi.gif" alt="" width="7" height="19" /> and each component of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_71.gif" alt="" width="9" height="12" /> are real-valued functions of a spacetime location (i.e. of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_72.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_73.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_74.gif" alt="" width="5" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_75.gif" alt="" width="4" height="12" />). Now comes an important point: within the current framework, it is physically meaningless to multiply two 4-vectors (we would not know how to transform such a product from one inertial frame to another), but it is possible to multiply a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_76.gif" alt="" width="13" height="12" />-vector by a 4-vector, creating what we call a mixed vector. It is thus quite legitimate to do</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_12.gif" alt="" width="261" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:12">(12)</a></td>
</tr>
</tbody>
</table>
<p>creating a mixed vector, which has its own new way of transforming (shown shortly).</p>
<p>To physically interpret the right-hand side of (<a href="#Eq:12">12</a>), we first impose the so-called Lorenz condition (often misattributed to the more famous Lorentz) of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_77.gif" alt="" width="75" height="12" /> (we prove shortly that this condition is frame invariant), and identify <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_78.gif" alt="" width="91" height="12" /> with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_79.gif" alt="" width="42" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_80.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_81.gif" alt="" width="8" height="12" /> are the resulting (real-valued) electric and magnetic fields, respectively.</p>
<p>One can now show rather easily that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_82.gif" alt="" width="61" height="24" /> will simply rotate the two fields. On the other hand, a boost <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_83.gif" alt="" width="55" height="24" /> results in</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_13.gif" alt="" width="242" height="99" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:13">(13)</a></td>
</tr>
</tbody>
</table>
<p>since transforming a mixed vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_84.gif" alt="" width="9" height="12" /> is done by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_85.gif" alt="" width="84" height="12" />. In both cases (rotation and boost), the scalar part remains equal to zero, thus proving invariance of the Lorenz condition.</p>
<p>Unlike 4-vectors, mixed vectors can be multiplied, yielding a new mixed vector (in terms of its transformation properties). Thus, for example,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_14.gif" alt="" width="263" height="18" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:14">(14)</a></td>
</tr>
</tbody>
</table>
<p>tells us that both <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_86.gif" alt="" width="40" height="15" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_87.gif" alt="" width="23" height="12" /> are invariant scalar fields.</p>
<p>Similarly, multiplying a 4-vector by a mixed vector returns a 4-vector; for example,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_15.gif" alt="" width="363" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:15">(15)</a></td>
</tr>
</tbody>
</table>
<p>This time, the result must equal the charge/current density (yet another basic 4-vector of the theory); this results in a compact, Dirac-algebra formulation of the usual Maxwell equations. As an example, the following program computes the electromagnetic field of a point-like massive particle of a unit charge, moving at a uniform speed <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_88.gif" alt="" width="5" height="12" /> along the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_89.gif" alt="" width="5" height="12" /> axis; it also verifies that the result satisfies Maxwell&#8217;s equations.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_7.gif" alt="" width="464" height="68" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_7.gif" alt="" width="580" height="48" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_8.gif" alt="" width="354" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_8.gif" alt="" width="89" height="12" /></p>
<h3>Dynamics of a Point-Like Charged Particle</h3>
<p>We choose units in which both the rest mass and the charge of the particle equal 1. Its instantaneous location is denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_90.gif" alt="" width="48" height="12" />, where the three components of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_91.gif" alt="" width="5" height="12" /> are functions of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_92.gif" alt="" width="4" height="12" />. To make the subsequent equations frame independent (having the same form in all inertial frames), we now need to introduce the particle&#8217;s so-called proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_93.gif" alt="" width="6" height="12" /> by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_16.gif" alt="" width="102" height="50" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:16">(16)</a></td>
</tr>
</tbody>
</table>
<p>We already know that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_94.gif" alt="" width="38" height="12" /> transforms as a 4-vector; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_95.gif" alt="" width="183" height="18" />, thus <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_96.gif" alt="" width="49" height="15" /> and, consequently, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_97.gif" alt="" width="57" height="24" /> are relativistically invariant (the dot over <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_98.gif" alt="" width="5" height="12" /> implies differentiation with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_99.gif" alt="" width="4" height="12" />). Proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_100.gif" alt="" width="6" height="12" /> is then computed by the corresponding integral, namely</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_17.gif" alt="" width="92" height="31" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:17">(17)</a></td>
</tr>
</tbody>
</table>
<p>which, being a &#8220;sum&#8221; of invariant quantities, is an invariant scalar as well. This implies that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_18.gif" alt="" width="169" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:18">(18)</a></td>
</tr>
</tbody>
</table>
<p>transforms as a 4-vector (we call it the 4-momentum of the moving particle).</p>
<p>The motion of the charged particle in a given electromagnetic field can now be established by solving</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_19.gif" alt="" width="130" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:19">(19)</a></td>
</tr>
</tbody>
</table>
<p>where the right-hand side is the so-called Lorentz force, and &#8220;<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_101.gif" alt="" width="13" height="12" />&#8221; takes the real part of its argument (also a 4-vector). Note that &#8220;<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_102.gif" alt="" width="13" height="12" />&#8221; applied to a 4-vector remains a 4-vector (since the complex conjugate of a 4-vector transforms as a 4-vector, as one can readily verify).</p>
<p>Based on (<a href="#Eq:18">18</a>), the right-hand side of (<a href="#Eq:19">19</a>) equals</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_20.gif" alt="" width="118" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:20">(20)</a></td>
</tr>
</tbody>
</table>
<p>For a particle with a negative unit charge, the sign of this 4-vector would be reversed.</p>
<p>One way of solving the resulting 4-vector equation is to expand the left-hand side of (<a href="#Eq:19">19</a>):</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_21.gif" alt="" width="331" height="47" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:21">(21)</a></td>
</tr>
</tbody>
</table>
<p>which has to equal (20). Canceling the scalar factor of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_103.gif" alt="" width="37" height="29" />, we get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_22.gif" alt="" width="255" height="44" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:22">(22)</a></td>
</tr>
</tbody>
</table>
<p>Finally, the first (scalar part) of these four equations can be obtained by taking the dot product of the remaining three equations (the vector part) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_104.gif" alt="" width="5" height="14" />, and is therefore redundant. All we need to solve in the end is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_23.gif" alt="" width="145" height="44" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:23">(23)</a></td>
</tr>
</tbody>
</table>
<p>or, equivalently (by solving for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_105.gif" alt="" width="5" height="15" />),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_24.gif" alt="" width="163" height="24" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:24">(24)</a></td>
</tr>
</tbody>
</table>
<p>the correctness of which can be easily verified by substituting this <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_106.gif" alt="" width="5" height="15" /> into the left-hand side of (<a href="#Eq:23">23</a>) and obtaining the right-hand side. These equations can, in general, be solved only numerically. The resulting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_107.gif" alt="" width="5" height="12" /> will be a three-component function of a frame-dependent time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_108.gif" alt="" width="4" height="12" /> (proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_109.gif" alt="" width="6" height="12" /> was used only as an intermediate tool to assure agreement between inertial frames of reference; our solution remains correct in any other such frame, after the corresponding transformation). The following program finds the motion of a negatively charged particle (chosen because an attractive force makes the resulting path somehow more interesting, compared to the same-charge repulsion) in the field of the previous section.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_9.gif" alt="" width="580" height="115" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_9.gif" alt="" width="400" height="310" /></p>
<p>The originally stationary unit-mass particle has been &#8220;captured&#8221; by the moving massive particle (which is assumed to be so heavy that its own motion remains unaffected), and will continue orbiting it (while following its uniform motion). It is important to realize that this formulation of the problem has ignored the fact that a moving particle generates (and radiates) an electromagnetic field of its own, which would further modify its motion. More importantly, we also know that, at an atomic level, the world is governed by quantum mechanics, ultimately resulting in a totally different description of an orbiting particle. This is the reason why the last solution is only of mathematical interest. Under a wide range of initial conditions, the light particle would be drawn to collide with the heavy one.</p>
<h4>Motion in a Constant Electromagnetic Field</h4>
<p>Things become easier when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_110.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_111.gif" alt="" width="8" height="12" /> are both constant fields (in space and time). One can then express <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_112.gif" alt="" width="7" height="12" /> as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_113.gif" alt="" width="62" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_114.gif" alt="" width="13" height="12" /> is the initial value of the particle&#8217;s 4-momentum, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_115.gif" alt="" width="8" height="12" /> is a spinor analogous to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_116.gif" alt="" width="7" height="12" /> that (instead of transforming 4-vectors between inertial frames) advances <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_117.gif" alt="" width="7" height="12" /> to its current location. This time we find it more convenient to make both <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_118.gif" alt="" width="7" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_119.gif" alt="" width="8" height="12" /> functions of proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_120.gif" alt="" width="6" height="12" />. Also, one must not forget to meet the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_121.gif" alt="" width="67" height="12" /> condition, which is then automatically maintained by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_122.gif" alt="" width="7" height="12" /> at all future times.</p>
<p>Expanding the right-hand side of (<a href="#Eq:19">19</a>) yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_25.gif" alt="" width="480" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:25">(25)</a></td>
</tr>
</tbody>
</table>
<p>This should equal the left-hand side of (<a href="#Eq:19">19</a>), namely</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_26.gif" alt="" width="163" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:26">(26)</a></td>
</tr>
</tbody>
</table>
<p>which implies that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_27.gif" alt="" width="117" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:27">(27)</a></td>
</tr>
</tbody>
</table>
<p>having the obvious solution</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_28.gif" alt="" width="105" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:29">(28)</a></td>
</tr>
</tbody>
</table>
<p>a function of a mixed vector transforms as a mixed vector. After computing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_123.gif" alt="" width="8" height="12" /> and, consequently, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_124.gif" alt="" width="62" height="12" />, all we need to do is to integrate this last expression in terms of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_125.gif" alt="" width="6" height="12" /> to get a solution for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_126.gif" alt="" width="24" height="12" />. A simple example follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_10.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_10.gif" alt="" width="580" height="88" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_11.gif" alt="" width="239" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_11.gif" alt="" width="450" height="205" /></p>
<p>In this example, we have been able to obtain an explicit analytic solution.</p>
<p>In most textbooks (e.g., [<a href="#Goldstein">1</a>], [<a href="#Jackson">2</a>]), the treatment we have described is done using conventional tensor analysis, with covariant and contravariant vectors. It is always illuminating, however, to obtain the same results using a completely different approach, such as the one favored by Hestenes [<a href="#Hestenes">3</a>]. We have shown that <em>Mathematica</em> is capable of handling computations in any of several formalisms.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Goldstein">[1] </a></td>
<td>H. Goldstein, <em>Classical Mechanics</em>, 2nd ed., Reading, MA: Addison-Wesley Publishing Company, 1980.</td>
</tr>
<tr>
<td class="Reference"><a name="Jackson">[2] </a></td>
<td>J. D. Jackson, <em>Classical Electrodynamics</em>, New York: John Wiley, 1962.</td>
</tr>
<tr>
<td class="Reference"><a name="Hestenes">[3] </a></td>
<td>D. Hestenes, <em>New Foundations for Classical Mechanics</em>, 2nd ed., Dordrecht/Boston: Kluwer Academic Publishers, 1999.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">J. Vrbik, &#8220;Relativistic Motion of a Charged Particle and Pauli Algebra,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-10.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor"><strong>Jan Vrbik</strong><br />
<em>Department of Mathematics, Brock University<br />
500 Glenridge Ave., St. Catharines<br />
Ontario, Canada, L2S 3A1<br />
</em><em><a href="mailto:jvrbik@brocku.ca">jvrbik@brocku.ca</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Population Dynamics to Partial Differential Equations</title>
		<link>http://www.mathematica-journal.com/2012/04/from-population-dynamics-to-partial-differential-equations/</link>
		<comments>http://www.mathematica-journal.com/2012/04/from-population-dynamics-to-partial-differential-equations/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 23:02:26 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=24754</guid>
		<description><![CDATA[Differential equation models for population dynamics are now standard fare in single-variable calculus. Building on these ordinary differential equation (ODE) models provides the opportunity for a meaningful and intuitive introduction to partial differential equations (PDEs). This article illustrates PDE models for location-dependent carrying capacities, migrations, and the dispersion of a population. The PDE models themselves [...]]]></description>
			<content:encoded><![CDATA[<p>Differential equation models for population dynamics are now standard fare in single-variable calculus. Building on these ordinary differential equation (ODE) models provides the opportunity for a meaningful and intuitive introduction to partial differential equations (PDEs). This article illustrates PDE models for location-dependent carrying capacities, migrations, and the dispersion of a population. The PDE models themselves are built from the logistic equation with location-dependent parameters, the traveling wave equation, and the diffusion equation. The approach presented here is suitable for a single lecture, reading assignment, and exercise set in multivariable calculus. Interactive examples accompany the text and the article is designed for use as a CDF document in which some of the input can remain hidden.<span id="more-24754"></span></p>
<h3>Introduction: Ordinary Differential Equations and Population Dynamics</h3>
<p>The ordinary differential equations with which students are most familiar are the equations for exponential and logistic population growth (see [<a href="#Stewart">1</a>], for example). Historically, Thomas Malthus initiated the mathematical treatment of population dynamics [<a href="#Malthus">2</a>]. His investigations into the consequences of exponential growth in human populations coupled with linear growth in agricultural production led him to a pessimistic view of the eventual fate of humankind, involving misery and starvation.</p>
<p>Pierre-Francois Verhulst and others considered how to model factors that might retard exponential growth, among which the roles of disease and famine had been suggested already by Malthus. In his 1838 paper [<a href="#Verhulst">3</a>], Verhulst transformed the discussion into a mathematical model by writing</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_1.gif" alt="" width="77" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>Here <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_1.gif" alt="" width="17" height="12" /> corresponds to exponential growth and the term <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_2.gif" alt="" width="30" height="12" /> corresponds to the effect of obstacles that slow the growth rate and that depend on the population size <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_3.gif" alt="" width="6" height="12" />. A simple form for the obstacle term is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_4.gif" alt="" width="55" height="15" />, and setting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_5.gif" alt="" width="39" height="12" /> yields the factored form</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_2.gif" alt="" width="75" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>the form we use in this article. Verhulst solved this equation; showed how it led, in the long run, to a bounded population size; and used actual population data to calculate the size of the limiting population for Belgium according to the model. He termed the graph of the solution the <em>logistic curve</em>: the word logistic has its origins in the Greek &#8220;logistikē&#8221;&#8212;the art of calculating&#8212;and Verhulst was the first to be able to calculate the effects of obstacles on the growth of human populations.</p>
<p>The logistic equation is especially useful for introducing ideas involving the qualitative behavior of solutions, in particular the notion of a stable equilibrium. We now write the relevant ODE as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_3.gif" alt="" width="197" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>In the logistic model, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_6.gif" alt="" width="18" height="12" /> is the population size at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_7.gif" alt="" width="4" height="12" />. Using the terminology of population dynamics, the parameters in this model are the growth constant, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_8.gif" alt="" width="6" height="12" />, which controls the rate of population growth near <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_9.gif" alt="" width="26" height="12" />; the carrying capacity, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_10.gif" alt="" width="8" height="12" />, which limits the eventual size of the population; and the initial population size <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_11.gif" alt="" width="12" height="12" />. <tt>DSolve</tt> gives an explicit formula for the solution to the corresponding initial value problem.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_1.gif" alt="" width="492" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_1.gif" alt="" width="96" height="38" /></p>
<p>The usual textbook formula for the solution divides both numerator and denominator by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_12.gif" alt="" width="23" height="15" /> to obtain <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_13.gif" alt="" width="110" height="28" />. From this simplified formula it is easy to check that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_14.gif" alt="" width="46" height="12" /> and that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_15.gif" alt="" width="77" height="12" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_16.gif" alt="" width="32" height="12" />.</p>
<p>The built-in <em>Mathematica</em> function <tt>Manipulate</tt> lets you vary the parameters <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_17.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_17-1.gif" alt="" width="8" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_18.gif" alt="" width="12" height="12" /> interactively to see the effect of varying those parameters graphically. Equilibrium solutions for the model (values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_19.gif" alt="" width="6" height="12" /> for which <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_20.gif" alt="" width="30" height="14" />) occur at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_21.gif" alt="" width="26" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_22.gif" alt="" width="28" height="12" />. The carrying capacity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_23.gif" alt="" width="8" height="12" /> is indicated by the dashed horizontal line (slope zero) in the figure, while the solution curve is purple. The initial value <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_24.gif" alt="" width="12" height="12" /> is the height of the curve at its intersection with the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_25.gif" alt="" width="6" height="12" /> axis. How would you describe the effect of varying the growth constant <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_26.gif" alt="" width="6" height="12" />?</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_2.gif" alt="" width="580" height="223" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_2.gif" alt="" width="403" height="387" /></p>
<p>The equilibrium solution <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_27.gif" alt="" width="28" height="12" /> is stable, since whenever <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_28.gif" alt="" width="32" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_29.gif" alt="" width="77" height="12" />. (However, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_30.gif" alt="" width="40" height="12" /> for some time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_31.gif" alt="" width="4" height="12" /> only if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_32.gif" alt="" width="34" height="12" />, and hence <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_33.gif" alt="" width="40" height="12" /> for all times <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_34.gif" alt="" width="4" height="12" />.) Since solution curves starting near <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_35.gif" alt="" width="26" height="12" /> do not satisfy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_36.gif" alt="" width="75" height="12" />, this equilibrium solution is not stable. This information can be captured in a &#8220;phase diagram,&#8221; shown in the next section. The diagram visually condenses the claims just made: solution curves diverge away from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_37.gif" alt="" width="26" height="12" /> and converge toward <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_38.gif" alt="" width="28" height="12" />. Use the sliders above to verify these claims, based on the plots of the various solution curves. Since this article is primarily concerned with the shapes of solution curves for the differential equations models we study, graphs do not include units on the axes.</p>
<h3>A Key Concept: The Time Evolution of a Spatial Profile Curve</h3>
<p>Now consider the case of a population that is spread out along a narrow strip of land or sea, which we will think of as a line. An initial study of the population might result in a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_39.gif" alt="" width="26" height="12" /> giving the size of the population at location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_40.gif" alt="" width="6" height="12" /> along the strip. But population size is a dynamic quantity, so we should really employ a function of two variables, time and location, in our attempt to model its evolution. Thus, the population size at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_41.gif" alt="" width="4" height="12" /> and location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_42.gif" alt="" width="6" height="12" /> is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_43.gif" alt="" width="31" height="12" /> with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_44.gif" alt="" width="73" height="12" /> recording the observed initial population distribution.</p>
<p>We model the time evolution of the population using the partial differential equation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_4.gif" alt="" width="265" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>This is just a modification of the logistic equation in which the carrying capacity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_45.gif" alt="" width="8" height="12" /> now depends on location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_46.gif" alt="" width="22" height="12" />. This allows the new model to account for environmental conditions that vary from place to place. The function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_47.gif" alt="" width="51" height="12" /> is now the unknown function that solves the PDE. In this setting, the role of the initial value, formerly played by the number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_48.gif" alt="" width="12" height="12" />, is being played by the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_49.gif" alt="" width="73" height="12" />. Essentially, what we have is a separate initial value problem at each location.</p>
<p>We will call the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_50.gif" alt="" width="33" height="12" /> the <em>initial profile curve</em>. Think of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_51.gif" alt="" width="31" height="12" /> for a given value of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_52.gif" alt="" width="4" height="12" /> as the profile curve for the population at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_53.gif" alt="" width="4" height="12" />. Its graph shows how the total population is distributed along the line. The left-hand side of our PDE gives the time rate of change of the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_54.gif" alt="" width="31" height="12" />, and we will interpret the right-hand side as the rule governing the time evolution of the initial profile curve <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_55.gif" alt="" width="33" height="12" />. This idea, <em>the time evolution of a profile curve</em>, is crucial to what follows.</p>
<p>Here is an example that illustrates this point of view. The location-dependent carrying capacity is given by the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_56.gif" alt="" width="134" height="24" />, and the growth constant is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_57.gif" alt="" width="41" height="12" />. Plots of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_58.gif" alt="" width="22" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_59.gif" alt="" width="26" height="12" /> are shown below.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_3.gif" alt="" width="580" height="229" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_3.gif" alt="" width="400" height="150" /></p>
<p>We might predict that the initial population will evolve toward the carrying capacity. To see whether this prediction is accurate, we use <tt>Manipulate</tt> to show the evolving profile curve as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_60.gif" alt="" width="4" height="12" /> increases. Use the &#8220;Reset and Play&#8221; button to show the time evolution.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_4.gif" alt="" width="580" height="290" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_4.gif" alt="" width="403" height="333" /></p>
<p>Here is a thought experiment: suppose we were to change the initial population curve, leaving the carrying capacity at each location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_61.gif" alt="" width="6" height="12" /> the same; would you expect the new initial profile curve to evolve to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_62.gif" alt="" width="22" height="12" />? Can you explain why this is so?</p>
<p>Another thought experiment: what would be the effect of a larger value of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_63.gif" alt="" width="6" height="12" /> on the time it takes for the initial population to approach equilibrium?</p>
<p>Once again, we can summarize the investigation with a &#8220;phase diagram.&#8221;</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_5.gif" alt="" width="580" height="251" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_5.gif" alt="" width="360" height="266" /></p>
<p>As before, the diagram indicates the equilibrium solutions, which are the curves along which <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_64.gif" alt="" width="14" height="24" /> is zero at every point. These are graphs of the functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_65.gif" alt="" width="51" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_66.gif" alt="" width="67" height="12" />. The arrows indicate that if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_67.gif" alt="" width="46" height="12" /> at every location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_68.gif" alt="" width="6" height="12" />, then <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_69.gif" alt="" width="104" height="12" />, so that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_70.gif" alt="" width="22" height="12" /> can be termed a stable equilibrium for this PDE.</p>
<p>A final note: another variation of logistic growth is given by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_71.gif" alt="" width="90" height="24" />, where the carrying capacity is constant, but the growth constant <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_72.gif" alt="" width="6" height="12" />, that is, the speed with which the initial population approaches the equilibrium population, depends on location.</p>
<h3>Migrating Populations</h3>
<p>In the previous example, the time evolution of the profile curve was governed by a right-hand side that involved only the values of the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_73.gif" alt="" width="31" height="12" />. The next PDE we consider has the time evolution at location <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_74.gif" alt="" width="6" height="12" /> governed by the slope of the profile curve at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_75.gif" alt="" width="6" height="12" />. The simplest equation of this type has the time rate of change of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_76.gif" alt="" width="6" height="12" /> proportional to its slope, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_77.gif" alt="" width="58" height="24" />, with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_78.gif" alt="" width="73" height="12" />.</p>
<p>We can interpret the solution to this PDE in terms of a migratory population with the parameter <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_79.gif" alt="" width="5" height="12" /> controlling the speed of the migration as shown in the output from <tt>Manipulate</tt> displayed below (use the &#8220;speed&#8221; buttons to vary <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_80.gif" alt="" width="5" height="12" />). Data for the migration of gray whales along the California coastline would provide a real-life example of the phenomenon we are modeling. In the graphic, it is best to use the &#8220;Reset&#8221; button before changing the speed.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_6.gif" alt="" width="580" height="178" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_6.gif" alt="" width="403" height="403" /></p>
<p><tt>DSolve</tt> gives the following formula for the solution to the PDE <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_81.gif" alt="" width="58" height="24" />, which we might call the migration equation. As usual, the initial population profile is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_82.gif" alt="" width="73" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_7.gif" alt="" width="519" height="88" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Kerckhove_Output_7.gif" alt="" width="135" height="12" /></p>
<p>You may have seen in previous courses how changing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_83.gif" alt="" width="21" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_84.gif" alt="" width="39" height="12" /> changes the graph. Consider the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_85.gif" alt="" width="6" height="12" /> value <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_86.gif" alt="" width="47" height="12" /> on the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_87.gif" alt="" width="21" height="12" />; this same <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_88.gif" alt="" width="6" height="12" /> value occurs on the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_89.gif" alt="" width="39" height="12" />, but now it occurs at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_90.gif" alt="" width="26" height="12" />, since <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_91.gif" alt="" width="100" height="12" />. Likewise, you see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_92.gif" alt="" width="138" height="12" />, so that the same <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_93.gif" alt="" width="6" height="12" /> value, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_94.gif" alt="" width="12" height="12" />, that occurred at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_95.gif" alt="" width="12" height="12" /> along the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_96.gif" alt="" width="21" height="12" /> will occur along the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_97.gif" alt="" width="39" height="12" /> at input value <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_98.gif" alt="" width="30" height="12" />. Since this relationship holds for every <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_99.gif" alt="" width="12" height="12" />, we conclude that the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_100.gif" alt="" width="39" height="12" /> is a horizontal translation of the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_101.gif" alt="" width="21" height="12" /> to the right by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_102.gif" alt="" width="6" height="12" /> units. In our setting, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_103.gif" alt="" width="49" height="12" /> gives a graph that is the graph of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_104.gif" alt="" width="26" height="12" /> displaced to the right by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_105.gif" alt="" width="11" height="12" /> units. Note how <em>displacement </em><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_106.gif" alt="" width="8" height="12" /> <em>speed</em> <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_107.gif" alt="" width="8" height="12" /> <em>time</em>.</p>
<p>An application of the chain rule shows that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_108.gif" alt="" width="49" height="12" /> satisfies the migration equation for any initial population distribution <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_109.gif" alt="" width="12" height="12" />. This model also applies to the familiar stadium wave and is commonly referred to as the traveling wave equation. Jean le Rond d&#8217;Alembert first introduced PDEs for waves and methods for solving them in his study of vibrating strings [<a href="#d'Alembert">4</a>]. In fluid dynamics, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_110.gif" alt="" width="58" height="24" /> is a simplified version of the transport equation that models how dissolved solids travel along with a current.</p>
<h4>Seasonal Migration</h4>
<p>The migration of gray whales is seasonal, ranging from the southern Baja peninsula near the Tropic of Cancer to the Chukchi Sea north of the Arctic Circle [<a href="#OceanInstitute">5</a>]. To model the periodic nature of the whales&#8217; migration, we can translate the initial graph using a periodic function to obtain <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_111.gif" alt="" width="126" height="12" />. Now <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_112.gif" alt="" width="31" height="12" /> satisfies the periodic migration equation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_5.gif" alt="" width="213" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_113.gif" alt="" width="26" height="12" /> as the initial profile curve. You can see how the factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_114.gif" alt="" width="61" height="12" /> comes from the chain rule. The parameter <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_115.gif" alt="" width="5" height="12" /> still governs the speed of the migration; can you predict the feature of the graph that is related to the parameter <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_116.gif" alt="" width="8" height="12" />?</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_8.gif" alt="" width="580" height="271" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_8.gif" alt="" width="403" height="429" /></p>
<h3>Dispersion</h3>
<p>In response to overcrowding in one location, a population may disperse over a wider area. A model is provided by making the time evolution of the population graph proportional to the concavity of the graph. To see why this works, recall that a local maximum is characterized via the second derivative test as occurring where the tangent line is horizontal and the graph is concave down (negative second derivative). Thus, the model stipulates that near a local maximum, the future population will decrease. We write the dispersion equation as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_6.gif" alt="" width="101" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>and refer to the proportionality constant <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_117.gif" alt="" width="6" height="12" /> as the dispersion coefficient. The graph of the so-called fundamental solution to this equation,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_7.gif" alt="" width="149" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>is a bell-shaped curve whose standard deviation increases as time moves forward, starting from some time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_118.gif" alt="" width="30" height="12" />.</p>
<p>This verifies that this function solves the dispersion equation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_9.gif" alt="" width="290" height="74" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_9.gif" alt="" width="29" height="12" /></p>
<p>The larger the dispersion coefficient, the faster the dispersion takes place; use the buttons for the dispersion coefficient and the plus and minus buttons for time to show that the graph with dispersion coefficient 5 at time 20 is identical to the graph with dispersion coefficient 20 at time 5.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_10.gif" alt="" width="580" height="133" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_10.gif" alt="" width="403" height="383" /></p>
<p>In these graphs, the total population is represented by the area under the curve and does not change. As time moves forward, the dispersion process leads to a population that is, for practical purposes, uniformly distributed. In chemistry, our dispersion equation is called the diffusion equation: the concentration of dye in a liquid diffuses toward a uniform concentration over time. The origins of this equation are in the study of how heat dissipates from a source. Joseph Fourier began circulating results on the mathematics of heat conduction in 1807, when the heat equation was born. He published a treatise on the subject in 1822 [<a href="#Fourier">6</a>].</p>
<h3>Combined Models</h3>
<p>For a population that disperses as it migrates, we can combine the two previous models via the advection-dispersion equation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_8.gif" alt="" width="134" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>As you might expect, a fundamental solution involves replacing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_119.gif" alt="" width="6" height="12" /> by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_120.gif" alt="" width="29" height="12" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_9.gif" alt="" width="180" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>Use the &#8220;Reset and Play&#8221; button to see how the initial data evolves.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_11.gif" alt="" width="580" height="103" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_11.gif" alt="" width="403" height="333" /></p>
<p>A more interesting combined model can be employed in the study of invasive species. The figure below shows data related to the spread of gypsy moths in Wisconsin over a ten-year period from 1996 to 2006 [<a href="#Tobin">7</a>].</p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_12.gif" alt="" width="580" height="345" /></p>
<p>The darkest regions on the maps represent 11 or more moths per trapping area, which we will take as the statewide carrying capacity. We let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_121.gif" alt="" width="6" height="12" /> represent the distance from the Mississippi River on the western edge of the state, with the total distance to Lake Michigan roughly 180 miles. We combine dispersion with logistic growth to obtain the PDE</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_DisplayFormulaNumbered_10.gif" alt="" width="189" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:10">(10)</a></td>
</tr>
</tbody>
</table>
<p>This equation is solved numerically (think of applying Euler&#8217;s method to the entire profile curve), and the time evolution of the initial profile curve is plotted below.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Input_12.gif" alt="" width="580" height="178" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Output_13.gif" alt="" width="403" height="329" /></p>
<p>You can see that the model does not fit the data precisely: the &#8220;edges&#8221; of the gypsy moth population shown on the two maps are not as uniformly sharp as the model would predict. Biological systems are complicated, particularly because an element of randomness may come into play. Still, the concept of a model that includes dispersion and logistic growth, a variant of the Fisher-Kolmogorov equation, seems to capture most of the essential features of the gypsy moth data.</p>
<p>Finally, note that the total gypsy moth population is not constant, as it would be under a dispersion-only model. Here the growth term <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_122.gif" alt="" width="50" height="12" /> on the right-hand side of the equation overcomes dispersion, and as time moves forward, the population spreads across the whole state, while its size approaches the carrying capacity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_123.gif" alt="" width="8" height="12" /> at each location.</p>
<h3>Summary</h3>
<p>Using <tt>DSolve</tt> and <tt>Manipulate</tt>, we have illustrated three basic partial differential equations and interpreted the equations via a profile curve (a function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_124.gif" alt="" width="6" height="12" /> at a specific time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Kerckhove_Math_125.gif" alt="" width="4" height="12" />) that evolves with time, according to a rule that depends on function value, slope, or concavity. In terms of population dynamics, these equations were used to model location-dependent carrying capacity, migration, and dispersion. Combinations of the basic models were used to capture more complicated phenomena in a conceptually simple way that is suitable for students in a multivariate calculus class and that takes advantage of their previous experience with ODEs. A beginning textbook for PDEs is [<a href="#Strauss">8</a>]. Further applications to population dynamics appear in [<a href="#Holmes">9</a>].</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Stewart">[1] </a></td>
<td>J. Stewart, <em>Calculus: Concepts and Contexts</em>, 4th ed., Belmont, CA: Brooks/Cole, 2009.</td>
</tr>
<tr>
<td class="Reference"><a name="Malthus">[2] </a></td>
<td>T. Malthus. <em>An Essay on the Principle of Population</em>, London: J. Johnson, 1798.</td>
</tr>
<tr>
<td class="Reference"><a name="Verhulst">[3] </a></td>
<td>P.-F. Verhulst, &#8220;Notice sur la loi que la population poursuit dans son accroissement,&#8221; <em>Correspondance math</em>é<em>matique et physique</em>, <strong>10</strong>, 1838 pp. 113-121.<br />
<a href="http://books.google.com/books?hl=fr&amp;id=8GsEAAAAYAAJ&amp;jtp=113#v=onepage&amp;q&amp;f=false" target="blank">books.google.com/books?hl=fr&amp;id=8GsEAAAAYAAJ&amp;jtp=113# v=onepage&amp;q&amp;f=false</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="d'Alembert">[4] </a></td>
<td>J. d&#8217;Alembert, &#8220;Recherches sur la courbe que forme une corde tendue mise en vibration,&#8221; <em>Histoire de l&#8217;Académie royale des sciences et belles-lettres de Berlin</em>, <strong>3</strong>, 1747 pp. 214-219. <a href="http://www.math.jussieu.fr/~daubin/cours/Textes/Dalembert-HAB-1746-TFA.pdf" target="blank">www.math.jussieu.fr/~daubin/cours/Textes/Dalembert-HAB-1746-TFA.pdf</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="OceanInstitute">[5] </a></td>
<td>Ocean Institute. &#8220;Whales of the World.&#8221; (Sep 2, 2011)<br />
<a href="http://www.ocean-institute.org/visitor/gray_whale.html" target="blank">www.ocean-institute.org/visitor/gray_whale.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Fourier">[6] </a></td>
<td>J. Fourier, <em>Th</em>é<em>orie analytique de la chaleur</em>, Paris: F. Didot, 1822.</td>
</tr>
<tr>
<td class="Reference"><a name="Tobin">[7] </a></td>
<td>P. Tobin and L. Blackburn, &#8220;Long-Distance Dispersal of the Gypsy Moth (Lepidoptera: Lymantriidae) Facilitated Its Initial Invasion of Wisconsin,&#8221; <em>Environmental Entomology</em>, <strong>37</strong>(1), 2008 pp. 87-93. Figure used with permission of the authors. <a href="http://www.treesearch.fs.fed.us/pubs/14617" target="blank">www.treesearch.fs.fed.us/pubs/14617</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Strauss">[8] </a></td>
<td>W. Strauss, <em>Partial Differential Equations: An Introduction</em>, 2nd ed., Hoboken, NJ: John Wiley &amp; Sons, 2009.</td>
</tr>
<tr>
<td class="Reference"><a name="Holmes">[9] </a></td>
<td>E. Holmes, M. Lewis, J. Banks, and R. Veit, &#8220;Partial Differential Equations in Ecology: Spatial Interactions and Population Dynamics,&#8221; <em>Ecology</em>, <strong>75</strong>(1), 1994 pp. 17-29. <a href="http://www.esajournals.org/doi/abs/10.2307/1939378" target="blank">www.esajournals.org/doi/abs/10.2307/1939378</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">M. Kerckhove, &#8220;From Population Dynamics to Partial Differential Equations,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-9.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Michael Kerckhove is an associate professor of mathematics at the University of Richmond. This article grew out of a desire to introduce PDEs, particularly the diffusion equation, in the context of cell signaling early in the second semester of our Integrated Quantitative Science course, <a href="http://iqscience.richmond.edu/" target="blank">iqscience.richmond.edu</a>.</p>
<p class="TextAboutAuthor"><strong>Michael Kerckhove</strong><br />
<em>Department of Mathematics<br />
University of Richmond<br />
28 Westhampton Way<br />
Richmond, VA 23173</em><br />
<em><a href="mailto:mkerckho@richmond.edu">mkerckho@richmond.edu</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/04/from-population-dynamics-to-partial-differential-equations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asymptotic Methods of ODEs:</title>
		<link>http://www.mathematica-journal.com/2012/03/asymptotic-methods-of-odes/</link>
		<comments>http://www.mathematica-journal.com/2012/03/asymptotic-methods-of-odes/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 22:59:40 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=24561</guid>
		<description><![CDATA[We develop symbolic methods of asymptotic approximations for solutions of linear ordinary differential equations and use them to stabilize numerical calculations. Our method follows classical analysis for first-order systems and higher-order scalar equations where growth behavior is expressed in terms of elementary functions. We then recast our equations in modified form, thereby obtaining stability.
Introduction and [...]]]></description>
			<content:encoded><![CDATA[<p>We develop symbolic methods of asymptotic approximations for solutions of linear ordinary differential equations and use them to stabilize numerical calculations. Our method follows classical analysis for first-order systems and higher-order scalar equations where growth behavior is expressed in terms of elementary functions. We then recast our equations in modified form, thereby obtaining stability.<span id="more-24561"></span></p>
<h3>Introduction and Review</h3>
<p>Following [<a href="#Coddington">1</a>], we study methods to develop asymptotic estimates for a system of ordinary differential equations given in the form</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_1.gif" alt="" width="106" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_1.gif" alt="" width="8" height="12" /> is an <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_2.gif" alt="" width="24" height="12" /> matrix (with elements depending on <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_3.gif" alt="" width="4" height="12" />) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_4.gif" alt="" width="20" height="17" /> is a column matrix whose elements are unknown functions. We suppose that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_5.gif" alt="" width="8" height="12" /> has analytic coefficients near infinity and can be written as a series <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_6.gif" alt="" width="80" height="19" /> (convergent for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_7.gif" alt="" width="4" height="12" />) for constant matrices <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_8.gif" alt="" width="13" height="14" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_9.gif" alt="" width="14" height="12" /> is nontrivial. Such a singularity at finite <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_10.gif" alt="" width="4" height="12" /> may be turned into a singularity at infinity by a change of variables. This type of singularity for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_11.gif" alt="" width="34" height="12" /> is called a <em>singularity of the second kind</em>, also known as an &#8220;irregular&#8221; singularity [<a href="#Nayfeh">2</a>].</p>
<p>Differential equations of the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_12.gif" alt="" width="119" height="27" />, with the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_13.gif" alt="" width="13" height="14" /> bounded for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_14.gif" alt="" width="24" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_15.gif" alt="" width="32" height="12" />, can also be written in the above general matrix form by setting</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_2.gif" alt="" width="111" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>where the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_16.gif" alt="" width="15" height="14" /> have zero elements except: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_17.gif" alt="" width="16" height="12" /> has diagonal elements <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_18.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_19.gif" alt="" width="55" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_20.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_21.gif" alt="" width="74" height="15" />; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_22.gif" alt="" width="16" height="12" /> has ones on the diagonal above the main diagonal; the last row of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_23.gif" alt="" width="16" height="12" /> consists of the block matrix <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_24.gif" alt="" width="151" height="12" />. Here, solutions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_25.gif" alt="" width="6" height="12" /> and their first <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_26.gif" alt="" width="24" height="12" /> derivatives are given by the respective components of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_27.gif" alt="" width="8" height="14" /> as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_28.gif" alt="" width="122" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_29.gif" alt="" width="70" height="12" />.</p>
<h3>Asymptotic Procedures</h3>
<p>Consider a system of the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_30.gif" alt="" width="54" height="16" />, where the elements of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_31.gif" alt="" width="8" height="12" /> are analytic (near infinity) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_32.gif" alt="" width="157" height="15" /> (formal series) where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_33.gif" alt="" width="14" height="12" /> is a diagonal matrix of distinct complex numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_34.gif" alt="" width="11" height="14" />. Then, there are constant matrices <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_35.gif" alt="" width="8" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_36.gif" alt="" width="14" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_37.gif" alt="" width="87" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_38.gif" alt="" width="12" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_39.gif" alt="" width="57" height="12" />, so that the columns of</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_3.gif" alt="" width="180" height="42" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>are each asymptotic series for some solution of (<a href="#Eq:1">1</a>). Here the matrices <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_40.gif" alt="" width="8" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_41.gif" alt="" width="14" height="14" /> are diagonal, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_42.gif" alt="" width="13" height="12" /> may be taken as the identity matrix, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_43.gif" alt="" width="17" height="12" />may be taken to equal <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_44.gif" alt="" width="14" height="12" />; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_45.gif" alt="" width="19" height="12" /> denotes the matrix exponential and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_46.gif" alt="" width="75" height="15" />. This is a special case of theorems 2.1 and 4.1 of [<a href="#Coddington">1</a>, Chapter 5]. In fact, this method produces exact solutions in cases not treated here; see [<a href="#Coddington">1</a>, Chapter 4]. We do not repeat the entire proof of this result here, but we elaborate on the construction of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_47.gif" alt="" width="14" height="14" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_48.gif" alt="" width="8" height="12" />. By methods which amount to a matrix version of the dominant balance method, the matrices <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_49.gif" alt="" width="12" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_50.gif" alt="" width="25" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_51.gif" alt="" width="62" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_52.gif" alt="" width="8" height="12" /> satisfy</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormula_1.gif" alt="" width="257" height="40" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormula_2.gif" alt="" width="298" height="38" /></p>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_53.gif" alt="" width="25" height="12" />, let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_54.gif" alt="" width="12" height="18" /> denote the same matrix as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_55.gif" alt="" width="12" height="14" /> above, but with zeros on its main diagonal. For our objectives, we need only to solve for the corresponding <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_56.gif" alt="" width="12" height="18" /> to proceed. We obtain</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_4.gif" alt="" width="308" height="16" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>By <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_57.gif" alt="" width="33" height="12" />, we mean that diagonal matrix whose elements match those of the argument along the main diagonal; this is not the same as the <em>Mathematica</em> built-in function <tt>Diagonal</tt>. Then for each <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_58.gif" alt="" width="45" height="12" /> (provided <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_59.gif" alt="" width="25" height="12" />), we may recursively compute the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_60.gif" alt="" width="14" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_61.gif" alt="" width="12" height="16" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_62.gif" alt="" width="8" height="12" /> by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_5.gif" alt="" width="201" height="40" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_6.gif" alt="" width="357" height="40" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_7.gif" alt="" width="227" height="38" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<h3>Example System of Equations</h3>
<p>We begin with an example involving rational functions of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_63.gif" alt="" width="4" height="12" />. Such examples suffice in our general setting by our hypothesis on <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_64.gif" alt="" width="20" height="12" />. Consider the case <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_65.gif" alt="" width="25" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_66.gif" alt="" width="40" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_67.gif" alt="" width="40" height="12" />, and</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_8.gif" alt="" width="242" height="31" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>We only need terms of order <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_68.gif" alt="" width="4" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_69.gif" alt="" width="6" height="12" /> for accuracy up to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_70.gif" alt="" width="33" height="18" /> in the first factor of (<a href="#Eq:3">3</a>). We follow equation (<a href="#Eq:4">4</a>) to solve <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_71.gif" alt="" width="15" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_72.gif" alt="" width="13" height="16" /> and equation (<a href="#Eq:7">7</a>) to solve <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_73.gif" alt="" width="8" height="12" />. We denote <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_74.gif" alt="" width="12" height="18" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_75.gif" alt="" width="51" height="12" />, by <tt>P0</tt>, <tt>P1</tt>, <tt>P2</tt> in input, and so on for other variables.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_3.gif" alt="" width="529" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_4.gif" alt="" width="480" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_5.gif" alt="" width="580" height="88" /></p>
<p>Asymptotic solutions up to first derivatives are given by the columns of the matrix <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_76.gif" alt="" width="8" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_6.gif" alt="" width="504" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_1.gif" alt="" width="189" height="82" /></p>
<p>We find that there are two linearly independent solution vectors <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_77.gif" alt="" width="15" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_78.gif" alt="" width="15" height="16" /> satisfying</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormula_7.gif" alt="" width="347" height="39" /></p>
<p>We compare our result with the exact solution of an initial value problem of the following asymptotically equivalent [<a href="#Brower">3</a>] system:</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormula_8.gif" alt="" width="204" height="49" /></p>
<p>Routine calculations, involving hypergeometric functions, show that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_79.gif" alt="" width="151" height="33" /> for a constant <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_80.gif" alt="" width="49" height="12" />.</p>
<h4>Instability</h4>
<p>A natural way to check our results is to compute numerical results via <tt>NDSolve</tt>. Here, we compare our dominant asymptotic calculations from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_81.gif" alt="" width="15" height="16" /> to numerical results of the original equation (via <tt>Interpolation</tt>). Below we expect our graphs to have horizontal asymptotes; instead, we find the calculations to be unstable for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_82.gif" alt="" width="24" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_9.gif" alt="" width="580" height="94" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_2.gif" alt="" width="360" height="221" /></p>
<h4>Modification</h4>
<p>We can apply these asymptotic estimates to produce stable solutions from <tt>NDSolve</tt> for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_83.gif" alt="" width="4" height="12" />. We replace <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_84.gif" alt="" width="18" height="12" /> by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_85.gif" alt="" width="96" height="20" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_86.gif" alt="" width="18" height="12" /> by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_87.gif" alt="" width="93" height="18" /> to produce a solution <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_88.gif" alt="" width="27" height="12" /> with less drastic decay rates.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_10.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_3.gif" alt="" width="360" height="222" /></p>
<p>The solutions seem to be tending to limiting values for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_89.gif" alt="" width="4" height="12" /> near 600: all with no call to any special calculation options.</p>
<p>It is beyond the scope of this article to compare and contrast numerical schemes, since our objective is to predict theoretically the growth behavior of solutions as demonstrated using default options of <tt>NDSolve</tt>. Our method, we note, may serve to improve stability and reduce stiffness, yet we do not quantify such results. We do, however, note that widely varying exponential growth/decay of solutions is known to produce instability similar to what we see in the literature. References [<a href="#Iserles">4</a>, <a href="#Butcher">5</a>, <a href="#Sofroniou">6</a>] and the <tt>NDSolve</tt> documentation [<a href="#NDSolve">7</a>], among many others, introduce rigorous methods regarding such issues.</p>
<h3>Application to a Third-Order Ordinary Differential Equation</h3>
<p>We now study asymptotic behavior of solutions to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_90.gif" alt="" width="33" height="12" /> (for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_91.gif" alt="" width="24" height="12" />) for the operator <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_92.gif" alt="" width="140" height="18" />. Following (<a href="#Eq:2">2</a>) we study the system <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_93.gif" alt="" width="46" height="14" />, which we can write as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_DisplayFormulaNumbered_9.gif" alt="" width="348" height="45" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>We choose this example so as to force a diagonalization step before applying the procedure to produce estimates (<a href="#Eq:3">3</a>), after which we identify <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_94.gif" alt="" width="13" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_95.gif" alt="" width="64" height="12" /> (with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_96.gif" alt="" width="25" height="12" />).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_11.gif" alt="" width="580" height="43" /></p>
<p>We proceed with the diagonalization step.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_12.gif" alt="" width="479" height="43" /></p>
<p>Here <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_97.gif" alt="" width="15" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_98.gif" alt="" width="15" height="12" /> are obvious and, using (<a href="#Eq:4">4</a>) and (<a href="#Eq:5">5</a>), we compute <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_99.gif" alt="" width="13" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_100.gif" alt="" width="15" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_13.gif" alt="" width="580" height="118" /></p>
<p>Using (<a href="#Eq:6">6</a>) and (<a href="#Eq:7">7</a>) we compute <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_101.gif" alt="" width="13" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_102.gif" alt="" width="8" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_14.gif" alt="" width="580" height="133" /></p>
<p>We are ready to compute asymptotic solutions after a change of basis.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_15.gif" alt="" width="507" height="28" /></p>
<p>We multiply rows of the solution matrix by various powers of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_103.gif" alt="" width="4" height="12" /> to produce the various asymptotic estimates of solutions to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_104.gif" alt="" width="33" height="12" />, which we can read off from the columns of <tt>Soln</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_16.gif" alt="" width="513" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_4.gif" alt="" width="276" height="100" /></p>
<p>We find three different types of behavior for asymptotic solutions: rapid decay, rapid growth, and a constant solution. We can check that any constant function is indeed a solution, so the constant behavior is precise and not just asymptotic in this case. Moreover, any solution <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_105.gif" alt="" width="6" height="12" /> is majorized by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_106.gif" alt="" width="200" height="23" />.</p>
<h4><span class="Subsection">Graphical Results</span></h4>
<p>We check our results using two approaches. First we simply graph ratios <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_107.gif" alt="" width="100" height="14" /> with numerical solutions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_108.gif" alt="" width="8" height="14" />. Let us consider this using a nonconstant solution arising from the initial values <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_109.gif" alt="" width="154" height="12" />. The analysis for initial values <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_110.gif" alt="" width="40" height="12" /> is similar, and we invite the reader to check.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_17.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_5.gif" alt="" width="360" height="232" /></p>
<p>We are able to produce graphs using default options of <tt>NDSolve</tt> only for moderate domains of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_111.gif" alt="" width="4" height="12" />. For our second approach, we modify the operator by substituting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_112.gif" alt="" width="199" height="24" />, thereby theoretically guaranteeing bounded solutions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_113.gif" alt="" width="6" height="12" /> on intervals away from the origin <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_114.gif" alt="" width="27" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_18.gif" alt="" width="580" height="88" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Output_6.gif" alt="" width="360" height="231" /></p>
<p>We find instability as we calculate relative errors over large intervals (see [<a href="#Winfield">8</a>]), as in the previous section. Alternatively, we use a modified operator along with a linear change of variable to calculate solutions on intervals for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_115.gif" alt="" width="4" height="12" />. We apply the transformation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_116.gif" alt="" width="47" height="12" /> after applying the modification procedure above; then the initial value problem applied near <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_117.gif" alt="" width="24" height="12" /> for the new problem is equivalent to solving the original near <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_118.gif" alt="" width="32" height="12" />for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_119.gif" alt="" width="6" height="12" />. We find that in this way we can accurately compute solutions on large intervals in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_120.gif" alt="" width="4" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Input_19.gif" alt="" width="580" height="118" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Winfield_Output_7.gif" alt="" width="403" height="309" /></p>
<p>The advantage here is that the end result is of the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/03/Winfield_Math_121.gif" alt="" width="161" height="24" /> for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_122.gif" alt="" width="4" height="12" /> where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_123.gif" alt="" width="6" height="12" /> is computed with considerable accuracy and the other terms are known exactly.</p>
<h3>Conclusion</h3>
<p>The classical techniques of asymptotics can be calculated symbolically and in an automated way via simple matrix manipulations. These estimates can serve to check accuracy of numerical solutions both for scalar equations and for systems of equations of the types studied. Moreover, these estimates may serve to transform differential equations to certain modified versions that admit solutions bounded as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Winfield_Math_124.gif" alt="" width="39" height="12" />; as solutions of modified problems can be computed with accuracy and stability, with the transformation in elementary form, accuracy in our calculations is improved overall.</p>
<h3>Acknowledgments</h3>
<p>The author would like to thank the members of Madison Area Science and Technology for their discussions of <em>Mathematica</em> programming and various applications.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Coddington">[1] </a></td>
<td>E. Coddington and N. Levinson, <em>Theory of Ordinary Differential Equations</em>, New York: McGraw-Hill, 1955.</td>
</tr>
<tr>
<td class="Reference"><a name="Nayfeh">[2] </a></td>
<td>A. H. Nayfeh, <em>Perturbation Methods</em>, New York: Wiley, 1973.</td>
</tr>
<tr>
<td class="Reference"><a name="Brower">[3] </a></td>
<td>F. Brauer and J. Nohel, <em>The Qualitative Theory of Ordinary Differential Equations: An Introduction</em>, New York: W. A. Benjamin Inc., 1969.</td>
</tr>
<tr>
<td class="Reference"><a name="Iserles">[4] </a></td>
<td>A. Iserles, <em>A First Course in the Numerical Analysis of Differential Equations</em>, 2nd ed., New York: Cambridge University Press, 2009.</td>
</tr>
<tr>
<td class="Reference"><a name="Butcher">[5] </a></td>
<td>J. C. Butcher, <em>Numerical Methods for Ordinary Differential Equations</em>, Hoboken, NJ: Wiley, 2003.</td>
</tr>
<tr>
<td class="Reference"><a name="Sofroniou">[6] </a></td>
<td>M. Sofroniou and R. Knapp, <em>Wolfram Mathematica Tutorial Collection: Advanced Numerical Differential Equation Solving in Mathematica</em>, Champaign, IL: Wolfram Research, Inc., 2008. <a href="http://www.wolfram.com/learningcenter/tutorialcollection/AdvancedNumericalDifferentialEquationSolvingInMathematica">www.wolfram.com/learningcenter/tutorialcollection/AdvancedNumericalDifferentialEquationSolvingInMathematica</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="NDSolve">[7] </a></td>
<td>Wolfram Research, Inc. &#8220;Wolfram <em>Mathematica</em> Documentation Center: NDSolve.&#8221; (Sep 29, 2011) <a href="http://reference.wolfram.com/mathematica/ref/NDSolve.html">reference.wolfram.com/mathematica/ref/NDSolve.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Winfield">[8] </a></td>
<td>C. Winfield. &#8220;MAST Research Log: Application of <em>Mathematica</em> to a Third-Order Ordinary Differential Equation.&#8221; (May 18, 2011) <a href="http://www.madscitech.org/rlog/webref1.cdf" target="blank">www.madscitech.org/rlog/webref1.cdf</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">C. Winfield, &#8220;Asymptotic Methods of ODEs: Exploring Singularities of the Second Kind,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-8.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Christopher Winfield holds a Ph.D. in mathematics/real analysis from UCLA (1996) and an M.S. in physics from UW-Madison (1989). He has publications in partial differential equations, quantum scattering theory, and cosmology/Einstein&#8217;s equation. He currently works as a consultant with the Madison Area Science and Technology group based in Madison, Wisconsin.</p>
<p class="TextAboutAuthor"><strong>Christopher Winfield<br />
</strong><em>3783 US Hwy. 45<br />
Conover, WI 54519</em><strong><br />
</strong><em><a href="mailto:cjwinfield@madscitech.org">cjwinfield@madscitech.org</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/03/asymptotic-methods-of-odes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gambler&#8217;s Ruin and First Passage Time</title>
		<link>http://www.mathematica-journal.com/2012/03/gamblers-ruin-and-first-passage-time/</link>
		<comments>http://www.mathematica-journal.com/2012/03/gamblers-ruin-and-first-passage-time/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 22:58:54 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=24370</guid>
		<description><![CDATA[We investigate the classical problem of a gambler repeatedly betting $1 on the flip of a potentially biased coin until he either loses all his money or wins the money of his opponent. This is then extended to the case of his adversary (a casino) having practically unlimited resources and used to derive the inverse [...]]]></description>
			<content:encoded><![CDATA[<p>We investigate the classical problem of a gambler repeatedly betting $1 on the flip of a potentially biased coin until he either loses all his money or wins the money of his opponent. This is then extended to the case of his adversary (a casino) having practically unlimited resources and used to derive the inverse Gaussian distribution of the first passage time.<span id="more-24370"></span></p>
<h3>Probability of Winning the Game</h3>
<p>We assume that the probability of winning a single round of this game is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_1.gif" alt="" width="7" height="12" />, which is usually close, but not necessarily equal, to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_2.gif" alt="" width="9" height="23" />. Thus, for example, when betting $1 on black in the game of roulette, with 18 black, 18 red, and 1 green, all with equally likely outcomes, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_3.gif" alt="" width="7" height="12" /> is equal to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_4.gif" alt="" width="60" height="23" />. We also assume that our player and his adversary start with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_5.gif" alt="" width="6" height="12" /> dollars and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_6.gif" alt="" width="6" height="12" /> dollars, respectively, and that they are both determined to continue playing until one of them goes broke.</p>
<p>Our first objective is to find the probability that our player wins the game, ending up with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_7.gif" alt="" width="24" height="12" /> dollars. To do this, we have to imagine that the game has been going on for some time, and the player has reached the point of having exactly <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_8.gif" alt="" width="3" height="12" /> dollars in his pocket, so that his opponent has <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_9.gif" alt="" width="39" height="12" />. Given that, we denote our player&#8217;s probability of winning the game by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_10.gif" alt="" width="12" height="12" />. If one more round is played, one can see that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/03/Vrbik_Gambler_DisplayFormulaNumbered_1.gif" alt="" width="131" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>depending on whether the player wins (the first term) or loses (the second one) the next round [<a href="#Feller">1</a>]. The end conditions are <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_11.gif" alt="" width="45" height="12" /> (the game is already won) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_12.gif" alt="" width="34" height="12" /> (the game is lost). We thus have <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_13.gif" alt="" width="42" height="12" /> linear equations for the corresponding <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_14.gif" alt="" width="12" height="12" /> probabilities, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_15.gif" alt="" width="61" height="12" />. The equations are of a rather special type, as each of them involves only three consecutive values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_16.gif" alt="" width="12" height="12" />, so rather than using the usual <tt>LinearSolve</tt> procedure, it is more appropriate to switch to <tt>RSolve</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_1.gif" alt="" width="557" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_1.gif" alt="" width="141" height="58" /></p>
<p>When <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_17.gif" alt="" width="30" height="23" />, the solution is indeterminate, but we get the correct answer in the limit.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_2.gif" alt="" width="170" height="31" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_2.gif" alt="" width="32" height="31" /></p>
<p>All we have to do now is to evaluate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_18.gif" alt="" width="12" height="12" /> using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_19.gif" alt="" width="23" height="12" />. To this end, we build the following function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_3.gif" alt="" width="400" height="19" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_4.gif" alt="" width="187" height="12" /></p>
<p>We apply the function to the cases discussed so far.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_5.gif" alt="" width="163" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_3.gif" alt="" width="22" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_4.gif" alt="" width="58" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_5.gif" alt="" width="72" height="12" /></p>
<p>From these examples we can see that when both players start with the same amount of money and the coin is fair, each of them can win with the same probability of 50%. But as soon as the coin is slightly biased, the probability of the disadvantaged player winning decreases; this disparity becomes more pronounced as the initial capital of both players increases.</p>
<p>In practice, things are even worse than that: the casino starts with practically unlimited resources, which implies that a disadvantaged player does not stand any chance of winning whenever <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_20.gif" alt="" width="30" height="23" />. Should <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_21.gif" alt="" width="7" height="12" /> be slightly higher than <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_22.gif" alt="" width="9" height="23" /> though, his chances to continue winning indefinitely are computed by taking the limit of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_23.gif" alt="" width="14" height="12" /> as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_24.gif" alt="" width="32" height="12" />, resulting in</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_2.gif" alt="" width="66" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<h3>Distribution of the Game&#8217;s Duration</h3>
<p>To find the distribution of the random number of rounds it takes to complete a game with two players, each with finite resources, given that currently the first player has <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_25.gif" alt="" width="3" height="12" /> dollars in his pocket, we introduce the corresponding probability generating function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_26.gif" alt="" width="26" height="12" />. Similarly to how we solved for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_27.gif" alt="" width="12" height="12" />, we can now set up the equations</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_3.gif" alt="" width="188" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>where the multiplication by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_28.gif" alt="" width="5" height="12" /> is necessary to account for the extra round played. We also know that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_29.gif" alt="" width="101" height="12" /> (a probability generating function of 1 indicates that there are no more rounds to be played).</p>
<p>We now solve these equations.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_6.gif" alt="" width="558" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_6.gif" alt="" width="498" height="167" /></p>
<p>Substituting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_30.gif" alt="" width="6" height="12" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_31.gif" alt="" width="3" height="12" /> yields the corresponding result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_7.gif" alt="" width="515" height="89" /></p>
<p>Using this function, we can now easily find and display the corresponding distribution of the game&#8217;s duration.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_8.gif" alt="" width="534" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_7.gif" alt="" width="580" height="217" /></p>
<p>One can see that these games can easily last hundreds of rounds (things get worse when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_32.gif" alt="" width="7" height="12" /> approaches <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_33.gif" alt="" width="9" height="23" />).</p>
<p>Sometimes it is sufficient to know only the mean and variance of this distribution.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_9.gif" alt="" width="251" height="34" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_10.gif" alt="" width="566" height="101" /></p>
<p>The correctness of these formulas can be verified by recalling that the mean <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Mu.gif" alt="" width=" 6" height="19" /> of a distribution is given by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_34.gif" alt="" width="28" height="12" /> evaluated at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_35.gif" alt="" width="25" height="12" />, and its variance similarly by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_36.gif" alt="" width="94" height="15" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_11.gif" alt="" width="537" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_8.gif" alt="" width="7" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_12.gif" alt="" width="580" height="34" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_9.gif" alt="" width="7" height="12" /></p>
<p>The two formulas can be extended to the case of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_37.gif" alt="" width="30" height="23" /> by taking the corresponding limit.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_13.gif" alt="" width="174" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_10.gif" alt="" width="17" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_14.gif" alt="" width="189" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_11.gif" alt="" width="116" height="32" /></p>
<p>These impose the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_15.gif" alt="" width="137" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_16.gif" alt="" width="233" height="37" /></p>
<h4>The Case of an Infinitely Rich Adversary</h4>
<p>By analyzing the local variables <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_38.gif" alt="" width="5" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_39.gif" alt="" width="5" height="12" /> in the definition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_40.gif" alt="" width="7" height="12" />, we can see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_41.gif" alt="" width="25" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_42.gif" alt="" width="45" height="12" />, for any <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_43.gif" alt="" width="45" height="12" />. As <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_44.gif" alt="" width="32" height="12" />, we thus get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_4.gif" alt="" width="205" height="49" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>When <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_45.gif" alt="" width="30" height="23" />, the probability that the game finishes in finite time is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_46.gif" alt="" width="34" height="26" />, according to (<a href="#Eq:2">2</a>). The <em>conditional</em> probability generating function of the total number of rounds, given that the game does not continue indefinitely, is thus</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_5.gif" alt="" width="138" height="49" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>The more interesting case is when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_47.gif" alt="" width="30" height="23" />, which implies that the game cannot continue indefinitely. Expanding (<a href="#Eq:4">4</a>) in powers of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_48.gif" alt="" width="5" height="12" /> would enable us to plot the corresponding distribution, as was done at the beginning of this section; we leave this as an exercise. Here is the mean and variance of the total number of rounds.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_17.gif" alt="" width="203" height="50" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_18.gif" alt="" width="404" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_12.gif" alt="" width="42" height="32" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_19.gif" alt="" width="496" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_13.gif" alt="" width="84" height="35" /></p>
<h3>Brownian Motion</h3>
<p>In this last section, we explore yet another interesting limit of the gambler&#8217;s ruin problem. First we assume that the game is happening in &#8220;real time&#8221; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_49.gif" alt="" width="4" height="12" /> and that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_50.gif" alt="" width="6" height="12" /> rounds are played during each hour (or any other unit of time). We also assume that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_6.gif" alt="" width="91" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_51.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_52.gif" alt="" width="25" height="12" /> are two constants, and that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_53.gif" alt="" width="26" height="39" /> dollars are bet in each round instead of the original $1. In the limit as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_54.gif" alt="" width="32" height="12" />, this results in a new process called Brownian motion that runs in real (i.e. continuous) time and whose values constitute a continuous, even though nowhere differentiable, function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_55.gif" alt="" width="4" height="12" /> [<a href="#Bartlett">2</a>].</p>
<p>To visualize its possible course, we take <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_56.gif" alt="" width="50" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_57.gif" alt="" width="16" height="12" />2, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_58.gif" alt="" width="33" height="12" /> and display a random realization of the process; that is, we display its current values&#8212;the amount of money in the gambler&#8217;s pocket&#8212;as a function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_59.gif" alt="" width="4" height="12" /> during the next 50 hours, taking the initial value to be $100.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_20.gif" alt="" width="580" height="97" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_14.gif" alt="" width="580" height="218" /></p>
<p>Assuming the gambler can borrow money and continue playing even when the value of the process (his current worth) is negative, it is easy to see that this value at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_60.gif" alt="" width="4" height="12" /> is a normally distributed random variable with mean <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_61.gif" alt="" width="32" height="12" /> and variance <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_62.gif" alt="" width="11" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_63.gif" alt="" width="8" height="12" /> is the initial value, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_64.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_65.gif" alt="" width="5" height="12" /> (introduced earlier) are the so-called <em>drift</em> and <em>diffusion</em> coefficients, respectively. This assertion can be proved by realizing that the moment-generating function of the net win (equal to 1 with probability <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_66.gif" alt="" width="7" height="12" /> and to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_67.gif" alt="" width="15" height="12" /> with probability <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_68.gif" alt="" width="25" height="12" />) in one round of the original game is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_69.gif" alt="" width="123" height="12" />. To adjust this to the new game (winning or losing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_70.gif" alt="" width="26" height="39" /> dollars, instead of $1), replace each <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_71.gif" alt="" width="6" height="12" /> of the last expression by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_72.gif" alt="" width="34" height="39" />. To get the moment-generating function of the total win (or loss, when negative) accumulated during a time interval of length <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_73.gif" alt="" width="4" height="12" />, we have to add the results of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_74.gif" alt="" width="12" height="12" /> independent rounds, which corresponds to raising <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_75.gif" alt="" width="25" height="12" /> to the power of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_76.gif" alt="" width="12" height="12" />. Finally, we need to take the limit as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_77.gif" alt="" width="32" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_21.gif" alt="" width="471" height="41" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_15.gif" alt="" width="71" height="23" /></p>
<p>This is the moment-generating function of a normal distribution with expected value <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_78.gif" alt="" width="12" height="12" /> (the exponent&#8217;s coefficient of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_79.gif" alt="" width="6" height="12" />) and variance of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_80.gif" alt="" width="11" height="12" /> (the coefficient of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_81.gif" alt="" width="15" height="27" />). Since it represents only the total net <em>winnings</em> up to time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_82.gif" alt="" width="4" height="12" />, we have to add the initial value of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_83.gif" alt="" width="8" height="12" /> to get the distribution of the gambler&#8217;s net worth at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_84.gif" alt="" width="4" height="12" />; this will increase the expected value to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_85.gif" alt="" width="32" height="12" />.</p>
<h4>Inverse Gaussian Distribution</h4>
<p>We now establish the distribution of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_86.gif" alt="" width="8" height="12" />, the first passage time through the value of zero, which is the time at which the gambler has to stop playing, since he has lost all his money. We assume that he starts with the amount <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_87.gif" alt="" width="8" height="12" /> and that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_88.gif" alt="" width="26" height="12" />; reaching the value of zero in finite time is thus guaranteed.</p>
<p>We proceed similarly to deriving the distribution of his net worth: we first find the moment-generating function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_89.gif" alt="" width="8" height="12" /> in terms of the old game, with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_90.gif" alt="" width="6" height="12" /> rounds played every hour, and then take the limit as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_91.gif" alt="" width="32" height="12" />.</p>
<p>To get the moment-generating function of the number of rounds of the old game needed to go broke, we simply replace <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_92.gif" alt="" width="5" height="12" /> in (<a href="#Eq:4">4</a>) by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_93.gif" alt="" width="11" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_94.gif" alt="" width="6" height="12" /> by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_95.gif" alt="" width="36" height="39" />, the initial amount expressed in the new monetary units. To convert the result into hours, each consisting of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_96.gif" alt="" width="6" height="12" /> rounds, we need to replace <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_97.gif" alt="" width="6" height="12" /> by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_98.gif" alt="" width="9" height="21" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_22.gif" alt="" width="328" height="91" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_16.gif" alt="" width="125" height="40" /></p>
<p>The resulting moment-generating function can be rewritten in the following simple form, using only two parameters: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_99.gif" alt="" width="49" height="23" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_100.gif" alt="" width="43" height="23" /> (since <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_101.gif" alt="" width="26" height="12" />, both are positive):</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_7.gif" alt="" width="85" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>The corresponding probability density function is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_8.gif" alt="" width="171" height="50" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_102.gif" alt="" width="24" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_103.gif" alt="" width="39" height="12" /> otherwise. To prove this, we compute the moment-generating function of (<a href="#Eq:8">8</a>), which agrees with (<a href="#Eq:7">7</a>).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_23.gif" alt="" width="439" height="80" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_17.gif" alt="" width="111" height="33" /></p>
<p>The corresponding distribution is called the inverse Gaussian; it has mean <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_104.gif" alt="" width="10" height="12" /> and variance <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_105.gif" alt="" width="19" height="27" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_24.gif" alt="" width="580" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_18.gif" alt="" width="64" height="34" /></p>
<p>Its distribution function of cumulative probabilities can be expressed in terms of the distribution function of the standard normal distribution (denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_106.gif" alt="" width="8" height="12" />) as:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_DisplayFormulaNumbered_9.gif" alt="" width="252" height="51" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>We verify this, getting an expression that agrees with (<a href="#Eq:8">8</a>).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_25.gif" alt="" width="493" height="83" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_19.gif" alt="" width="125" height="62" /></p>
<p>Applying the inverse Gaussian distribution to our previous example (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_107.gif" alt="" width="25" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_108.gif" alt="" width="50" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_109.gif" alt="" width="40" height="12" />), we now display the distribution of time it takes the corresponding Brownian motion to reach zero for the first time.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_26.gif" alt="" width="421" height="80" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_20.gif" alt="" width="360" height="220" /></p>
<p>One last issue: to find the probability density function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_110.gif" alt="" width="8" height="12" /> when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_111.gif" alt="" width="30" height="23" />, we need to take the limit of (<a href="#Eq:8">8</a>) as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Math_112.gif" alt="" width="28" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Input_27.gif" alt="" width="416" height="50" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Vrbik_Gambler_Output_21.gif" alt="" width="88" height="50" /></p>
<p>This distribution has an infinite mean and variance.</p>
<h3>Conclusion</h3>
<p>The study of first passage times and their distributions is an important area of research. The author hopes that this article has provided a useful introduction to the topic.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Feller">[1] </a></td>
<td>W. Feller, <em>An Introduction to Probability Theory and Its Applications</em>, Vol. I, 3rd ed., New York: Wiley, 1968.</td>
</tr>
<tr>
<td class="Reference"><a name="Bartlett">[2] </a></td>
<td>M. S. Bartlett, <em>An Introduction to Stochastic Processes, with Special Reference to Methods and Applications</em>, 2nd ed., Cambridge: Cambridge University Press, 1966.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">J. Vrbik, &#8220;Gambler&#8217;s Ruin and First Passage Time,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-7.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor"><strong>Jan Vrbik</strong><br />
<em>Department of Mathematics, Brock University<br />
500 Glenridge Ave., St. Catharines<br />
Ontario, Canada, L2S 3A1<br />
</em><em><a href="mailto:jvrbik@brocku.ca">jvrbik@brocku.ca</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/03/gamblers-ruin-and-first-passage-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diffusion Modeling</title>
		<link>http://www.mathematica-journal.com/2012/03/diffusion-modeling/</link>
		<comments>http://www.mathematica-journal.com/2012/03/diffusion-modeling/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 22:58:23 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=23276</guid>
		<description><![CDATA[This article describes how to model diffusion using NDSolve, and then compares that to constructing your own methods using procedural, functional, rule-based, and modular programming. While based on the diffusion equation, these techniques can be applied to any partial differential equation.
Introduction
Using the built-in Mathematica command NDSolve to solve partial differential equations is very simple to [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes how to model diffusion using <tt>NDSolve</tt>, and then compares that to constructing your own methods using procedural, functional, rule-based, and modular programming. While based on the diffusion equation, these techniques can be applied to any partial differential equation.<span id="more-23276"></span></p>
<h3>Introduction</h3>
<p>Using the built-in <em>Mathematica</em> command <tt>NDSolve</tt> to solve partial differential equations is very simple to do, but it can hide what is really going on. You can always consult references about using <em>Mathematica</em> for differential equations [<a href="#Sofroniou-Knapp">1</a>, <a href="#Ganzha-Vorozhtsov">2</a>]. Exploring various programming methods also lets you create your own procedures that can be incorporated into <tt>NDSolve</tt> [<a href="#Sofroniou-Knapp">1</a>]. I chose the diffusion equation as the main example because there is so much material available for it and because of its high level of interest [<a href="#Ghez">3</a>, <a href="#Cussler">4</a>, <a href="#Crank">5</a>]. In this article I am using <em>Mathematica</em> 8.</p>
<p>Begin with a model of diffusion, in this case, the diffusion equation. The continuity equation is</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormula_1.gif" alt="" width="92" height="34" /></p>
<p>where <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" /> is the density, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_1.gif" alt="" width="4" height="12" /> is time, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_2.gif" alt="" width="10" height="12" /> is the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_3.gif" alt="" width="11" height="15" /> component of velocity. We can assume the rate of diffusion <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_4.gif" alt="" width="9" height="12" /> is constant and write the diffusion equation,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormulaNumbered_1.gif" alt="" width="71" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>For complete generality, we can write</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormula_2.gif" alt="" width="84" height="34" /></p>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_5.gif" alt="" width="17" height="15" /> is a positive-definite matrix of diffusion coefficients that may or may not depend on position and time; this is the diffusion tensor.</p>
<h3>Building Up Your Program Idea in Small Steps</h3>
<p>First, try built-in functions to see if they can solve your problem right away. The plan here is to use <tt>DSolve</tt> and then, when it likely fails to solve the PDE, try <tt>NDSolve</tt>. We are solving for a ring, so we will use only one spatial dimension. We begin by writing our diffusion equation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_3.gif" alt="" width="221" height="15" /></p>
<p>Now we try <tt>DSolve</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_4.gif" alt="" width="200" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_1.gif" alt="" width="365" height="18" /></p>
<p><tt>DSolve</tt> is unable to reach a solution to the naively formulated problem. We next provide a set of initial conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_5.gif" alt="" width="114" height="12" /></p>
<p>We incorporate the initial value and try again.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_6.gif" alt="" width="239" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_2.gif" alt="" width="468" height="18" /></p>
<p>Again it fails; we could play with the initial conditions until we found a set that worked, or we could try <tt>NDSolve</tt>. Let us say that we want to investigate the diffusion in a tube of gas. We consider this tube to be one dimensional to keep things simple. We assume our ring has a fixed length 1. We then &#8220;unwrap&#8221; the ring, making it a line, which lets us plot results. We will solve the equation for 10 units of time. We also specify the rate of diffusion.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_7.gif" alt="" width="51" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_3.gif" alt="" width="14" height="12" /></p>
<p>Let us try changing the initial density value to 0.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_8.gif" alt="" width="107" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_9.gif" alt="" width="211" height="12" /></p>
<p>We put all of these elements together into <tt>NDSolve</tt> and get a solution in the form of an interpolating function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_10.gif" alt="" width="409" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_4.gif" alt="" width="459" height="12" /></p>
<p>We can plot this function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_11.gif" alt="" width="290" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_5.gif" alt="" width="360" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 1.</strong> Solution to the diffusion equation with initial density of 0 in empty space.</p>
<p>Let us try another initial value, say a sinusoidal density wave.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_12.gif" alt="" width="321" height="12" /></p>
<p>Now we try a solution.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_13.gif" alt="" width="376" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_6.gif" alt="" width="459" height="12" /></p>
<p>We can plot this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_14.gif" alt="" width="290" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_7.gif" alt="" width="360" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 2.</strong> Solution to the diffusion equation with initial density based on a sine function. We have not determined the rate of diffusion.</p>
<p>This does not seem realistic, as the density drops to zero immediately. Now we need to determine what <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_6.gif" alt="" width="9" height="12" /> is, say 1.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_15.gif" alt="" width="51" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_16.gif" alt="" width="383" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_8.gif" alt="" width="459" height="12" /></p>
<p>Here is the plot.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_17.gif" alt="" width="297" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_9.gif" alt="" width="360" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 3.</strong> Solution to the diffusion equation with sinusoidal boundary conditions.</p>
<p>This seems more realistic than Figure 2, but the boundary conditions do not match up. If we think of this as a circle (wrapping the line to form a ring), we suddenly get a discontinuity when we go from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_7.gif" alt="" width="26" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_8.gif" alt="" width="26" height="12" />. We can repair our ring solution by using periodic boundary conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_18.gif" alt="" width="368" height="12" /></p>
<p>We are forcing an initial uniform density of 1, despite the sinusoidal boundary conditions in time, which would give us values of 0 density at the origin, and we do not want that. We get the solution, along with a warning message about inconsistent boundary and initial value conditions. Please ignore that in this case.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_19.gif" alt="" width="394" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Message_20.gif" alt="" width="580" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_10.gif" alt="" width="495" height="12" /></p>
<p>We can plot this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_21.gif" alt="" width="497" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_11.gif" alt="" width="360" height="267" /></p>
<p class="NumberedFigureCaption"><strong>Figure 4.</strong> A fairly good model of diffusion on a ring with sinusoidal boundary conditions.</p>
<p>This looks reasonable. The boundary conditions are now periodic, as on a ring. How do we write a program to do this?</p>
<h3>Procedural Programming of Diffusion</h3>
<p>Those of you who have programmed in languages like FORTRAN, C++, or Java are familiar with the idea of procedural programming. Procedures are executed in looping structures. We implement a finite-difference scheme to solve our equation. <tt>NDSolve</tt> is able to use finite differences as a specific method [<a href="#Sofroniou-Knapp">1</a>].</p>
<p>Begin by converting the diffusion equation to its finite-difference equivalent,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormulaNumbered_2.gif" alt="" width="176" height="38" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>Here a ring is divided into <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_9.gif" alt="" width="8" height="12" /> cells for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_10.gif" alt="" width="9" height="12" /> time steps. Specify a given cell&#8217;s density by considering the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_11.gif" alt="" width="11" height="15" /> cell for the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_12.gif" alt="" width="14" height="15" /> time step. So <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_13.gif" alt="" width="3" height="12" /> extends from 0 to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_14.gif" alt="" width="8" height="12" />, and time extends from 0 to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_15.gif" alt="" width="9" height="12" />. For any specific time step,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormula_22.gif" alt="" width="177" height="38" /></p>
<p>The stability condition [<a href="#Ganzha-Vorozhtsov">2</a>] is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormulaNumbered_3.gif" alt="" width="59" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>If this ratio is greater than 1/2, the solution becomes unstable in time. Write</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_DisplayFormulaNumbered_4.gif" alt="" width="192" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>If <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" />0</tt> is some set of initial conditions for <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" /></tt>, in the next time step we can use this equation to get a set of values for <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" /></tt>. We can then relabel these as the new <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" />0</tt> values and continue the calculation. We have to establish the initial conditions and use the procedural iterator <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_16.gif" alt="" width="191" height="12" /> to produce this result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_23.gif" alt="" width="310" height="12" /></p>
<p>Choose this for positions 0 to 6.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_24.gif" alt="" width="97" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_12.gif" alt="" width="129" height="12" /></p>
<p>We then develop the current time step as the initial conditions. This specifies the part of the list considered, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_17.gif" alt="" width="164" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_25.gif" alt="" width="114" height="12" /></p>
<p>Here are the periodic boundary conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_26.gif" alt="" width="169" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_13.gif" alt="" width="7" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_27.gif" alt="" width="169" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_14.gif" alt="" width="7" height="12" /></p>
<p>This completes the initialization step, establishing the initial conditions.</p>
<p>We now construct a single time step by rewriting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_18.gif" alt="" width="28" height="12" /> to include the boundary conditions, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_19.gif" alt="" width="354" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_28.gif" alt="" width="580" height="32" /></p>
<p>We test this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_29.gif" alt="" width="172" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_15.gif" alt="" width="43" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_30.gif" alt="" width="172" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_16.gif" alt="" width="7" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_31.gif" alt="" width="172" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_17.gif" alt="" width="43" height="12" /></p>
<p>Define a time step, again using <tt>Table</tt> to generate the list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_32.gif" alt="" width="531" height="12" /></p>
<p>We check this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_33.gif" alt="" width="205" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_18.gif" alt="" width="211" height="12" /></p>
<p>We now construct the solution in time, using <tt>Table</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_34.gif" alt="" width="580" height="12" /></p>
<p>This completes the model development.</p>
<p>Now we need to display the results. I make a test called <tt>run1</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_35.gif" alt="" width="249" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_19.gif" alt="" width="580" height="133" /></p>
<p>Here is the plot of these results.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_36.gif" alt="" width="115" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_20.gif" alt="" width="360" height="296" /></p>
<p class="NumberedFigureCaption"><strong>Figure 5.</strong> A jumbled mess of a solution for diffusion, not much like Figure 4.</p>
<p>This distorts and gets noisy very fast; of course we violated the stability condition with our choice of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_20.gif" alt="" width="9" height="12" />, so let us try it again. We know from (<a href="#Eq:3">3</a>) that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_21.gif" alt="" width="43" height="12" />. We need to reinitialize <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" />0</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_37.gif" alt="" width="97" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_21.gif" alt="" width="129" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_38.gif" alt="" width="114" height="12" /></p>
<p>Then we construct <tt>run</tt> using the correct value for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_22.gif" alt="" width="9" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_39.gif" alt="" width="254" height="31" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_22.gif" alt="" width="580" height="133" /></p>
<p>This produces the result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_40.gif" alt="" width="115" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_23.gif" alt="" width="360" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 6.</strong> A better solution that looks like Figure 4.</p>
<p>That looks better. This looks like the result we got from <tt>NDSolve</tt>, with some extra noise. We could use a finer grid and a better difference scheme if we wanted to get more precise and accurate. That is, however, the subject for another article.</p>
<h3>Functional Programming</h3>
<p>Another style of programming uses <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_23.gif" alt="" width="21" height="12" /> as the application of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_24.gif" alt="" width="7" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_25.gif" alt="" width="6" height="12" />. So we start by establishing a function in the traditional way, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_26.gif" alt="" width="263" height="12" />. Here we use the notation <tt>#</tt> to represent a formal argument.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_41.gif" alt="" width="124" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_24.gif" alt="" width="29" height="24" /></p>
<p>We could write this in short form without the word <tt>Function</tt>, but then we need an ampersand following the function statement so that <em>Mathematica</em> knows that the function statement is complete.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_42.gif" alt="" width="63" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_25.gif" alt="" width="29" height="24" /></p>
<p>We write <tt>#1</tt> and <tt>#2</tt> for two arguments.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_43.gif" alt="" width="182" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_26.gif" alt="" width="55" height="24" /></p>
<p>Or again we can write this in short form.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_44.gif" alt="" width="121" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_27.gif" alt="" width="55" height="24" /></p>
<p>We can apply a function to each element of a list by the use of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_27.gif" alt="" width="134" height="12" /> command.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_45.gif" alt="" width="151" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_28.gif" alt="" width="105" height="20" /></p>
<p>We could also use the short form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_28.gif" alt="" width="75" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_46.gif" alt="" width="124" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_29.gif" alt="" width="105" height="20" /></p>
<p>This is equivalent.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_47.gif" alt="" width="156" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_30.gif" alt="" width="105" height="20" /></p>
<p>Say we want to program the diffusion equation using functional programming. We begin by defining the list of cells in the ring. We use <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_29.gif" alt="" width="125" height="12" /> to produce a list from 1 to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_30.gif" alt="" width="75" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_48.gif" alt="" width="151" height="12" /></p>
<p>We decide we want to go from 1 to 6.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_49.gif" alt="" width="64" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_31.gif" alt="" width="111" height="12" /></p>
<p>We now define the initial conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_50.gif" alt="" width="276" height="12" /></p>
<p>For our choice of initial conditions, we have 1 everywhere, so we just say to divide by itself at each location.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_51.gif" alt="" width="133" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_32.gif" alt="" width="111" height="12" /></p>
<p>Now we specify the diffusion equation. Since we have periodic boundary conditions and a list, we can just rotate the list right and left.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_52.gif" alt="" width="488" height="32" /></p>
<p>We can test this. First, clear the procedural definition of <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" /></tt> from the previous section.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_53.gif" alt="" width="166" height="31" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_33.gif" alt="" width="111" height="12" /></p>
<p>We now need to impose our boundary conditions. Here we are replacing the end parts with the boundary conditions, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_31.gif" alt="" width="297" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_54.gif" alt="" width="417" height="12" /></p>
<p>We will test these.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_55.gif" alt="" width="98" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_34.gif" alt="" width="183" height="12" /></p>
<p>So we construct a single step.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_56.gif" alt="" width="580" height="12" /></p>
<p>Let us try it.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_57.gif" alt="" width="142" height="31" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_35.gif" alt="" width="183" height="12" /></p>
<p>We can construct a table to produce the result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_58.gif" alt="" width="560" height="12" /></p>
<p>We can try this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_59.gif" alt="" width="243" height="31" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_36.gif" alt="" width="580" height="133" /></p>
<p>We can plot this result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_60.gif" alt="" width="136" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_37.gif" alt="" width="360" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 7.</strong> Another solution that looks like Figure 4.</p>
<p>We have obtained the same result as with procedural programming.</p>
<h3>Rule-Based Programming and Pattern-Matching</h3>
<p>Another style of programming uses the symbolic nature of <em>Mathematica</em> to transform expressions. Rule-based programming uses the notion of transformation rules, which rewrite expressions based on their form. Take the expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_32.gif" alt="" width="29" height="24" /> and apply a transformation rule to it.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_61.gif" alt="" width="84" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_38.gif" alt="" width="29" height="24" /></p>
<p>Here is a more complicated example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_62.gif" alt="" width="231" height="26" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_39.gif" alt="" width="69" height="19" /></p>
<p>Coming back to the diffusion equation, we begin with the initial conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_63.gif" alt="" width="274" height="12" /></p>
<p>Then we execute it.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_64.gif" alt="" width="136" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_40.gif" alt="" width="129" height="12" /></p>
<p>Then we have the diffusion equation. Here the double underscore <tt>__</tt> following the <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Rho.gif" alt="" width="6" height="19" />0</tt> signifies a list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_65.gif" alt="" width="528" height="32" /></p>
<p>For our example, define <tt>t1</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_66.gif" alt="" width="228" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_41.gif" alt="" width="129" height="12" /></p>
<p>Define the boundary conditions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_67.gif" alt="" width="469" height="28" /></p>
<p>Test this for the first time step.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_68.gif" alt="" width="330" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_42.gif" alt="" width="266" height="12" /></p>
<p>We can test this again.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_69.gif" alt="" width="474" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_43.gif" alt="" width="354" height="12" /></p>
<p>We need to include an intermediate function that specifies the values for our model for the <tt>FoldList</tt> command.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_70.gif" alt="" width="188" height="31" /></p>
<p>We can then produce our model <tt>runt1</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_71.gif" alt="" width="580" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_44.gif" alt="" width="517" height="148" /></p>
<p>We can plot this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_72.gif" alt="" width="122" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_45.gif" alt="" width="360" height="279" /></p>
<p class="NumberedFigureCaption"><strong>Figure 8.</strong> Yet another solution that looks like Figure 4.</p>
<h3>Scoping Constructs</h3>
<p>A scoping construct makes symbols local so that they do not create or redefine global values. We can make local object names using the command <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_33.gif" alt="" width="190" height="12" />. We can temporarily assign values to variables with the command <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Math_34.gif" alt="" width="212" height="12" />. I will demonstrate the use of the <tt>Module</tt> command.</p>
<p>We can build a module for what we have been doing.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_73.gif" alt="" width="555" height="102" /></p>
<p>We can run this and plot the result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Input_74.gif" alt="" width="284" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Hrabovsky_Output_46.gif" alt="" width="360" height="279" /></p>
<p class="NumberedFigureCaption"><strong>Figure 9.</strong> Yet again another solution that looks like Figure 4.</p>
<h3>Conclusion</h3>
<p>We have seen that we can apply the canonical programming paradigms of <em>Mathematica</em> to the problem of diffusion. I have only scratched the surface of the diffusion problem. The methods I have presented could easily form the template for new methods for <tt>NDSolve</tt>, whose implementation is documented [<a href="#Sofroniou-Knapp">1</a>]. This flexibility in being able to introduce new methods into the existing structure of a <em>Mathematica</em> function is extremely powerful. Of course, the most powerful programming methods merge the paradigms.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Sofroniou-Knapp">[1] </a></td>
<td>M. Sofroniou and R. Knapp, <em>Advanced Numerical Differential Equation Solving in</em> <em>Mathematica</em>, Champaign, IL: Wolfram Research, Inc., 2008. <a href="http://www.wolfram.com/learningcenter/tutorialcollection/AdvancedNumericalDifferentialEquationSolvingInMathematica/">www.wolfram.com/learningcenter/tutorialcollection/AdvancedNumericalDifferentialEquationSolvingInMathematica</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ganzha-Vorozhtsov">[2] </a></td>
<td>V. G. Ganzha and E. V. Vorozhtsov, <em>Numerical Solutions for Partial Differential Equations</em>&#8212;<em>Problem Solving Using Mathematica</em>, Boca Raton, FL: CRC Press, Inc., 1996.</td>
</tr>
<tr>
<td class="Reference"><a name="Ghez">[3] </a></td>
<td>R. Ghez, <em>A Primer of Diffusion Problems</em>, New York: John Wiley and Sons, Inc., 1988. <a href="http://onlinelibrary.wiley.com/book/10.1002/3527602836" target="blank">onlinelibrary.wiley.com/book/10.1002/3527602836</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Cussler">[4] </a></td>
<td>E. L. Cussler, <em>Diffusion</em>: <em>Mass Transfer in Fluid Systems</em>, 3rd ed., New York: Cambridge University Press, 2009.</td>
</tr>
<tr>
<td class="Reference"><a name="Crank">[5] </a></td>
<td>J. Crank, <em>The Mathematics of Diffusion</em>, 2nd ed., Oxford, England: Clarendon Press, 1975.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">G. E. Hrabovsky, &#8220;Diffusion Modeling,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-6.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">George Hrabovsky is the president and founder of Madison Area Science and Technology, a nonprofit scientific research and education organization. He has been a <em>Mathematica</em> user and programmer for more than 20 years. He does research into theoretical physics, atmospheric science, and computational physics.</p>
<p class="TextAboutAuthor"><strong>George E. Hrabovsky<br />
</strong><em>105 Alhambra Place #2<br />
Madison, WI 53713</em><br />
<em><a href="mailto:george@madscitech.org">george@madscitech.org</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/03/diffusion-modeling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perimetric Complexity of Binary Digital Images</title>
		<link>http://www.mathematica-journal.com/2012/02/perimetric-complexity-of-binary-digital-images/</link>
		<comments>http://www.mathematica-journal.com/2012/02/perimetric-complexity-of-binary-digital-images/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 00:00:44 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=22997</guid>
		<description><![CDATA[Perimetric complexity is a measure of the complexity of binary pictures. It is defined as the sum of inside and outside perimeters of the foreground, squared, divided by the foreground area, divided by . Difficulties arise when this definition is applied to digital images composed of binary pixels. In this article we identify these problems [...]]]></description>
			<content:encoded><![CDATA[<p>Perimetric complexity is a measure of the complexity of binary pictures. It is defined as the sum of inside and outside perimeters of the foreground, squared, divided by the foreground area, divided by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_1.gif" alt="" width="16" height="13" />. Difficulties arise when this definition is applied to digital images composed of binary pixels. In this article we identify these problems and propose solutions. Perimetric complexity is often used as a measure of visual complexity, in which case it should take into account the limited resolution of the visual system. We propose a measure of visual perimetric complexity that meets this requirement.<span id="more-22997"></span></p>
<h3>Background</h3>
<p><em>Perimetric complexity</em> is a measure of the complexity of binary pictures. It is defined as the sum of inside and outside perimeters of the foreground, squared, divided by the foreground area, divided by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_2.gif" alt="" width="14" height="12" />. The concept of perimetric complexity was first introduced (and called <em>dispersion</em>) by Attneave and Arnoult [<a href="#Attneave">1</a>] in an effort to explain the apparent perceptual complexity of visual shapes. In the field of image processing, the concept appears as its inverse, <em>compactness</em> [<a href="#Sankar">2</a>, <a href="#Ullman">3</a>, <a href="#Montero">4</a>]. The concept was given new life (and a new name) in 2006 by Pelli et al., who showed that the efficiency of letter identification was nearly proportional to perimetric complexity [<a href="#Pelli">5</a>]. It has since become a popular metric in a variety of shape analysis applications, including human letter identification [<a href="#Pelli">5</a>, <a href="#Zhang">6</a>, <a href="#Watson">7</a>], handwriting recognition [<a href="#Rusu">8</a>], evolution of graphical symbols [<a href="#Garrod">9</a>], and design of graphical anti-spam technologies [<a href="#Chew">10</a>, <a href="#Biggio">11</a>, <a href="#Fumera">12</a>].</p>
<p>In this article we develop <em>Mathematica</em> functions to compute perimetric complexity of binary digital images and illustrate their application. The code is compatible with Version 8 of <em>Mathematica</em>.</p>
<p>Although the concept of perimetric complexity is clear when applied to continuous plane shapes, complications arise when the concept is extended to binary digital images. We discuss these complications and suggest suitable solutions. We also introduce the concept of visual perimetric complexity, which takes into account the blurring action of the human visual system.</p>
<p>We begin by illustrating the application of the function <tt>PerimetricComplexity</tt> to a binary image.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_1.gif" alt="" width="114" height="70" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_2.gif" alt="" width="180" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_1.gif" alt="" width="174" height="12" /></p>
<p>The output is a list containing the perimeter (in pixels), the area (in square pixels), and the complexity. In the following sections we describe the derivation of this function, as well as the options that may be used to control its operation.</p>
<h3>Perimetric Complexity of Geometric Shapes</h3>
<p>Perimetric complexity is a measure of the complexity of binary pictures. In a binary picture, one or several regions of the same color (white) are defined as foreground, and the remainder (black) as background. Perimetric complexity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_3.gif" alt="" width="8" height="12" /> is defined here as the sum of the inside and outside perimeters of the foreground <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_4.gif" alt="" width="7" height="12" />, squared, divided by the foreground area <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_5.gif" alt="" width="8" height="12" />, divided by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_6.gif" alt="" width="14" height="12" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_1.gif" alt="" width="53" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(1)</a></td>
</tr>
</tbody>
</table>
<p>In the remainder of this article, unless otherwise noted, we use the term complexity as synonymous with perimetric complexity.</p>
<p>We begin with the example of a circular disk with unit radius.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_3.gif" alt="" width="412" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_2.gif" alt="" width="128" height="128" /></p>
<p>Here the perimeter is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_7.gif" alt="" width="14" height="12" /> and the area is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_8.gif" alt="" width="6" height="12" />, so the complexity is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_2.gif" alt="" width="77" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(2)</a></td>
</tr>
</tbody>
</table>
<p>It can be shown that the disk is the shape with the lowest complexity. The normalizing constant <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_9.gif" alt="" width="14" height="12" /> in the definition leads to a unit value for this most simple shape. As a consequence, any other value of complexity is easily compared to that of the circular disk. Pelli et al. [<a href="#Pelli">5</a>] suggest that complexity is closely related to the number of visual features in a shape. In that sense, we could say that the circular disk has only a single feature.</p>
<p>Our next example is a square with unit sides.</p>
<p>The perimeter here is 4, and the area is 1, so the perimetric complexity is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_3.gif" alt="" width="106" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(3)</a></td>
</tr>
</tbody>
</table>
<p>If we add a square hole in the center with side length 1/2, there is an interior perimeter as well, as shown here.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_4.gif" alt="" width="293" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_3.gif" alt="" width="128" height="128" /></p>
<p>Now the total perimeter is the sum of inner and outer perimeters and the area is the difference in areas of the squares, so</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_4.gif" alt="" width="156" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(4)</a></td>
</tr>
</tbody>
</table>
<p>So according to this measure, the square with a hole is about three times as complex as the square.</p>
<p>Some important observations about complexity are: (1) it is dimensionless; (2) it is independent of scale or orientation; and (3) it is additive. By additive we mean that the complexity of a pair of shapes, considered as a single shape, is equal to the sum of their complexities computed separately.</p>
<h3>Perimetric Complexity of Plane Curves</h3>
<p>Although it is beyond the scope of this article, we note for reference that if a shape is defined by a closed parametric curve, its exact complexity can be obtained using calculus methods [<a href="#Courant">13</a>]. Specifically, if over an interval <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_10.gif" alt="" width="44" height="12" /> the functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_11.gif" alt="" width="18" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_12.gif" alt="" width="18" height="12" /> and their derivatives <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_13.gif" alt="" width="18" height="14" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_14.gif" alt="" width="18" height="14" /> are continuous, then the curve described has a length</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_5.gif" alt="" width="103" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(5)</a></td>
</tr>
</tbody>
</table>
<p>and an area</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Watson_DisplayFormulaNumbered_6.gif" alt="" width="78" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(6)</a></td>
</tr>
</tbody>
</table>
<h3>Perimetric Complexity of Binary Digital Images</h3>
<p>A digital image is defined here as a rectangular array of square pixels. A binary digital image contains pixel values of 1 (white) and 0 (black) only. The foreground consists of the white pixels.</p>
<p>The original definition of complexity relies upon the notion of a perimeter, which has no unique analog in the context of digital images. However, two definitions of perimeter are available, as described below.</p>
<h4>Using &#8220;PerimeterLength&#8221;</h4>
<p>The first definition we consider is the most straightforward. Consider a binary image consisting of a single white pixel.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_5.gif" alt="" width="175" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_4.gif" alt="" width="30" height="30" /></p>
<p>It seems natural to define the perimeter of this shape as 4 (pixels), and the area as 1 (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_15.gif" alt="" width="30" height="15" />), so <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_16.gif" alt="" width="42" height="12" />, the same as the square discussed earlier.</p>
<p>Now consider this shape consisting of 3 white pixels.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_6.gif" alt="" width="243" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_5.gif" alt="" width="32" height="32" /></p>
<p>Here the perimeter, consisting of the exposed pixel faces, is 8, and the area is 3, so <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_17.gif" alt="" width="64" height="12" />.</p>
<p>Extending this idea, we can define the perimeter as the sum of the exposed faces of pixels in the foreground.</p>
<p>Version 8 of <em>Mathematica</em> includes a set of functions from the discipline of mathematical morphology. These can be used to easily calculate perimetric complexity. To illustrate this we begin with a binary image with several separated parts.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_7.gif" alt="" width="89" height="55" /></p>
<p>The <tt>MorphologicalComponents</tt> function finds connected regions and labels them with integers. The <tt>Colorize</tt> function visualizes these regions by assigning colors to each label. The <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_18.gif" alt="" width="161" height="12" /> option ensures that only 4-connected neighborhoods are considered.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_8.gif" alt="" width="446" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_6.gif" alt="" width="53" height="53" /></p>
<p>The <tt>ComponentMeasurements</tt> function returns a selected set of measurements about each region. In this case we are interested in the area and the perimeter length. The results are returned as a set of rules, showing the results for each region.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_9.gif" alt="" width="561" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_7.gif" alt="" width="299" height="12" /></p>
<p>We can combine the perimeters and areas of the several regions, and then compute complexity in the usual way.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_10.gif" alt="" width="114" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_8.gif" alt="" width="69" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_11.gif" alt="" width="195" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_9.gif" alt="" width="50" height="12" /></p>
<p>The preceding calculations are implemented in the function <tt>PerimetricComplexity</tt>, defined in the Appendix. We can obtain the previous result.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_12.gif" alt="" width="494" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_10.gif" alt="" width="144" height="12" /></p>
<p>A list is returned, containing the perimeter, the area, and the complexity. The option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_19.gif" alt="" width="182" height="12" /> ensures that we use the definition of perimeter described above. The option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_20.gif" alt="" width="89" height="12" /> is explained later.</p>
<p>For future reference, to distinguish it from variants that we consider, we call this the &#8220;raw&#8221; perimetric complexity. Thus the same result can be obtained with the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_21.gif" alt="" width="96" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_13.gif" alt="" width="308" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_11.gif" alt="" width="144" height="12" /></p>
<h4>Using &#8220;PolygonalLength&#8221;</h4>
<p>The second definition of the perimeter of a connected region in a binary digital image is to consider the perimeter pixel centers as points on a lattice, and to define the length as the sum of the sides of the polygon defined by those points. This estimate of the perimeter is obtained from <tt>ComponentMeasurements</tt> by using the measurement <tt>"PolygonalLength"</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_14.gif" alt="" width="561" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_12.gif" alt="" width="391" height="12" /></p>
<p>Note that the measures of perimeter length are smaller than before.</p>
<p>And again complexity can be easily computed.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_15.gif" alt="" width="321" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_13.gif" alt="" width="50" height="12" /></p>
<p>This variant of perimetric complexity is implemented with the following options.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_16.gif" alt="" width="494" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_14.gif" alt="" width="165" height="12" /></p>
<p>Or, since <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_22.gif" alt="" width="182" height="12" /> is the default, the input can be simplified.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_17.gif" alt="" width="301" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_15.gif" alt="" width="165" height="12" /></p>
<h3>Approximating Complexity of Continuous Shapes</h3>
<p>We introduced the concept of perimetric complexity with a few continuous shapes, such as a square and a circle. In these cases, complexity is easily calculated, because we have simple formulas for the area and perimeter. It might be imagined that complexity of the continuous shape could be approximated by computing the complexity of a discrete sampled image, rendered from the shape. As we shall see, this assumption is not strictly correct.</p>
<p>Consider the circular disk. As noted at the beginning, it has <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_23.gif" alt="" width="28" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_18.gif" alt="" width="356" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_16.gif" alt="" width="128" height="128" /></p>
<p>We set the foreground color to white, as is our convention. Now we consider an image rendered from the continuous shape. We render it into a certain size image.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_19.gif" alt="" width="552" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_17.gif" alt="" width="129" height="129" /></p>
<p>If we compute the complexity, we find that it is 62% too large relative to the continuous shape.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_20.gif" alt="" width="359" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_18.gif" alt="" width="160" height="12" /></p>
<p>The reason is that the sampled image is actually more complex than the continuous shape. Its contour is jagged, while that of the continuous shape is smooth. It might be imagined that this could be remedied by increasing the resolution of the rendering. Here we show that belief is misplaced. We render at several sizes and plot the results. Size has little effect, and the complexity never approaches the value of 1 corresponding to the continuous shape.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_21.gif" alt="" width="519" height="118" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_19.gif" alt="" width="300" height="311" /></p>
<p>This problem can be somewhat ameliorated by using the <tt>PolygonalLength</tt> measure of perimeter length. Rather than the pure approach of measuring the exposed face of each foreground pixel, this measures the length of the contour that travels between the centers of those pixels.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_22.gif" alt="" width="516" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_20.gif" alt="" width="174" height="12" /></p>
<p>Now the difference is reduced to 9%. Here again, the reader might think that this difference could be reduced to zero by enlarging the resolution (number of pixels) in the rendered image, but this is not so. We leave that as an exercise for the reader. The error can never be zero, because the path between pixel centers must always be vertical, horizontal, or diagonal, so it can never smoothly follow the true circular contour. Put another way, it has a higher fractal dimension than the circle, and thus greater length.</p>
<h3>Pelli Algorithm</h3>
<p>Pelli et al. [<a href="#Sankar">2</a>] proposed a method for computing complexity that we quote here in full:</p>
<div class="Quote">The ink area is the number of 1&#8217;s. To measure the perimeter we first replace the image by its outline. (We OR the image with translations of the original, shifted by one pixel left; left and up; up; up and right; right; right and down; down; and down and left; and then bit clear with the original image. This leaves a one-pixel-thick outline.) It might seem enough to just count the 1&#8217;s in this outline image, but the resulting &#8220;lengths&#8221; are not Euclidean: diagonal lines have &#8220;lengths&#8221; equal to that of their base plus height. Instead we first thicken the outline. (We OR the outline image with translations of the original outline, shifted by one pixel left; up; right; and down.) This leaves a three-pixel-thick outline. We then count the number of 1&#8217;s and divide by 3.</div>
<p>This method can be implemented using the <tt>Dilation</tt> function, as we show here. With <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_24.gif" alt="" width="97" height="12" />, it shows two images: the perimeter in red and the thickened perimeter. It returns the length of the perimeter, the area, and the complexity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_23.gif" alt="" width="460" height="178" /></p>
<p>We apply this to the three-component Chinese character.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_24.gif" alt="" width="176" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_21.gif" alt="" width="165" height="86" /></p>
<p>The raw method gives the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_25.gif" alt="" width="308" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_22.gif" alt="" width="144" height="12" /></p>
<p>We see that the perimeter is substantially underestimated by the Pelli method in this case. This method has other limitations. It effectively assumes regions that are large in pixel dimensions. For example, consider the case of a single pixel object. As noted above, it has <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_25.gif" alt="" width="83" height="12" />. But the Pelli method yields a complexity value more than three times too large.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_26.gif" alt="" width="266" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_23.gif" alt="" width="35" height="35" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_27.gif" alt="" width="191" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_24.gif" alt="" width="128" height="86" /></p>
<h3>Visual Perimetric Complexity</h3>
<p>Much of the motivation for the use of perimetric complexity is the hope that it might provide an approximate measure of the visually perceived complexity of shapes. But this only makes sense if the shape is actually visible. Consider the difference between the continuous circular disk and its sampled image, as discussed above. They have different perimetric complexities, no matter how high the resolution of the sampled version. But of course, at a certain viewing distance, they are indistinguishable.</p>
<h4>Filtering</h4>
<p>Here we propose an approach to dealing with this problem. The idea is to first blur the image, in a manner consistent with visual blur, and then compute perimetric complexity. To make things simple, we use Gaussian blur, although this is not an accurate description of human visual blur. Later we show a more accurate form of blur. We begin with the example of a Chinese character jun (<span><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_1.gif" alt="" width="18" height="18" /></span>).</p>
<p>We pad the image slightly, so that the blur is contained, and then magnify, to allow greater flexibility in the filtering. Then we blur the image, in this case by a Gaussian filter with a radius of 8 pixels.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_28.gif" alt="" width="360" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_25.gif" alt="" width="256" height="256" /></p>
<p>Then we binarize the image. Unfortunately, this requires some method of setting the threshold. Here we use a fixed threshold of 0.5. We use <tt>ImageAdjust</tt> to ensure that the filtered image is amplified to fill the grayscale range before thresholding.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_29.gif" alt="" width="271" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_26.gif" alt="" width="256" height="256" /></p>
<p>And because we imagine that the image is viewed at such a distance that the pixels are not resolved, we use the (default) <tt>PolygonalLength</tt> method.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_30.gif" alt="" width="287" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_27.gif" alt="" width="174" height="12" /></p>
<p>We can compare this to the unfiltered raw complexity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_31.gif" alt="" width="316" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_28.gif" alt="" width="151" height="12" /></p>
<p>The filtered version has substantially lower complexity, as we expect.</p>
<h4>Visual Filtering Using a Gaussian</h4>
<p>For the filtering to approximate visual blur, it must be based on the size of the original image and its distance from the viewer. Obviously, as the shape becomes smaller or farther from the observer, its details are more blurred, less visible, and contribute less to the visual complexity.</p>
<p>The challenge is to determine the appropriate value of the Gaussian filter radius for a given viewing distance. From measurements of visual sensitivity, we know that visual Gaussian blur has a standard deviation of about <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_26.gif" alt="" width="60" height="12" /> degrees of visual angle [<a href="#Biggio">11</a>]. But we need to convert this into a radius in pixels. Recall that the image may be magnified by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_27.gif" alt="" width="11" height="12" /> before filtering. If we express the viewing distance <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_28.gif" alt="" width="8" height="12" /> in terms of pixels (before magnification), then the size of each pixel <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_29.gif" alt="" width="6" height="12" /> (after magnification) is approximately</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_7.gif" alt="" width="67" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(7)</a></td>
</tr>
</tbody>
</table>
<p>The constant 57.3 is an approximation to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/02/Watson_Math_30-1.gif" alt="" width="64" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_32.gif" alt="" width="97" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_29.gif" alt="" width="50" height="12" /></p>
<p>By default, the radius is twice the standard deviation. So the filter radius should be</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_8.gif" alt="" width="122" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(8)</a></td>
</tr>
</tbody>
</table>
<p>Consider an example. Suppose that our Chinese character image is displayed on a typical computer screen with a resolution of 72 pixels/inch, and viewed at a distance of 48 inches.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_33.gif" alt="" width="63" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_30.gif" alt="" width="29" height="12" /></p>
<p>Recall the value of <tt>B</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_34.gif" alt="" width="79" height="12" /></p>
<p>Suppose further that the magnification is 4.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_35.gif" alt="" width="37" height="12" /></p>
<p>Then we know <tt>R</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_36.gif" alt="" width="100" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_31.gif" alt="" width="50" height="12" /></p>
<p>We now proceed with the steps outlined above for filtering.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_37.gif" alt="" width="346" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_32.gif" alt="" width="224" height="224" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_33.gif" alt="" width="174" height="12" /></p>
<p>The preceding steps of padding, magnification, and filtering are built into the function <tt>PerimetricComplexity</tt>, as shown below. With <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_30.gif" alt="" width="96" height="12" />, the function also shows the original, the filtered version, the binarized version, and the original (in red) with the perimeter of the filtered version (in white within the original and aqua outside the original).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_38.gif" alt="" width="580" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_34.gif" alt="" width="400" height="120" /></p>
<p>The Gaussian is parameterized by a scale in degrees of visual angle. The default value is 2.33/60 degrees. The user can experiment with different values via the option <tt>GaussianScale</tt>.</p>
<h4>Accurate Visual Filtering with Sech</h4>
<p>Visual blur is more accurately represented with filters other than a Gaussian. In one simple form, the kernel is a sech (hyperbolic secant) function [<a href="#Watson2005">14</a>, <a href="#Watson2011">15</a>]. This filter can be selected with an option (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_31.gif" alt="" width="103" height="12" />, the default) in the function <tt>PerimetricComplexity</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_39.gif" alt="" width="180" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_35.gif" alt="" width="165" height="12" /></p>
<p>The hyperbolic secant is parameterized by a scale in degrees of visual angle. The default value is 2.16/60 degrees [<a href="#Watson2005">14</a>, <a href="#Watson2011">15</a>]. The user can experiment with different values via the option <tt>SechScale</tt>.</p>
<h4>Accurate Visual Filtering with an Arbitrary Point Spread Function</h4>
<p>In real human eyes, blur results not only from low-order aberrations such as defocus and astigmatism, but also from higher-order aberrations. In this example, we use a blur function defined by an array of values representing the filter kernel. This example is an actual estimate of the point spread function for an individual human observer, as measured using a device called a wavefront aberrometer that includes both low-order and high-order aberrations [<a href="#Thibos">16</a>].</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_40.gif" alt="" width="165" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_36.gif" alt="" width="64" height="64" /></p>
<p>We can use this blur kernel by supplying it directly to the <tt>Filter</tt> option.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_41.gif" alt="" width="509" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_37.gif" alt="" width="400" height="120" /></p>
<p>In the above calculation we used a magnification of 2. We do not address this topic in detail, but when a kernel is supplied, the pixels of the kernel and of the magnified image must be of the same size, in degrees of visual angle, for the filter to be accurate. The size of the magnified pixels in degrees depends upon the viewing distance and the magnification, as described above.</p>
<h4>Magnification Parameter</h4>
<p>The <tt>Magnification</tt> parameter should be set with a value that ensures that a filter kernel, if present, has enough pixels in it to adequately represent the filter. For the <tt>Sech</tt> filter, we generally want a width of least three times the scale, and at least 8 pixels. This means that for the magnification,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_DisplayFormulaNumbered_9.gif" alt="" width="64" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Unspecified">(9)</a></td>
</tr>
</tbody>
</table>
<p>This rule is effectively implemented by the default <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_32.gif" alt="" width="176" height="12" /> option.</p>
<h4>Binarization</h4>
<p>After applying visual blur, it is necessary to binarize the image before calculating the perimetric complexity. There are many ways to binarize an image and <em>Mathematica</em> offers many of them as options. The simplest is to use a fixed threshold. Since our images are initially defined as 0 or 1, a natural choice of threshold is 0.5. One drawback of this choice is that as images become severely blurred, no pixels may remain that exceed the threshold. From a perceptual point of view, the mean might appear a reasonable choice. As the image blurs, all pixels revert towards the mean, but some always remain above the mean until a uniform image is reached. A drawback of the mean is that it is influenced by the area of the background. For this reason, we adopt the fixed value of 0.5 as the default threshold for binarization.</p>
<p>We should acknowledge that a more valid visual thresholding scheme might be devised that better reflects our perceptual segregation of areas into light and dark. This is a topic for future research.</p>
<p>It should also be acknowledged that for severely blurred images, considerable grayscale information remains that is lost in binarization. Thus we should question whether perimetric complexity is an appropriate measure for such images.</p>
<p>To illustrate that problem, we show an example of a character viewed at 10 feet on a display with 100 pixels/inch. Note that the blurred image displays internal grayscale structure that is not conveyed by the binarized version.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_42.gif" alt="" width="499" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_38.gif" alt="" width="400" height="120" /></p>
<h4>Viewing Distance</h4>
<p>For a given shape, complexity declines with viewing distance as a result of visual blur. Here we illustrate this effect with an example Chinese character. First we find the raw complexity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_43.gif" alt="" width="388" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_39.gif" alt="" width="50" height="12" /></p>
<p>Now we compute complexity for viewing distances ranging from 3 inches to 10 feet, assuming a display with a resolution of 100 pixels/inch. For reference, we show as red lines the raw complexity and the theoretical limit of 1 (a circular disk). As it should, the visual complexity proceeds from one of these limits to the other as distance increases.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_44.gif" alt="" width="580" height="88" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_40.gif" alt="" width="360" height="234" /></p>
<p>At very small viewing distances (in pixels) the blur has little effect on each pixel, so the visual complexity approaches the raw value. As a rule of thumb, this asymptote is approached when the size of each pixel exceeds 1/4 degree.</p>
<p>It is reassuring to know that the algorithm does approach the correct asymptote as distance increases. Here we show the intermediate images for a case of extreme blur (distance = 30 feet).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_45.gif" alt="" width="499" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_41.gif" alt="" width="400" height="120" /></p>
<p>But a note of caution is warranted. Consider the effect of distance on our other example character yi (<span><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_3.gif" alt="" width="23" height="23" /></span>). We show it here along with the previous plot. Note that the curves cross, so that at large distances (large blurs) the &#8220;simpler&#8221; character becomes the more complex of the two.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_46.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_42.gif" alt="" width="360" height="234" /></p>
<p>This makes sense, since the densely packed features of the &#8220;complex&#8221; character blur onto each other, while the more widely separated features of the &#8220;simple&#8221; character remain distinct. This is illustrated in the following, which shows the intermediate images for the two characters when highly blurred (distance = 10 feet).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_47.gif" alt="" width="576" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_43.gif" alt="" width="420" height="262" /></p>
<p>But the conclusion we must draw is that even the <em>relative</em> complexity of different shapes cannot be known without specifying the viewing distance.</p>
<p>We use the quantity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_33.gif" alt="" width="225" height="12" /> as a default value. This corresponds to a visual resolution of 48 pixels/degree. It is a commonly encountered resolution, about that achieved by a display with 100 pixels/inch viewed from 27 inches. But in actual use, it is advised to use the actual viewing distance rather than relying on this default.</p>
<p>Here is a <tt>Manipulate</tt> that lets you experiment with different viewing distances. The complexity and the diagnostic images are shown.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_48.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_44.gif" alt="" width="443" height="205" /></p>
<h3>Recommended Practice</h3>
<p>In general, we recommend using the function with default parameters, shown here as a reminder.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_49.gif" alt="" width="208" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_45.gif" alt="" width="580" height="43" /></p>
<p>The only option that should be specified for the typical use of this function is <tt>ViewingDistance</tt>. This specifies the distance from the eye to the image in pixels. The default is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_34.gif" alt="" width="175" height="12" />, consistent with a display having 96 pixels/inch viewed at 28.65 inches (equal to a display with 48 pixels/degree of visual angle).</p>
<p>It is difficult to imagine a case in which vision, in some form, would not be used to view the shape in question. If such a case arises, however, the &#8220;raw&#8221; complexity can be measured with the following options.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_50.gif" alt="" width="342" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_46.gif" alt="" width="580" height="43" /></p>
<p>This is also an appropriate measure when the pixels are very large (larger than 1/4 degree).</p>
<p>When trying to approximate the raw complexity of a continuous shape by means of a sampled representation (e.g., a circle via an image of a circle), the following options yield the lowest error. But as noted above, the error is still significant.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_51.gif" alt="" width="330" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_47.gif" alt="" width="580" height="43" /></p>
<h3>Examples</h3>
<p>We conclude with two examples of the application of <tt>PerimetricComplexity</tt>.</p>
<p>The first example is a set of three binary images. Below each image we print the complexity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_52.gif" alt="" width="220" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_53.gif" alt="" width="580" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_48.gif" alt="" width="438" height="146" /></p>
<p>The second example is an array of characters. This array was created as part of an experiment on the effect of complexity on visual acuity [<a href="#Zhang">6</a>]. The first row is the Sloan letters, a well-known set of letter acuity targets [<a href="#Pelli">5</a>]. The remaining six rows are sets of Chinese characters selected so as to be of equal complexity within a row, but increasing in complexity from row to row [<a href="#Zhang">6</a>]. The metric of complexity used for selection was different from that developed in this article.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_54.gif" alt="" width="165" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_49.gif" alt="" width="128" height="89" /></p>
<p>We first apply the function to each character and plot the results, with a different curve for each set.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_55.gif" alt="" width="392" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Watson_Output_50.gif" alt="" width="300" height="181" /></p>
<p>The plot shows that there is considerable variation in each set. If we take the mean of each set we see a progression in complexity, except for the last three sets. In the next graphic we show at the bottom an exemplar from each set.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_56.gif" alt="" width="560" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/02/Watson_Output_51.gif" alt="" width="300" height="181" /></p>
<h3>Conclusion</h3>
<p>We have illustrated several different methods for computing the perimetric complexity of binary digital images. These methods differ in how they compute the perimeter and in whether the image is blurred and binarized before the complexity calculation. We have introduced the concept of visual perimetric complexity and argued that in general it requires blur for a sensible estimate. We have described several methods of implementing visual blur.</p>
<p>The computed value of visual perimetric complexity depends somewhat upon details of the calculation, such as the presumed magnitude and nature of visual blur, and the binarization threshold. In this regard, we have proposed a set of standard default settings and procedures for calculation of visual perimetric complexity.</p>
<p>We have also made the observation that visual perimetric complexity cannot be estimated without specifying the resolution of the display and the viewing distance. As a general rule, the visual perimetric complexity approaches the raw complexity when the width of a pixel exceeds 1/4 degree of visual angle.</p>
<h3>Appendix</h3>
<h4>Functions</h4>
<p>Here we define several functions based on the derivations presented above.</p>
<h5>PerimetricComplexity</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_57.gif" alt="" width="580" height="58" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_58.gif" alt="" width="580" height="298" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_59.gif" alt="" width="580" height="838" /></p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_60.gif" alt="" width="316" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_52.gif" alt="" width="400" height="120" /></p>
<h5>PerimeterLength</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_61.gif" alt="" width="580" height="118" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_62.gif" alt="" width="549" height="283" /></p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_63.gif" alt="" width="340" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_53.gif" alt="" width="32" height="32" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_64.gif" alt="" width="331" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_54.gif" alt="" width="7" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_65.gif" alt="" width="324" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_55.gif" alt="" width="94" height="120" /></p>
<h5>PixelPathLength</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_66.gif" alt="" width="580" height="43" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_67.gif" alt="" width="419" height="88" /></p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_68.gif" alt="" width="344" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_56.gif" alt="" width="30" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_57.gif" alt="" width="71" height="31" /></p>
<h5>PixelBorderLength</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_69.gif" alt="" width="580" height="58" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_70.gif" alt="" width="360" height="28" /></p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_71.gif" alt="" width="401" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_58.gif" alt="" width="40" height="42" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_59.gif" alt="" width="7" height="12" /></p>
<h5>SechKernel2D</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_72.gif" alt="" width="580" height="103" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_73.gif" alt="" width="580" height="43" /></p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_74.gif" alt="" width="371" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_60.gif" alt="" width="32" height="32" /></p>
<h5>Perimeter</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_75.gif" alt="" width="580" height="73" /></p>
<h4>Initializations</h4>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_76.gif" alt="" width="266" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_77.gif" alt="" width="580" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_78.gif" alt="" width="527" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_79.gif" alt="" width="527" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_80.gif" alt="" width="527" height="28" /></p>
<p>The next closed cell contains the definition of <tt>psf</tt>, a 64×64 array of numbers.</p>
<h5>psf</h5>
<h5>characters</h5>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_81.gif" alt="" width="98" height="56" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_82.gif" alt="" width="89" height="55" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_83.gif" alt="" width="580" height="1106" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_84.gif" alt="" width="114" height="70" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_85.gif" alt="" width="118" height="59" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_86.gif" alt="" width="125" height="59" /></p>
<h4>Computing Complexity without Using <em>Mathematica</em>&#8217;s Morphological Operators</h4>
<p>Some readers may wish to write programs in other languages to compute complexity. For that reason we provide an explanation here of how to compute complexity without using 3×3 morphological operators. This amounts to finding alternate methods for computing the perimeter. These are incorporated in the function <tt>PerimeterLength</tt>, defined above, and derived below. These functions can be exercised from within <tt>PerimetricComplexity</tt> by selecting the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_35.gif" alt="" width="211" height="12" />. This is useful mainly for testing.</p>
<p>Consider the following binary image.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_87.gif" alt="" width="22" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_61.gif" alt="" width="54" height="54" /></p>
<p>The foreground area is easily obtained, since it is just the sum of all the white pixels.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_88.gif" alt="" width="169" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_62.gif" alt="" width="29" height="12" /></p>
<h5>Using &#8220;PerimeterLength&#8221;</h5>
<p>As noted above, there are two definitions of the perimeter of a binary digital image. The first consists of the sum of the exposed pixel faces. To count the exposed faces we use the function <tt>PixelBorderLength</tt>. This takes a binary image of dimensions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_36.gif" alt="" width="27" height="12" /> and counts the number of black 4-connected neighbors of the center pixel.</p>
<p>Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_89.gif" alt="" width="408" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_63.gif" alt="" width="40" height="42" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_90.gif" alt="" width="165" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_64.gif" alt="" width="7" height="12" /></p>
<p>In this example, the center pixel has only two black neighboring pixels.</p>
<p>The total perimeter can be obtained by applying this function to the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_37.gif" alt="" width="27" height="12" /> neighborhood of every white pixel in the image. Pixels in the interior return a value of 0, so only perimeter pixels contribute.</p>
<p>To implement this idea, we first identify the positions of all the white pixels.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_91.gif" alt="" width="278" height="12" /></p>
<p>Next we extract all the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Math_38.gif" alt="" width="27" height="12" /> neighborhoods.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_92.gif" alt="" width="560" height="12" /></p>
<p>We can look at the first five.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_93.gif" alt="" width="242" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_65.gif" alt="" width="258" height="42" /></p>
<p>We can also compute the pixel border length of the first five.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_94.gif" alt="" width="321" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_66.gif" alt="" width="93" height="12" /></p>
<p>In a large complex image, the same neighborhood might occur many times, so we perform a tally.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_95.gif" alt="" width="202" height="12" /></p>
<p>We can take a look at the tally along with the pixel border length for each type of neighborhood. Note that 850 cases consist of all white, drawn from the interior of the foreground, with 0 border length. Here we just look at the first 10 elements of the tally.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_96.gif" alt="" width="548" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_67.gif" alt="" width="119" height="448" /></p>
<p>The total perimeter length is the sum of all of the border lengths for all the collected neighborhoods. We use the tallied neighborhoods, so that the pixel border length of each type of neighborhood is computed only once.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_97.gif" alt="" width="354" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_68.gif" alt="" width="22" height="12" /></p>
<p>This is the complexity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_98.gif" alt="" width="156" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_69.gif" alt="" width="50" height="12" /></p>
<h5>Using &#8220;PolygonalLength&#8221;</h5>
<p>The second definition of the length of the perimeter is the sum of sides of the polygon defined by the perimeter pixels considered as points in a lattice.</p>
<p>To extract the perimeter, we use a new function <tt>Perimeter</tt>, defined above. This duplicates a built-in <em>Mathematica</em> function. We verify that they yield the same results.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_99.gif" alt="" width="181" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_70.gif" alt="" width="129" height="129" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_100.gif" alt="" width="454" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_71.gif" alt="" width="129" height="129" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_101.gif" alt="" width="295" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_72.gif" alt="" width="54" height="54" /></p>
<p>We identify the positions of all of the pixels in the perimeter.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_102.gif" alt="" width="371" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_73.gif" alt="" width="22" height="12" /></p>
<p>We extract all of the 3×3 neighborhoods of pixels in the perimeter.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_103.gif" alt="" width="580" height="12" /></p>
<p>Then we use a new function <tt>PixelPathLength</tt>, which looks at a 3×3 binary neighborhood, identifies the two closest white pixels not at the center, and finds the distances from their centers to that of the central pixel. That is the path length corresponding to that neighborhood.</p>
<p>We apply this to all the perimeter pixels and add up the results.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_104.gif" alt="" width="301" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_74.gif" alt="" width="50" height="12" /></p>
<p>We can verify this is the same perimeter length obtained from <tt>PerimetricComplexity</tt> using <em>Mathematica</em>&#8217;s morphological operators.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Input_105.gif" alt="" width="502" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Watson_Output_75.gif" alt="" width="172" height="12" /></p>
<h3>Acknowledgments</h3>
<p>I thank and blame Denis Pelli for introducing me to perimetric complexity [<a href="#Pelli">5</a>]. I thank Dr. Cong Yu for providing the Chinese character optotypes [<a href="#Zhang">6</a>]. I thank Albert Ahumada and Jeffrey Mulligan for useful discussions. I thank Larry Thibos for providing the wavefront data [<a href="#Thibos">16</a>]. This work was supported by NASA Space Human Factors Engineering WBS 466199.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Attneave">[1] </a></td>
<td>F. Attneave and M. D. Arnoult, &#8220;The Quantitative Study of Shape and Pattern Perception,&#8221; <em>Psychological Bulletin</em>, <strong>53</strong>(6), 1956 pp. 452-471. <a href="http://psycnet.apa.org/journals/bul/53/6/452" target="blank">psycnet.apa.org/journals/bul/53/6/452</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Sankar">[2] </a></td>
<td>P. V. Sankar and E. V. Krishnamurthy, &#8220;On the Compactness of Subsets of Digital Pictures,&#8221; <em>Computer Graphics and Image Processing</em>, <strong>8</strong>(1), 1978 pp. 136-143. <a href="http://www.sciencedirect.com/science/article/pii/S0146664X78800215" target="blank">www.sciencedirect.com/science/article/pii/S0146664X78800215</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ullman">[3] </a></td>
<td>S. Ullman, &#8220;The Visual Analysis of Shape and Form,&#8221; <em>The Cognitive Neurosciences</em> (M. S. Gazzaniga, ed.), Cambridge, MA: MIT Press, 1995 pp. 339-350.</td>
</tr>
<tr>
<td class="Reference"><a name="Montero">[4] </a></td>
<td>R. Montero and E. Bribiesca, &#8220;State of the Art of Compactness and Circularity Measures,&#8221; <em>International Mathematical Forum</em>, <strong>4</strong>(27), 2009 pp. 1305-1335.<br />
<a href="http://www.m-hikari.com/imf-password2009/25-28-2009/index.html" target="blank">www.m-hikari.com/imf-password2009/25-28-2009/index.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Pelli">[5] </a></td>
<td>D. G. Pelli, C. W. Burns, B. Farell, and D. C. Moore-Page, &#8220;Feature Detection and Letter Identification,&#8221; <em>Vision Research</em>, <strong>46</strong>(28), 2006 pp. 4646-4674. <a href="http://www.psych.nyu.edu/pelli/pubs/pelli2006letters.pdf" target="blank">www.psych.nyu.edu/pelli/pubs/pelli2006letters.pdf</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Zhang">[6] </a></td>
<td>J.-Y. Zhang, T. Zhang, F. Xue, L. Liu, and C. Yu, &#8220;Legibility Variations of Chinese Characters and Implications for Visual Acuity Measurement in Chinese Reading Population,&#8221; <em>Investigative Ophthalmology &amp; Visual Science</em>, <strong>48</strong>(5), 2007 pp. 2383-2390. <a href="http://www.iovs.org/content/48/5/2383.short" target="blank">www.iovs.org/content/48/5/2383.short</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Watson">[7] </a></td>
<td>A. B. Watson and A. J. Ahumada, Jr., &#8220;Modeling Acuity for Optotypes Varying in Complexity,&#8221; presentation given at <em>The Association for Research in Vision and Ophthalmology Conference (ARVO 2010)</em>, Ft. Lauderdale, FL. <a href="http://abstracts.iovs.org//cgi/content/abstract/51/5/5174?sid=402a2b61-150a-442b-9a63-5ca9501a95c5" target="blank">abstracts.iovs.org//cgi/content/abstract/51/5/5174</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Rusu">[8] </a></td>
<td>A. Rusu and V. Govindaraju, &#8220;The Influence of Image Complexity on Handwriting Recognition,&#8221; in <em>Proceediings of the Tenth International Workshop on Frontiers in Handwriting Recognition (IWFHR 2006)</em>, La Baule (France). <a href="http://hal.inria.fr/view_by_stamp.php?&amp;halsid=0dklr0o22f897j7vvdc6t7i293&amp;label=IWFHR10&amp;langue=en&amp;action_todo=view&amp;id=inria-00112666&amp;version=1" target="blank">hal.inria.fr/view_by_stamp.php</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Garrod">[9] </a></td>
<td>S. Garrod, N. Fay, J. Lee, J. Oberlander, and T. MacLeod, &#8220;Foundations of Representation: Where Might Graphical Symbol Systems Come From?,&#8221; <em>Cognitive Science</em>, <strong>31</strong>(6), 2007 pp. 961-987. <a href="http://onlinelibrary.wiley.com/doi/10.1080/03640210701703659/abstract" target="blank">onlinelibrary.wiley.com/doi/10.1080/03640210701703659/abstract</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Chew">[10] </a></td>
<td>M. Chew and H. Baird, &#8220;BaffleText: A Human Interactive Proof,&#8221; in <em>Proceedings of the IS&amp;T/SPIE Document Recognition and Retrieval Conference X (DRR X)</em>, Santa Clara, CA, 2003 pp. 305-316. <a href="http://www.imaging.org/IST/store/epub.cfm?abstrid=22585" target="blank">www.imaging.org/IST/store/epub.cfm?abstrid=22585</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Biggio">[11] </a></td>
<td>B. Biggio, G. Fumera, I. Pillai, and F. Roli, &#8220;Image Spam Filtering Using Visual Information,&#8221; in <em>Proceedings of the 14th International Conference on Image Analysis and Processing (ICIAP 2007)</em>, Modena, Italy pp. 105-110. <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4362765" target="blank">ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4362765</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Fumera">[12] </a></td>
<td>G. Fumera, I. Pillai, F. Roli, and B. Biggio, &#8220;Image Spam Filtering Using Textual and Visual Information,&#8221; in <em>Proceedings of the MIT Spam Conference 2007</em>, Cambridge, MA. <a href="http://projects.csail.mit.edu/spamconf/SC2007/MIT_Spam_Conf_2007_Papers.tar.gz" target="blank">projects.csail.mit.edu/spamconf/SC2007/MIT_Spam_Conf _ 2007_Papers.tar.gz</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Courant">[13] </a></td>
<td>R. Courant, <em>Differential and Integral Calculus</em>, Vol. 1, 2nd ed. (E. J. McShane, trans.), London: Blackie &amp; Son Limited, 1937.</td>
</tr>
<tr>
<td class="Reference"><a name="Watson2005">[14] </a></td>
<td>A. B. Watson and A. J. Ahumada, Jr., &#8220;A Standard Model for Foveal Detection of Spatial Contrast,&#8221; <em>Journal of Vision</em>, <strong>5</strong>(9), 2005 pp. 717-740. <a href="http://www.journalofvision.org/content/5/9/6" target="blank">journalofvision.org/5/9/6</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Watson2011">[15] </a></td>
<td>A. B. Watson and A. J. Ahumada, &#8220;Blur Clarified: A Review and Synthesis of Blur Discrimination,&#8221; <em>Journal of Vision</em>, <strong>11</strong>(5), 2011. <a href="http://www.journalofvision.org/content/11/5/10" target="blank">journalofvision.org/11/5/10</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Thibos">[16] </a></td>
<td>L. N. Thibos, X. Hong, A. Bradley, and X. Cheng, &#8220;Statistical Variation of Aberration Structure and Image Quality in a Normal Population of Healthy Eyes,&#8221; <em>Journal of the Optical Society of America A: Optics, Image Science, and Vision</em>, <strong>19</strong>(12), 2002 pp. 2329-2348. <a href="http://www.opticsinfobase.org/abstract.cfm?URI=josaa-19-12-2329" target="blank">www.opticsinfobase.org/abstract.cfm?URI=josaa-19-12-2329</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">A. B. Watson, &#8220;Perimetric Complexity of Binary Digital Images,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-5.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Andrew B. Watson is the Senior Scientist for Vision Research at NASA. He is editor-in-chief of the <em>Journal of Vision</em> (<a href="http://journalofvision.org" target="blank">journalofvision.org</a>). He is the author of over 150 scientific papers and four patents. He is a Fellow of the Optical Society of America, the Association for Research in Vision and Ophthalmology, and the Society for Information Display.</p>
<p class="TextAboutAuthor"><strong>Andrew B. Watson<br />
</strong><em>MS 262-2<br />
NASA Ames Research Center<br />
Moffett Field, CA 94035<br />
</em><em><a href="mailto:andrew.b.watson@nasa.gov">andrew.b.watson@nasa.gov</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/02/perimetric-complexity-of-binary-digital-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Motion of a Spinning Top</title>
		<link>http://www.mathematica-journal.com/2012/02/motion-of-a-spinning-top/</link>
		<comments>http://www.mathematica-journal.com/2012/02/motion-of-a-spinning-top/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 20:46:31 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=22816</guid>
		<description><![CDATA[Both approximate and exact solutions for the motion of a spinning top are constructed with the help of quaternions.
Quaternion Algebra
A quaternion is a four-dimensional quantity consisting of a scalar, say , and a three-dimensional vector , collectively denoted . Addition of two quaternions is component-wise,




(1)



(we do not need to add quaternions in this article). Their [...]]]></description>
			<content:encoded><![CDATA[<p>Both approximate and exact solutions for the motion of a spinning top are constructed with the help of quaternions.<span id="more-22816"></span></p>
<h3>Quaternion Algebra</h3>
<p>A quaternion is a four-dimensional quantity consisting of a scalar, say <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_1.gif" alt="" width="8" height="12" />, and a three-dimensional vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_2.gif" alt="" width="6" height="12" />, collectively denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_3.gif" alt="" width="52" height="12" />. Addition of two quaternions is component-wise,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_1.gif" alt="" width="156" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>(we do not need to add quaternions in this article). Their multiplication follows the rule</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_2.gif" alt="" width="232" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>It is important to note that such multiplication is <em>associative</em> (even though noncommutative). This can be verified by the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_1.gif" alt="" width="474" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_2.gif" alt="" width="434" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_1.gif" alt="" width="89" height="12" /></p>
<p>When the scalar part of a quaternion is zero, it is called a pure quaternion. Since this constitutes an important special case, we will extend our definition of multiplication accordingly.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_3.gif" alt="" width="382" height="12" /></p>
<p>The operation of conjugation simply changes the sign of the vector part of a quaternion.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_4.gif" alt="" width="124" height="15" /></p>
<p>Based on the corresponding Taylor expansion, it is possible to evaluate various functions of a quaternion. Of these, the most important is the exponential function, which, in this article, we need only with pure-quaternion arguments.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_5.gif" alt="" width="471" height="23" /></p>
<h3>Rotation</h3>
<p>Rotating a 3D vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_4.gif" alt="" width="6" height="12" /> with respect to an axis through the origin (with a unit direction of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_5.gif" alt="" width="8" height="14" />) by an angle <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_6.gif" alt="" width="6" height="12" /> can be achieved by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_3.gif" alt="" width="580" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_7.gif" alt="" width="38" height="14" /> (a vector of length <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_8.gif" alt="" width="6" height="12" /> and unit direction <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_9.gif" alt="" width="8" height="14" />), and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_10.gif" alt="" width="11" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_11.gif" alt="" width="13" height="12" /> are the parallel and perpendicular (to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_12.gif" alt="" width="8" height="12" />) parts of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_13.gif" alt="" width="6" height="12" />, respectively [<a href="#Hestenes">1</a>]. Note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_14.gif" alt="" width="11" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_15.gif" alt="" width="8" height="12" /> commute, while <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_16.gif" alt="" width="13" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_17.gif" alt="" width="8" height="12" /> anticommute.</p>
<p>One can show that a quaternion <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_18.gif" alt="" width="9" height="12" /> has the form of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_19.gif" alt="" width="20" height="15" /> if and only if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_20.gif" alt="" width="84" height="15" /> (a pure scalar). Alternately, the same <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_21.gif" alt="" width="9" height="12" /> can be parametrized by the three Euler angles (see the next section).</p>
<p>By taking <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_22.gif" alt="" width="37" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_23.gif" alt="" width="4" height="12" /> is time, we achieve constant rotation with an uniform angular velocity <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_24.gif" alt="" width="9" height="12" />. Note that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_4.gif" alt="" width="59" height="16" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_25.gif" alt="" width="55" height="15" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_26.gif" alt="" width="9" height="16" /> denotes its time derivative.</p>
<p>The previous formula can be generalized to any time-dependent <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_27.gif" alt="" width="9" height="12" />, as can be seen by differentiating <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_28.gif" alt="" width="61" height="15" />, thus</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_5.gif" alt="" width="535" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_29.gif" alt="" width="9" height="12" /> is now the instantaneous angular velocity at time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_30.gif" alt="" width="4" height="12" />, which may change with time. Note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_31.gif" alt="" width="25" height="16" /> must be a pure quaternion (take the time derivative of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_32.gif" alt="" width="45" height="15" /> to see that). Now, any rotation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_33.gif" alt="" width="9" height="12" /> can be applied to the axes of the original (inertial) system of coordinates, thus creating the corresponding new, rotating (noninertial) frame. Components of any vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_34.gif" alt="" width="6" height="12" /> can then be expressed in either the old, or (often and more conveniently) the new coordinates; the latter will be given by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_35.gif" alt="" width="38" height="15" />. The angular velocity <strong><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Omega.gif" alt="" width="8" height="19" /></strong>, in the new coordinates, will thus have components given by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_36.gif" alt="" width="33" height="16" />. This becomes an important and helpful tool: even though the laws of physics are normally valid only in inertial coordinates, the resulting equations often simplify when expressed in the rotating frame.</p>
<h3>Spinning Top</h3>
<p>Let us consider an axially symmetrical body (a &#8220;top&#8221;) of mass <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_37.gif" alt="" width="11" height="12" />, and parallel and perpendicular (with respect to the body&#8217;s symmetry axis) moments of inertia equal to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_38.gif" alt="" width="10" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_39.gif" alt="" width="12" height="12" />, respectively. We make it spin around its axis, place the bottom tip of its (usually tilted) axis on a nonslip horizontal plane (a desk), and let it continue its motion subject to the vertical gravity field. Let us also assume that the top&#8217;s center of mass is at a distance <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_40.gif" alt="" width="5" height="12" /> from its point of contact, that the gravitational acceleration is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_41.gif" alt="" width="6" height="12" />, and that there is no friction.</p>
<p>To investigate the top&#8217;s motion, we introduce an inertial coordinate system with its origin at the point of contact and its <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_42.gif" alt="" width="5" height="12" /> direction pointing vertically upward. First we position a motionless top vertically (its symmetry axis aligned with the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_43.gif" alt="" width="5" height="12" /> direction) on the desk&#8217;s surface. We then rotate it using a fully general, time-dependent rotation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_44.gif" alt="" width="9" height="12" />, parametrized by three Euler angles, thus</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_6.gif" alt="" width="119" height="15" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_45.gif" alt="" width="7" height="12" /> is a rapidly increasing function of time that represents the actual spinning of the top around its symmetry axis (this rotation is applied first), followed by tilting the spinning top by an angle <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_46.gif" alt="" width="5" height="12" /> (potentially a slowly varying function of time) around the inertial <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_47.gif" alt="" width="6" height="12" /> direction, further followed by slowly rotating the spinning, tilted top around the inertial <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_48.gif" alt="" width="5" height="12" /> direction by an angle <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Psi.gif" alt="" width="7" height="19" />, thus creating a so-called precession. Also: <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/DoubleStruckI.gif" alt="" width="4" height="19" />, <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/DoubleStruckJ.gif" alt="" width="5" height="19" /> (not used in the last formula), and <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/DoubleStruckK.gif" alt="" width="7" height="19" /> are unit vectors along the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_49.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_50.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_51.gif" alt="" width="5" height="12" /> directions, respectively, in their pure-quaternion form.</p>
<h4>Equations of Motion</h4>
<p>We now use the Lagrange technique to find the corresponding equations for the three Euler angles. The kinetic energy of the top equals one-half of the scalar product of its angular velocity with its angular momentum, as its motion is purely rotational. In the rotating frame (this is when it becomes handy), this equals</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_7.gif" alt="" width="172" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_52.gif" alt="" width="15" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_53.gif" alt="" width="15" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_54.gif" alt="" width="15" height="14" /> are the rotating-frame coordinates of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_55.gif" alt="" width="8" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_56.gif" alt="" width="48" height="15" /> (denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_57.gif" alt="" width="6" height="12" /> from now on; similarly, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_58.gif" alt="" width="10" height="12" /> will be called <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_59.gif" alt="" width="11" height="12" />) is the top&#8217;s moment of inertia with respect to a line perpendicular to its symmetry axis, and passing through the origin (which is displaced by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_60.gif" alt="" width="5" height="12" /> from its center of mass). Usually <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_61.gif" alt="" width="31" height="12" /> (a thin circular disk needs <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_62.gif" alt="" width="5" height="12" /> to be bigger than only one-half of its radius to meet this condition), but our results are valid when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_63.gif" alt="" width="31" height="12" /> as well.</p>
<p>Subtracting the potential energy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_64.gif" alt="" width="107" height="12" /> (by the definition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_65.gif" alt="" width="9" height="12" />) yields the resulting Lagrangian.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_6.gif" alt="" width="385" height="67" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_2.gif" alt="" width="519" height="31" /></p>
<p>Since the result is free of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_66.gif" alt="" width="7" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_67.gif" alt="" width="7" height="12" /> (it contains only their time derivatives), the corresponding <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_68.gif" alt="" width="14" height="26" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_69.gif" alt="" width="15" height="26" /> must be constants of motion [<a href="#Goldstein">2</a>]. The remaining equation is then obtained from</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_8.gif" alt="" width="79" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>This yields the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_7.gif" alt="" width="303" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_3.gif" alt="" width="174" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_4.gif" alt="" width="369" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_5.gif" alt="" width="527" height="18" /></p>
<p>The first two expressions are constants of motion, while the last one must be equal to zero.</p>
<p>Introducing a new variable <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_70.gif" alt="" width="8" height="12" /> by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_9.gif" alt="" width="127" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>the last three expressions simplify further. It is also important to realize that the transformation (<a href="#eq:9">9</a>) replaces only the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_71.gif" alt="" width="7" height="12" /> parameter (the speed of spinning); if we are interested in the behavior of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_72.gif" alt="" width="7" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_73.gif" alt="" width="5" height="12" /> only (as is usually the case), we get the same solution regardless of whether we use <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_74.gif" alt="" width="7" height="12" /> (in the old set of equations) or <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_75.gif" alt="" width="8" height="12" /> (in the new one).</p>
<p>So, let us see what the new results look like.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_8.gif" alt="" width="480" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_6.gif" alt="" width="144" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_7.gif" alt="" width="144" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_8.gif" alt="" width="278" height="12" /></p>
<p>The equations are now much simpler, and the number of parameters has been reduced from three to only one (namely <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_76.gif" alt="" width="9" height="12" />, whose dimension is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_77.gif" alt="" width="27" height="15" />).</p>
<p>We can now easily infer a possibility of what we call a &#8220;steady&#8221; solution, with a constant value of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_78.gif" alt="" width="5" height="12" /> (say <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_79.gif" alt="" width="11" height="12" />) and</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_10.gif" alt="" width="75" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:10">(10)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_80.gif" alt="" width="14" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_81.gif" alt="" width="13" height="18" /> are two constants whose product must be equal to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_82.gif" alt="" width="9" height="12" />. To relate the precession speed <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_83.gif" alt="" width="13" height="18" /> to the actual spinning speed, say <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_84.gif" alt="" width="13" height="18" />, we have to solve (based on (<a href="#eq:9">9</a>))</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_11.gif" alt="" width="156" height="38" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:11">(11)</a></td>
</tr>
</tbody>
</table>
<p>for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_85.gif" alt="" width="13" height="16" />, which yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_12.gif" alt="" width="237" height="58" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:12">(12)</a></td>
</tr>
</tbody>
</table>
<p>where the negative sign corresponds to the usually observed &#8220;slow&#8221; precession (assuming, from now on, that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_86.gif" alt="" width="33" height="16" />), whereas the positive sign yields a hard-to-achieve &#8220;fast&#8221; precession. When <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_87.gif" alt="" width="31" height="12" /> (spherically symmetrical top), we get only the &#8220;slow&#8221; solution <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_88.gif" alt="" width="42" height="25" />. For a fast-spinning top, the previous formula yields, to a good approximation, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_89.gif" alt="" width="55" height="26" />; the precession speed is practically independent of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_90.gif" alt="" width="11" height="12" />.</p>
<h4>Approximate Solution</h4>
<p>The actual motion is usually more complicated than a steady solution of the previous section, as <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Theta.gif" alt="" width="5" height="19" /> may undergo periodic oscillations, called nutation. Assuming that the amplitude of these is small, we can expand the three dependent variables of our equations around the steady-state solution:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_13.gif" alt="" width="74" height="73" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:13">(13)</a></td>
</tr>
</tbody>
</table>
<p>where the first term of each right-hand side is a constant, the second term remains time dependent, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_91.gif" alt="" width="5" height="12" /> is small. We substitute these into the three equations, neglecting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_92.gif" alt="" width="11" height="15" /> and higher powers of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_93.gif" alt="" width="5" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_9.gif" alt="" width="553" height="57" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_9.gif" alt="" width="567" height="65" /></p>
<p>Each of the three expressions must be equal to zero.</p>
<p>We solve the first two equations for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_94.gif" alt="" width="16" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_95.gif" alt="" width="17" height="12" /> and substitute into the last equation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_10.gif" alt="" width="518" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_10.gif" alt="" width="542" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_11.gif" alt="" width="254" height="41" /></p>
<p>Solving for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_96.gif" alt="" width="11" height="12" /> (and, subsequently, for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_97.gif" alt="" width="13" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_98.gif" alt="" width="14" height="12" />) is now quite easy. Note that the coefficient of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_99.gif" alt="" width="11" height="12" /> in the last expression is always non-negative.</p>
<p>Also note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_100.gif" alt="" width="7" height="16" /> will be always positive (assuming &#8220;slow&#8221; precession), whenever the following condition is met:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_14.gif" alt="" width="116" height="46" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:14">(14)</a></td>
</tr>
</tbody>
</table>
<p>Reversing the above inequality results in so-called looping orbits (in terms of the path of the axis, when displayed on a unit sphere: see below), with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_101.gif" alt="" width="7" height="16" /> periodically changing direction; making the two sides of (<a href="#eq:14">14</a>) equal to each other results in cuspidal orbits (when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_102.gif" alt="" width="5" height="12" /> reaches its smallest value, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_103.gif" alt="" width="7" height="16" /> becomes zero).</p>
<p>If desired, one can extend the approximate solution to achieve <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_104.gif" alt="" width="11" height="15" /> (and higher) accuracy.</p>
<h4>Exact Solution</h4>
<p>One can show that the original differential equation for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_105.gif" alt="" width="5" height="12" />, namely</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_DisplayFormulaNumbered_15.gif" alt="" width="122" height="17" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq:15">(15)</a></td>
</tr>
</tbody>
</table>
<p>has the following constant of motion.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_11.gif" alt="" width="466" height="31" /></p>
<p>This can be easily verified.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_12.gif" alt="" width="580" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_12.gif" alt="" width="278" height="12" /></p>
<p>Making <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_106.gif" alt="" width="21" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_107.gif" alt="" width="21" height="12" /> equal to their initial values, we can solve for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_108.gif" alt="" width="7" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_109.gif" alt="" width="8" height="16" /> and substitute these into <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_110.gif" alt="" width="21" height="12" /> (minus its initial value, so that the resulting expression must be equal to zero).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_13.gif" alt="" width="580" height="71" /></p>
<p>The resulting differential equation can be simplified by the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_111.gif" alt="" width="66" height="12" /> transformation [<a href="#Whittaker">3</a>].</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_14.gif" alt="" width="580" height="88" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_13.gif" alt="" width="413" height="78" /></p>
<p>To simplify the subsequent solution, we have assumed (without loss of generality) that the initial time has been chosen to coincide with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_112.gif" alt="" width="5" height="12" /> reaching its maximum value (and, consequently, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_113.gif" alt="" width="32" height="17" />). The above equation can then be solved, using specific initial conditions, which must satisfy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_114.gif" alt="" width="52" height="18" /> (due to (<a href="#eq:15">15</a>), since <span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Image_2.gif" alt="" width="32" height="17" /></span>); here <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_115.gif" alt="" width="15" height="15" /> provides the solution for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_116.gif" alt="" width="12" height="15" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_15.gif" alt="" width="507" height="129" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_14.gif" alt="" width="332" height="15" /></p>
<p>This can be easily transformed back to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_117.gif" alt="" width="5" height="12" />; one can then find the corresponding <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_118.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_119.gif" alt="" width="7" height="12" /> by analytically integrating the expressions for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_120.gif" alt="" width="7" height="16" /> and (if desired) <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Math_121.gif" alt="" width="8" height="16" />. Finally, the results can be displayed graphically.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Input_16.gif" alt="" width="580" height="162" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Vrbik_Motion_Output_15.gif" alt="" width="360" height="400" /></p>
<p>One can now compute and display the top&#8217;s motion under various initial conditions, check the accuracy of the approximate solution, and so forth. We will leave it for you to explore. Have fun!</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Hestenes">[1] </a></td>
<td>D. Hestenes, <em>New Foundations for Classical Mechanics</em>, 2nd ed., Dordrecht/Boston/London: Kluwer Academic Publishers, 1999.</td>
</tr>
<tr>
<td class="Reference"><a name="Goldstein">[2] </a></td>
<td>H. Goldstein, <em>Classical Mechanics</em>, 2nd ed., Reading, MA: Addison-Wesley, 1980.</td>
</tr>
<tr>
<td class="Reference"><a name="Whittaker">[3] </a></td>
<td>E. T. Whittaker, <em>A Treatise on the Analytical Dynamics of Particles and Rigid Bodies</em>, 2nd ed., Cambridge: Cambridge University Press, 1917. <a href="http://www.archive.org/details/atreatiseonanal00whitgoog" target="blank">www.archive.org/details/atreatiseonanal00whitgoog</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">J. Vrbik, &#8220;Motion of a Spinning Top,&#8221; <em>The Mathematica Journal</em>, 2012.<br />
dx.doi.org/doi:10.3888/tmj.14-4.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor"><strong>Jan Vrbik</strong><br />
<em>Department of Mathematics, Brock University<br />
500 Glenridge Ave., St. Catharines<br />
Ontario, Canada, L2S 3A1<br />
</em><em><a href="mailto:jvrbik@brocku.ca">jvrbik@brocku.ca</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/02/motion-of-a-spinning-top/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evaluation of Gaussian Molecular Integrals</title>
		<link>http://www.mathematica-journal.com/2012/02/evaluation-of-gaussian-molecular-integrals/</link>
		<comments>http://www.mathematica-journal.com/2012/02/evaluation-of-gaussian-molecular-integrals/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 20:45:44 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=22634</guid>
		<description><![CDATA[This article discusses the evaluation of molecular overlap integrals for Gaussian-type functions with arbitrary angular dependence. As an example, we calculate the overlap matrix for the water molecule in the STO-3G basis set.
Introduction
Computational quantum chemistry makes extensive use of various integrals (and their derivatives) of the general form [1, 2, 3]




(1)



where  is an unnormalized [...]]]></description>
			<content:encoded><![CDATA[<p>This article discusses the evaluation of molecular overlap integrals for Gaussian-type functions with arbitrary angular dependence. As an example, we calculate the overlap matrix for the water molecule in the STO-3G basis set.<span id="more-22634"></span></p>
<h3>Introduction</h3>
<p>Computational quantum chemistry makes extensive use of various integrals (and their derivatives) of the general form [<a href="#Szabo">1</a>, <a href="#Helgaker">2</a>, <a href="#Jensen">3</a>]</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_1.gif" alt="" width="105" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.1">(1)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_1.gif" alt="" width="27" height="12" /> is an unnormalized Cartesian Gaussian function centered at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_2.gif" alt="" width="84" height="18" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_2.gif" alt="" width="284" height="23" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.2">(2)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_3.gif" alt="" width="9" height="12" /> is normally taken at the nucleus, <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Alpha.gif" alt="" width="7" height="19" /> is the orbital exponent, and the polynomial represents the angular part, in that the sum of the Cartesian angular momenta <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_4.gif" alt="" width="124" height="14" /> corresponds to functions of type <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_5.gif" alt="" width="5" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_6.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_7.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_8.gif" alt="" width="5" height="12" />, &#8230;. When the operator <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_9.gif" alt="" width="9" height="12" /> is 1, one simply has the overlap/density integral; otherwise it can be the energy operator for kinetic energy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_10.gif" alt="" width="37" height="23" />, electron-nuclear attraction <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_11.gif" alt="" width="50" height="17" />, or electron-electron repulsion <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_12.gif" alt="" width="55" height="17" /> (which would involve double integrals). Other molecular properties involving external fields (response functions) or transition moments can also be computed from integrals of this form.</p>
<h4>Gaussian-Type Functions</h4>
<p>Gaussian-type functions are not the most natural choice for expanding the wavefunction. Slater-type functions, where the exponent is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_13.gif" alt="" width="54" height="14" /> instead, can describe atomic systems more realistically. However, complications quickly arise in molecular calculations, which has led to the use of Gaussian functions in the overwhelming majority of current computational programs. Gaussian functions possess several desirable computational properties [<a href="#Shavitt">4</a>, <a href="#SFBoys">5</a>, <a href="#Taketa">6</a>]. (Much credit is due to S. F. Boys for the introduction of the Cartesian Gaussian function into computational chemistry and its early development in a series of 12 papers under the general title &#8220;Electronic Wavefunctions,&#8221; the first being [<a href="#SFBoys">5</a>].) A given Slater function can be approximated by a linear combination of several Gaussians.</p>
<p>The first useful property is that the product of two Gaussian functions located at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_14.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_15.gif" alt="" width="8" height="12" /> is another Gaussian located at a point <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_16.gif" alt="" width="7" height="12" /> somewhere between <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_17.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_18.gif" alt="" width="8" height="12" />. (The proof of this can be found in [<a href="#Shavitt">4</a>].) The product of two Gaussians <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_19.gif" alt="" width="69" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_20.gif" alt="" width="71" height="12" /> is:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_3.gif" alt="" width="580" height="22" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.3">(3)</a></td>
</tr>
</tbody>
</table>
<p>with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_21.gif" alt="" width="94" height="26" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_22.gif" alt="" width="59" height="25" />.</p>
<p>A second desirable property is that a derivative of a Gaussian can be expressed as a sum of Gaussians of lower and higher Cartesian angular values.</p>
<h3>Overlap Integrals</h3>
<p>The simplest molecular integral is the overlap integral <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_23.gif" alt="" width="208" height="18" />. We first separate the integral into its orthogonal components:</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_1.gif" alt="" width="194" height="18" /></p>
<p>where the notation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_24.gif" alt="" width="48" height="12" /> expresses its functional dependence on the Cartesian angular components. The <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_25.gif" alt="" width="6" height="12" /> component, for instance, is:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_4.gif" alt="" width="273" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.4">(4)</a></td>
</tr>
</tbody>
</table>
<p>Using a binomial expansion in the polynomial part,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_2.gif" alt="" width="418" height="43" /></p>
<p>yields:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_5.gif" alt="" width="477" height="43" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.5">(5)</a></td>
</tr>
</tbody>
</table>
<p>Odd values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_26.gif" alt="" width="30" height="12" /> result in odd functions whose integrals vanish. For even values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_27.gif" alt="" width="30" height="12" />, a solution [<a href="#Abramowitz">7</a>] for the integrals is given by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_28.gif" alt="" width="121" height="27" />, and, in those cases:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_6.gif" alt="" width="447" height="51" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.6">(6)</a></td>
</tr>
</tbody>
</table>
<p>We keep in mind that for the summations only terms of even values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_29.gif" alt="" width="30" height="12" /> survive. We have thus obtained an expression to evaluate the overlap of two Gaussians with arbitrary Cartesian angular factors. Equation (<a href="#Eq.6">6</a>) should be sufficient for programming or even for manual evaluation with small Cartesian angular values. One can, however, further reduce the number of operations by using a recurrence relation, one of the most useful techniques of computational chemistry. Recurrence relations let us efficiently calculate molecular integrations of higher angular values using previously obtained results with lower angular values. Recurrence relations are used in most computational chemistry programs and their application to other molecular integrations will be shown here.</p>
<h4>Recurrence Relations</h4>
<p>The derivation of the following relations involves straightforward algebraic manipulations, but is rather lengthy. Its omission does not impede our understanding of the recurrence relation, but helps maintain a reasonable continuity in our discussion. Interested readers can find a detailed derivation in the Appendix.</p>
<p>We start by defining the function</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_3.gif" alt="" width="161" height="51" /></p>
<p>where we have removed the factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_30.gif" alt="" width="64" height="23" /> from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_31.gif" alt="" width="48" height="12" /> in (<a href="#Eq.6">6</a>). If we take the derivative of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_32.gif" alt="" width="49" height="12" />with respect to the nuclear coordinate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_33.gif" alt="" width="13" height="12" /> using the definition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_34.gif" alt="" width="48" height="12" /> in equation (<a href="#Eq.4">4</a>),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_7.gif" alt="" width="580" height="51" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.7">(7)</a></td>
</tr>
</tbody>
</table>
<p>and combining the result with the same derivative of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_35.gif" alt="" width="47" height="12" />, but using the definition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_36.gif" alt="" width="48" height="12" /> in equation (<a href="#Eq.6">6</a>) instead,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_8.gif" alt="" width="580" height="85" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.8">(8)</a></td>
</tr>
</tbody>
</table>
<p>we obtain</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_9.gif" alt="" width="443" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.9">(9)</a></td>
</tr>
</tbody>
</table>
<p>The same approach in which we combine the derivatives of (<a href="#Eq.4">4</a>) and (<a href="#Eq.6">6</a>) with respect to the nuclear coordinate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_37.gif" alt="" width="12" height="12" /> gives</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_10.gif" alt="" width="440" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.10">(10)</a></td>
</tr>
</tbody>
</table>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_38.gif" alt="" width="31" height="12" />, we have the index recursion relation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_11.gif" alt="" width="296" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.11">(11)</a></td>
</tr>
</tbody>
</table>
<p>and combining equations (<a href="#Eq.7">7</a>) and (<a href="#Eq.8">8</a>) yields the transfer equation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_12.gif" alt="" width="261" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.12">(12)</a></td>
</tr>
</tbody>
</table>
<p>Starting with the initial values <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_39.gif" alt="" width="57" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_40.gif" alt="" width="105" height="12" />, the recurrence relation and the transfer equation, we can build up the overlap of functions of higher Cartesian angular values from lower ones. This is particularly useful for contracted Gaussian basis primitives with different functions sharing the same exponent.</p>
<h4>Implementation</h4>
<p>The function <tt>Ov</tt> evaluates the overlap integral of two Gaussian functions; here <tt>alpha</tt>, <tt>beta</tt>, <tt>RA</tt>, <tt>RB</tt>, <tt>LA</tt>, and <tt>LB</tt> are <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_41.gif" alt="" width="7" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_42.gif" alt="" width="7" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_43.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_44.gif" alt="" width="8" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_45.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_46.gif" alt="" width="7" height="12" /> as defined earlier.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_4.gif" alt="" width="580" height="358" /></p>
<h3>Examples</h3>
<p>The published contracted Gaussian basis sets (see, for example, [<a href="#Ref:8">8</a>]) are usually not normalized; in our first example, we will calculate the normalization factor of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_47.gif" alt="" width="5" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_48.gif" alt="" width="6" height="12" /> Cartesian Gaussian functions that we will need later on. The normalization factor is simply the inverse square root of the overlap integral. Here we calculate the overlap between two <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_49.gif" alt="" width="5" height="12" /> functions with the Cartesian angular vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_50.gif" alt="" width="60" height="12" />,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_5.gif" alt="" width="277" height="30" /></p>
<p>and observe that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_51.gif" alt="" width="196" height="14" />. The normalization factor for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_52.gif" alt="" width="11" height="12" /> functions is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_53.gif" alt="" width="109" height="24" />. Similarly, the overlap between two <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_54.gif" alt="" width="11" height="12" /> functions (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_55.gif" alt="" width="60" height="12" />) is</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_6.gif" alt="" width="422" height="32" /></p>
<p>where we have analogously used the recurrence relations to obtain <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_56.gif" alt="" width="37" height="12" /> and afterward, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_57.gif" alt="" width="37" height="12" />. Similar results are obtained for <span><img style="vertical-align: middle;" title="S_(p_y)" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Image_1.gif" alt="S_(p_y)" width="17" height="17" /></span> and <span><img style="vertical-align: middle;" title="S_(p_z)" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Image_3.gif" alt="S_(p_z)" width="17" height="16" /></span>. The normalization factor for the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_58.gif" alt="" width="6" height="12" /> function is then <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_59.gif" alt="" width="76" height="19" />. These results are special cases of the more general formula of the normalization factor</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_7.gif" alt="" width="291" height="45" /></p>
<p>and we note that this value depends only on the orbital exponent and the Cartesian angular values.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_8.gif" alt="" width="556" height="38" /></p>
<p>In the second example, we will calculate the overlap matrix of the water molecule (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_60.gif" alt="" width="96" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_61.gif" alt="" width="92" height="12" />, geometry optimized at the HF/STO-3G level). The molecule lies in the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_62.gif" alt="" width="6" height="12" />-<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_63.gif" alt="" width="5" height="12" /> plane with Cartesian coordinates in atomic units.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_9.gif" alt="" width="245" height="43" /></p>
<p>In the STO-3G basis set, each atomic orbital is described by a sum of three Gaussians; here are their primitive contraction coefficients and orbital exponents (taken from [<a href="#Ref:8">8</a>]).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_10.gif" alt="" width="392" height="223" /></p>
<p>Here are the centers and Cartesian angular values of the orbitals, in the following order: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_64.gif" alt="" width="19" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_65.gif" alt="" width="19" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_66.gif" alt="" width="19" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_67.gif" alt="" width="19" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_68.gif" alt="" width="25" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_69.gif" alt="" width="25" height="17" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_70.gif" alt="" width="25" height="16" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_11.gif" alt="" width="449" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_12.gif" alt="" width="344" height="28" /></p>
<p>For instance, the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_71.gif" alt="" width="5" height="12" /> atomic orbital of the hydrogen atom 1 is described as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_13.gif" alt="" width="544" height="65" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.13">(13)</a></td>
</tr>
</tbody>
</table>
<p>Similarly, the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_72.gif" alt="" width="11" height="12" /> orbital of the oxygen atom is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormulaNumbered_14.gif" alt="" width="380" height="66" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.14">(14)</a></td>
</tr>
</tbody>
</table>
<p>The overlap integral between the two orbitals expands to nine integrals involving the primitives. Using the function <tt>Ov</tt>, for example, the overlap integral between the first two primitives of equations (<a href="#Eq.13">13</a>) and (<a href="#Eq.14">14</a>) is</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_13.gif" alt="" width="531" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_14.gif" alt="" width="388" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Output_1.gif" alt="" width="94" height="12" /></p>
<p>And the overlap between <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_73.gif" alt="" width="26" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_74.gif" alt="" width="26" height="12" /> is</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_15.gif" alt="" width="132" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_16.gif" alt="" width="313" height="163" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Output_2.gif" alt="" width="66" height="12" /></p>
<p>The overlap matrix <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_75.gif" alt="" width="7" height="12" /> for the entire water molecule in the STO-3G basis set can be calculated in a similar manner.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_17.gif" alt="" width="390" height="163" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Output_3.gif" alt="" width="469" height="110" /></p>
<p>Since the overlap matrix is symmetrical, we need to calculate only the elements above the main diagonal. The basis functions are normalized, as indicated by the unit diagonal elements. We note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_76.gif" alt="" width="16" height="12" /> equals zero. This is the overlap between the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_77.gif" alt="" width="11" height="12" /> orbital of the first hydrogen atom and the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_78.gif" alt="" width="17" height="12" /> of the oxygen atom. The molecule lies in the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_79.gif" alt="" width="6" height="12" />-<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_80.gif" alt="" width="5" height="12" /> plane, so this overlap vanishes due to symmetry. Similar cases occur in the overlaps between the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_81.gif" alt="" width="5" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_82.gif" alt="" width="6" height="12" /> orbitals of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_83.gif" alt="" width="9" height="12" /> (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_84.gif" alt="" width="81" height="12" />) and among the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_85.gif" alt="" width="12" height="12" /> orbitals (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_86.gif" alt="" width="62" height="12" />), etc. The strongest overlaps are those between the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_87.gif" alt="" width="11" height="12" /> hydrogen orbitals and the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_88.gif" alt="" width="11" height="12" /> oxygen orbital.</p>
<p>We next plot the atomic-orbital overlap between <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_89.gif" alt="" width="11" height="12" /> of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_90.gif" alt="" width="15" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_91.gif" alt="" width="17" height="12" /> of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_92.gif" alt="" width="9" height="12" />,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_18.gif" alt="" width="276" height="40" /></p>
<p>in the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_93.gif" alt="" width="6" height="12" />-<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_94.gif" alt="" width="5" height="12" /> plane, superimposing the molecule structure.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_19.gif" alt="" width="305" height="118" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_20.gif" alt="" width="580" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_21.gif" alt="" width="410" height="58" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Input_22.gif" alt="" width="155" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Output_4.gif" alt="" width="360" height="360" /></p>
<p>We observe a strong distortion of the positive (lower) lobe of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_95.gif" alt="" width="17" height="12" /> function toward the hydrogen atom. The negative lobe shows less deformation, whereas the node remains precisely at the atomic position. Note that this is simply the orbital overlap between noninteracting atoms, such as in the case of the &#8220;promolecule.&#8221;</p>
<h3>Conclusion</h3>
<p>We have provided an introduction to the evaluation of molecular integrals involving Gaussian-type basis functions both analytically and by use of recurrence relations. The results are general and relatively straightforward; the simple algorithm makes it suitable for implementation in a number of programming languages. Together with the kinetic, nuclear-electron attraction, and electron-electron repulsion energies, this is the first step toward the calculation of molecular energies and electronic properties.</p>
<h3>Appendix<span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Image_5.gif" alt="" width="5" height="16" /></span></h3>
<p>Here we provide the derivation of equations (<a href="#Eq.7">7</a>) and (<a href="#Eq.8">8</a>). Differentiate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_96.gif" alt="" width="47" height="12" /> using equation (<a href="#Eq.5">5</a>) with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_97.gif" alt="" width="13" height="12" />:</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_23.gif" alt="" width="371" height="51" /></p>
<p>Consider the derivative term</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_24.gif" alt="" width="565" height="35" /></p>
<p>the first term is simply</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_25.gif" alt="" width="165" height="19" /></p>
<p>and, using the chain rule, the derivative of the second term is</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_26.gif" alt="" width="509" height="36" /></p>
<p>recalling that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_98.gif" alt="" width="131" height="12" />. Substitute the results into the expression for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_99.gif" alt="" width="82" height="12" />,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_27.gif" alt="" width="578" height="51" /></p>
<p>Writing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_100.gif" alt="" width="140" height="12" /> in the second term inside the bracket, after expanding we have</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_28.gif" alt="" width="580" height="111" /></p>
<p>Comparing the three integrals with the definitions of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_101.gif" alt="" width="47" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_102.gif" alt="" width="48" height="12" /> we have the desired equation (<a href="#Eq.7">7</a>).</p>
<p>To derive equation (<a href="#Eq.8">8</a>), we differentiate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_103.gif" alt="" width="47" height="12" /> with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_Math_104.gif" alt="" width="13" height="12" /> using equation (<a href="#Eq.6">6</a>) instead,</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_29.gif" alt="" width="580" height="282" /></p>
<p>We make use of the relationship</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_30.gif" alt="" width="343" height="34" /></p>
<p>to reduce the derivative above to</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/01/Ho_DisplayFormula_31.gif" alt="" width="465" height="178" /></p>
<p>This is equation (<a href="#Eq.8">8</a>), which is what was needed to prove.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Szabo">[1] </a></td>
<td>A. Szabo and N. Ostlund, <em>Modern Quantum Chemistry: Introduction to Advanced Electronic Structure Theory</em>, New York: Dover, 1996.</td>
</tr>
<tr>
<td class="Reference"><a name="Helgaker">[2] </a></td>
<td>T. Helgaker, P. Jørgensen, and J. Olsen, <em>Molecular Electronic-Structure Theory</em>, New York: Wiley, 2000.</td>
</tr>
<tr>
<td class="Reference"><a name="Jensen">[3] </a></td>
<td>F. Jensen, <em>Introduction to Computational Chemistry</em>, New York: Wiley, 1999.</td>
</tr>
<tr>
<td class="Reference"><a name="Shavitt">[4] </a></td>
<td>I. Shavitt, &#8220;The Gaussian Function in Calculations of Quantum Mechanics,&#8221; in <em>Methods in Computational Physics</em>, Vol. 2, B. Alder, S. Fernbach, and M. Rotenberg, eds., New York: Academic Press, 1963 pp. 1-45.</td>
</tr>
<tr>
<td class="Reference"><a name="SFBoys">[5] </a></td>
<td>S. F. Boys, &#8220;A General Method of Calculation for Stationary States of Any Molecular System,&#8221; <em>Proceedings of the Royal Society A</em>, <strong>200</strong>, 1950 pp. 542-554. <a href="http://rspa.royalsocietypublishing.org/content/200/1063/542.abstract" target="blank">rspa.royalsocietypublishing.org/content/200/1063/542.abstract</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Taketa">[6] </a></td>
<td>H. Taketa, S. Huzinaga, and K. O-ohata, &#8220;Gaussian-Expansion Methods for Molecular Integrals,&#8221; <em>Journal of the Physical Society of Japan</em>, <strong>21</strong>, 1966 pp. 2313-2324.</td>
</tr>
<tr>
<td class="Reference"><a name="Abramowitz">[7] </a></td>
<td>M. Abramowitz and I. A. Stegun, <em>Handbook of Mathematical Functions with Formulas</em>, <em>Graphs</em>, <em>and Mathematical Tables</em>, New York: Dover, 1965, Eq. (7.4.4) p. 302.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref:8">[8] </a></td>
<td>&#8220;Basis Set Exchange.&#8221; (Sep 13, 2011) <a href="https://bse.pnl.gov/bse/portal" target="blank">bse.pnl.gov/bse/portal</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">M. Hô and J. M. Hernández-Pérez, &#8220;Evaluation of Gaussian Molecular Integrals,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-3.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Authors</h3>
<p class="TextAboutAuthor">Minhhuy Hô received his Ph.D. in theoretical chemistry at Queen&#8217;s University, Kingston, Ontario, Canada in 1998. He is currently a professor at the Centro de Investigaciones Químicas at the Universidad Autónoma del Estado de Morelos in Cuernavaca, Morelos, México.</p>
<p class="TextAboutAuthor">Julio-Manuel Hernández-Pérez obtained his Ph.D. at the Universidad Autónoma del Estado de Morelos in 2008. He has been a professor of chemistry at the Facultad de Ciencias Químicas at the Benemérita Universidad Autónoma de Puebla since 2010.</p>
<p class="TextAboutAuthor"><strong>Minhhuy Hô</strong><br />
<em>Universidad Autónoma del Estado de Morelos<br />
Centro de Investigaciones Químicas<br />
Ave</em>. <em>Universidad</em>, <em>No</em>. <em>1001</em>, <em>Col</em>. <em>Chamilpa<br />
Cuernavaca</em>, <em>Morelos</em>, <em>Mexico CP 92010<br />
</em><em><a href="mailto:homh@uaem.mx">homh@uaem.mx</a></em></p>
<p class="TextAboutAuthor"><strong>Julio-Manuel Hernández-Pérez<br />
</strong><em>Benemérita Universidad Autónoma de Puebla<br />
Facultad de Ciencias Químicas<br />
Ciudad Universitaria</em>, <em>Col</em>. <em>San Manuel<br />
Puebla</em>, <em>Puebla</em>, <em>Mexico CP 72570<br />
</em><em><a href="mailto:jumahernandez@gmail.com">jumahernandez@gmail.com</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/02/evaluation-of-gaussian-molecular-integrals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Return of the Riemann Surface</title>
		<link>http://www.mathematica-journal.com/2012/02/the-return-of-the-riemann-surface/</link>
		<comments>http://www.mathematica-journal.com/2012/02/the-return-of-the-riemann-surface/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 00:16:34 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 10, Issue 4]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=17814</guid>
		<description><![CDATA[My favorite subject&#8212;Riemann surfaces&#8212;is revisited through the eyes (functions) of Mathematica 6. Old friends will appear in a new light(ing) and new acquaintances with untreated surfaces will be made.
Introduction
This is my first column since Version 6 came out a few months ago. Version 6, after being in the works for many years, provides a wealth [...]]]></description>
			<content:encoded><![CDATA[<p>My favorite subject&#8212;Riemann surfaces&#8212;is revisited through the eyes (functions) of <em>Mathematica</em> 6. Old friends will appear in a new light(ing) and new acquaintances with untreated surfaces will be made.<span id="more-17814"></span></p>
<h3>Introduction</h3>
<p>This is my first column since Version 6 came out a few months ago. Version 6, after being in the works for many years, provides a wealth of new features that are useful in many numeric and symbolic calculations, advanced programs, visualizations, and elsewhere. With so many exciting new possibilities, it was not easy to decide what to discuss in this column. So instead of delving into a new subject, I think the best way to see some of the new features and resulting capabilities of Version 6 is to compare with some corresponding Version 5 results. That is why today I will come back to a subject discussed in earlier columns and demonstrate how to go quite a bit further with Version 6.</p>
<p>In earlier columns, I started discussing the visualization of Riemann surfaces. In this column, I want to come back to this mathematically (and aesthetically) beautiful subject. So far, we discussed the construction of Riemann surfaces of compositions of elementary functions with finitely many branch points (articles IIa to IId [<a href="#IIa">1</a>-<a href="#IId">4</a>]). With the new 3D graphics system and interactive features of Version 6, new possibilities open up for visualizing Riemann surfaces; the main ones are:</p>
<ul>
<li>Specifying vertex normals to obtain smooth-looking surfaces</li>
<li>Using opacity to get a better look &#8220;inside&#8221; a Riemann surface (instead of cutting holes in the polygons of the surface)</li>
<li>Using adaptive refinement of the built-in graphics functions to better resolve branch points</li>
<li>Using <tt>Manipulate</tt> to easily view a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_1.gif" alt="" width="55" height="12" /> as a 3D projection of the hypersurface <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_2.gif" alt="" width="85" height="15" /> (where showing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_3.gif" alt="" width="42" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_4.gif" alt="" width="42" height="12" /> over the complex plane become special cases)</li>
<li>Using the <tt>Exclusions</tt> option to avoid branch cuts in <tt>Plot3D</tt>, <tt>ParametricPlot3D</tt>, and others</li>
</ul>
<p>These features offer a fresh look at the topic of Riemann surfaces (so, if numbered, this would be article IIdII, not yet IIe, which will appear later and deal with special functions).</p>
<p>Starting with this column, I will also introduce a formatting change: <em>Mathematica</em>&#8217;s default <tt>StandardForm</tt> is an ideal editing and reading environment for mathematical expressions and very small program snippets (one to two lines). Convenient automatic line breaking, two-dimensional fraction and radical formatting, and other features make writing and reading easy. But for multiline program-like code pieces, the formatted results are frequently less readable than manually formatting the code to avoid unexpected line breaks, alignments, and nonuniform line spacings. A new style in Version 6 (available as <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/AltKey.gif" alt="" width="14" height="18" />-8) is the <tt>"Code"</tt> style. It is the default style for packages (the canonical place to store a program) and can, of course, also be used in notebooks. It does not automatically break lines, but allows for special characters and inherits the new syntax coloring feature to maximize code readability. So, function definitions are given in <tt>"Code"</tt> style (easily identifiable in this notebook by its light blue background) and example uses of the defined functions will be in style <tt>"Input"</tt>. In addition to an easier visual discrimination between actual definitions and example uses, this also allows for a quick selection of all definitions (using RIGHT<img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/KeyBar.gif" alt="" width="1" height="18" /><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/AltKey.gif" alt="" width="14" height="18" />) for immediate use without having to run all (sometimes time-consuming) examples to experiment with further Riemann surfaces.</p>
<h3>The Updated Riemann Surface Package</h3>
<p>We start with an updated version of the construction discussed in my earlier columns. Let us quickly recap the construction idea: Starting with a given function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_5.gif" alt="" width="55" height="12" />, a set of coupled nonlinear meromorphic differential equations is derived from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_6.gif" alt="" width="20" height="12" /> and this set is solved on patches of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_7.gif" alt="" width="5" height="12" /> plane. These patches arise from a tensor product decomposition of the complex plane in a cylindrical coordinate system and are separated by branch points. The system of differential equations is solved numerically and the resulting function values are displayed. If at the same time we calculate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_8.gif" alt="" width="24" height="14" />, it is possible to construct the normals to obtain a smooth-looking surface. (Calculating the normals of the 3D embedding of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_9.gif" alt="" width="40" height="12" /> can be done easily using the Cauchy-Riemann conditions.) An updated version of the package, based on the code from <em>The Mathematica GuideBook for Numerics</em> [<a href="#GuideBook">5</a>], is available on the <em>Mathematica</em> <em>GuideBooks</em> website (<a href="http://www.mathematicaguidebooks.org/V6/downloads/RiemannSurfacePlot3D.m">www.mathematicaguidebooks.org/V6/downloads/RiemannSurfacePlot3D.m</a>).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_1.gif" alt="" width="580" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_2.gif" alt="" width="540" height="58" /></p>
<p>This is the main function defined in the package.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_3.gif" alt="" width="153" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Print_4.gif" alt="" width="580" height="73" /></p>
<p>The first example is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_10.gif" alt="" width="54" height="15" /> displayed as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_11.gif" alt="" width="29" height="12" /> over the complex <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_12.gif" alt="" width="5" height="12" /> plane.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_5.gif" alt="" width="519" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_1.gif" alt="" width="244" height="244" /></p>
<p>The function has a few new options in addition to the built-in 3D graphics options.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_6.gif" alt="" width="444" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_2.gif" alt="" width="580" height="89" /></p>
<p>Because 3D graphics in Version 6 are typically no longer made from individual polygons, but rather from <tt>GraphicsComplex</tt> objects that contain polygons and their adjacency information, it is possible to avoid the small gaps that were used in Version 5 between the patches. The function <tt>StitchPatches</tt> &#8220;stitches&#8221; the <tt>GraphicsComplex</tt> objects together along their boundaries. While in static images, the small (typically 1ppm or smaller) gaps are usually not visible; when interactively rotating graphics, such gaps can potentially become more pronounced.</p>
<p>Note that we do not have to specify a domain of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_13.gif" alt="" width="5" height="12" /> plane over which to plot the function. The domain is chosen automatically in such a way to include all finite branch points of the function.</p>
<p>Here is another example of a Riemann surface plotted with <tt>RiemannSurfacePlot3D</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_7.gif" alt="" width="525" height="38" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_3.gif" alt="" width="244" height="244" /></p>
<p>In the next example, we display the imaginary part of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_14.gif" alt="" width="52" height="18" /> over the complex plane and color the surface according to the real part.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_8.gif" alt="" width="519" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_4.gif" alt="" width="244" height="244" /></p>
<p>Using a transparent surface makes it easier to see the inner parts of more complicated Riemann surfaces.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_9.gif" alt="" width="499" height="39" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_5.gif" alt="" width="244" height="244" /></p>
<p>Here are some more examples.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_10.gif" alt="" width="510" height="38" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_6.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_11.gif" alt="" width="524" height="38" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_7.gif" alt="" width="244" height="244" /></p>
<p><tt>RiemannSurfacePlot3D</tt> stores some intermediate time-consuming results for the function it has just plotted. As a result, once a function is plotted, calls to <tt>RiemannSurfacePlot3D</tt> with an identical first argument and mostly identical option settings, but a potentially different second argument, are generally quite fast.</p>
<p>Here is a demonstration that allows moving smoothly from the real to the imaginary part.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_12.gif" alt="" width="538" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_8.gif" alt="" width="245" height="122" /></p>
<p>By parametrizing the three Cartesian coordinates as a linear form of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_15.gif" alt="" width="26" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_16.gif" alt="" width="26" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_17.gif" alt="" width="29" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_18.gif" alt="" width="29" height="12" />, we can implement an even more general view of the surface. We do this through a <tt>Manipulate</tt> object that makes it easy to change any of the 12 parameters that define the actual function value that is plotted.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_13.gif" alt="" width="580" height="193" /></p>
<p>We give two examples: the first algebraic and the second inverse trigonometric.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_14.gif" alt="" width="207" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_9.gif" alt="" width="375" height="359" /></p>
<p>Here is the inverse trigonometric function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_15.gif" alt="" width="500" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_10.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_16.gif" alt="" width="198" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_11.gif" alt="" width="375" height="359" /></p>
<p>For details of the construction, see the package. Within the new package editor of Version 6, it is quite convenient and straightforward to experiment. Input cells are kept in the package and are easily evaluated; comments and examples can be easily embedded, but are invisible when the package is loaded. When developing or investigating package code with the package editor, we do not have to worry about contexts or saving outputs.</p>
<p><tt>RiemannSurfacePlot3D</tt> fails for functions with infinitely many branch points. Here is an example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_17.gif" alt="" width="351" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_12.gif" alt="" width="344" height="20" /></p>
<p>The construction given next deals with functions having infinitely many branch points.</p>
<h3>The New ContourPlot3D</h3>
<p><tt>ContourPlot3D</tt>, a package function in Version 5, is now a much faster built-in kernel function. This function comes in handy sometimes for polynomials dealing with Riemann surfaces. Here is a simple example that uses <tt>ContourPlot3D</tt> to display the real part of the functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_19.gif" alt="" width="108" height="19" /> defined implicitly through a bivariate polynomial.</p>
<p>Eliminating <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_20.gif" alt="" width="29" height="12" /> yields a (more complicated) trivariate polynomial that can be plotted.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_18.gif" alt="" width="473" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_13.gif" alt="" width="255" height="18" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_19.gif" alt="" width="231" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_14.gif" alt="" width="501" height="34" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_20.gif" alt="" width="577" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_15.gif" alt="" width="244" height="244" /></p>
<h3>Using the Exclusions Options</h3>
<p>Now we will use new features of <tt>Plot3D</tt> and <tt>ParametricPlot3D</tt> to construct a Riemann surface. Using these 3D plotting functions on a function that has branch cuts, we now automatically get cuts along the branch cuts.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_21.gif" alt="" width="580" height="19" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_16.gif" alt="" width="244" height="244" /></p>
<p>Modulo the mesh, in Version 5, we would have gotten a graphic similar to the following, much less appealing (but still correct) image.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_22.gif" alt="" width="580" height="39" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_17.gif" alt="" width="244" height="244" /></p>
<p>We can also obtain descriptions of the excluded cuts using the function <tt>VisualizationDiscontinuities</tt> from the context <tt>Visualization`</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_23.gif" alt="" width="468" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_18.gif" alt="" width="262" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_24.gif" alt="" width="461" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_19.gif" alt="" width="262" height="12" /></p>
<p>This neat feature of plotting functions that recognize branch cuts can be used to construct Riemann surfaces by finding parametrizations of all sheets and then plotting them. Instead of the steep vertical walls in earlier versions of <em>Mathematica</em>, we now get small cuts between the sheet patches. The analytic continuation of the logarithm and the power function are straightforward to define through adding multiples of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_21.gif" alt="" width="19" height="12" /> and multiplication by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_22.gif" alt="" width="58" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_25.gif" alt="" width="550" height="159" /></p>
<p>For the logarithm, with its infinitely many sheets, we restrict ourselves to (typically) three sheets.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_26.gif" alt="" width="533" height="37" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_27.gif" alt="" width="486" height="181" /></p>
<p>This list can be easily extended to elliptic integrals, Bessel functions, polylogarithms, and others.</p>
<p>The function <tt>makeSheetList</tt> generates a list of the analytically continued sheets of a multivalued function by forming the outer product of all sheets of all the multivalued functions that occur.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_28.gif" alt="" width="505" height="146" /></p>
<p>Here is an example. The function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_23.gif" alt="" width="137" height="20" /> results in six parametrized sheets: three from the outer logarithm combined with two from the inner square root.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_29.gif" alt="" width="496" height="24" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_20.gif" alt="" width="551" height="42" /></p>
<p>Here is a quick view on the branch cut structure of these six functions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_30.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_21.gif" alt="" width="469" height="320" /></p>
<p>And here are the real and imaginary parts of the six sheets shown as 3D plots.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_31.gif" alt="" width="580" height="37" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_22.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_32.gif" alt="" width="580" height="37" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_23.gif" alt="" width="244" height="244" /></p>
<p>Emphasizing the cuts and making the surface transparent gives an even better looking graphic.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_33.gif" alt="" width="580" height="49" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_24.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_34.gif" alt="" width="580" height="49" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_25.gif" alt="" width="244" height="244" /></p>
<p>As a second example, we use <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_24.gif" alt="" width="129" height="24" />. This time we have five sheets, all arising from the topmost fifth root.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_35.gif" alt="" width="476" height="19" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_26.gif" alt="" width="473" height="63" /></p>
<p>Here is a plot of the real part over the complex plane.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_36.gif" alt="" width="580" height="37" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_27.gif" alt="" width="244" height="244" /></p>
<p>The function <tt>RiemannSheetParametricPlot3D</tt> combines the sheet generation and plotting results. All sheets are included in the first argument of <tt>ParametricPlot3D</tt>, instead of making multiple calls to it. This has the advantage of getting better visual results because the optimal plot range will be calculated by taking all sheets into account.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_37.gif" alt="" width="526" height="134" /></p>
<p>Here are two examples of this function in action: one algebraic and the other a transcendental function containing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_25.gif" alt="" width="10" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_38.gif" alt="" width="566" height="45" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_28.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_39.gif" alt="" width="522" height="64" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_29.gif" alt="" width="244" height="244" /></p>
<p>Using <tt>RiemannSheetParametricPlot3D</tt>, we can now plot the Riemann surface of the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_26.gif" alt="" width="70" height="15" /> that failed earlier. We emphasize the vertical connection along the branch cuts through red polygons.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_40.gif" alt="" width="497" height="57" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_30.gif" alt="" width="244" height="244" /></p>
<p>And here are four considerably more complicated examples. Because of the infinite number of branch points, the function <tt>RiemannSurfacePlot3D</tt> cannot handle them.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_41.gif" alt="" width="580" height="74" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_31.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_42.gif" alt="" width="580" height="69" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_32.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_43.gif" alt="" width="556" height="83" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_33.gif" alt="" width="244" height="244" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_44.gif" alt="" width="580" height="67" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_34.gif" alt="" width="244" height="244" /></p>
<p>We generalize <tt>RiemannSheetParametricPlot3D</tt> to allow for a matrix as its second argument.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_45.gif" alt="" width="526" height="145" /></p>
<p>In effect, the next graphic shows <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_27.gif" alt="" width="67" height="12" /> over the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_28.gif" alt="" width="64" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_29.gif" alt="" width="70" height="12" /> plane.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_46.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_35.gif" alt="" width="244" height="244" /></p>
<p>To summarize: Using analytically continued sheets and <tt>Plot3D</tt>/<tt>ParametricPlot3D</tt> with the <tt>Exclusions</tt> option lets you plot Riemann surfaces of compositions of elementary functions. This includes cases where the branch points cannot be calculated in closed form or the case of countably many branch points. Two potential disadvantages of this approach are that calculating the exclusions can be potentially very time consuming and the gaps arising from cutting out thin strips along potential branch cuts cannot be made arbitrarily small with reasonable computational effort.</p>
<h3>Higher-Order Polynomial Roots</h3>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_47.gif" alt="" width="100" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_36.gif" alt="" width="549" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_48.gif" alt="" width="580" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_37.gif" alt="" width="438" height="38" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_49.gif" alt="" width="87" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_38.gif" alt="" width="206" height="18" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_50.gif" alt="" width="428" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_39.gif" alt="" width="244" height="244" /></p>
<p>This is not unexpected. The internal function <tt>VisualizationDiscontinuities</tt> yields no exclusions for the <tt>Root</tt> object.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_51.gif" alt="" width="502" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_40.gif" alt="" width="14" height="12" /></p>
<p>The reason is the quite large computational effort needed to determine the cuts for parametrized roots. While the branch points are relatively easy to determine as the common root of the function and its derivative through one resultant calculation, calculating the cuts is more expensive.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_52.gif" alt="" width="580" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_53.gif" alt="" width="195" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_41.gif" alt="" width="580" height="107" /></p>
<p>Expanding the first of the roots, we see the existence of three second-order branch points.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_54.gif" alt="" width="395" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_42.gif" alt="" width="580" height="172" /></p>
<p>A discontinuity of a <tt>Root</tt> object occurs due to a switch in the root numbering. This in turn results from coinciding real parts of different roots. At the point where two roots have a common real part, the real part must have a double root. So carrying out the two resultant calculations gives a sufficient set of algebraic curves along which the roots will exhibit discontinuities.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_55.gif" alt="" width="525" height="148" /></p>
<p>Even for just a fourth root, evaluating <tt>rootExclusions</tt> is quite time consuming and the resulting polynomial is large and complex.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_56.gif" alt="" width="351" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_43.gif" alt="" width="104" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_57.gif" alt="" width="100" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_44.gif" alt="" width="580" height="92" /></p>
<p>Here is a quick overview of the last polynomial.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_58.gif" alt="" width="576" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_45.gif" alt="" width="217" height="12" /></p>
<p>Once the set of exclusions has been calculated, we can use it as the setting for the <tt>Exclusions</tt> option.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_59.gif" alt="" width="580" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_46.gif" alt="" width="244" height="244" /></p>
<h3>Life in Four Dimensions</h3>
<p>Up to now, we have seen <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_30.gif" alt="" width="42" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_31.gif" alt="" width="42" height="12" /> over the complex <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_32.gif" alt="" width="5" height="12" /> plane (we plotted a more general graphic earlier). The most complete information of a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_33.gif" alt="" width="43" height="12" /> is the set of pairs of complex numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_34.gif" alt="" width="28" height="12" /> or the quadruple of real numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_35.gif" alt="" width="139" height="12" />. Imagining the hypersurface <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_36.gif" alt="" width="42" height="12" /> in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_37.gif" alt="" width="14" height="15" /> (isomorphic to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_38.gif" alt="" width="15" height="15" />), we are naturally led to Banchoff&#8217;s tetraview [<a href="#Banchoff">6</a>] of a complex-valued function. In this section, we implement such a construction. Starting with a plot of the real and imaginary parts of a complex-valued function over the complex plane, we extract the underlying graphic complex, and re-evaluate the function at the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_39.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_40.gif" alt="" width="6" height="12" /> values. (Using the already discretized surface in the form of a <tt>GraphicsComplex</tt> gives us the advantage of adaptive subdivision.) Because we will use the values of the derivatives of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_41.gif" alt="" width="21" height="12" /> with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_42.gif" alt="" width="5" height="12" /> for calculating the normals, we store the values of the derivatives at the (complex) vertex points in the option setting for <tt>VertexNormals</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_60.gif" alt="" width="472" height="133" /></p>
<p>We define a function <tt>RiemannSheetParametricPlots4D</tt> that generates a <tt>GraphicsComplex</tt> with vertex values in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_43.gif" alt="" width="15" height="15" />. (Here we use the suboption <tt>TimeConstraint</tt> in the <tt>Exclusions</tt> option to allow the calculation of more complicated exclusion sets for more complicated functions.) The sheets are generated using the function <tt>analyticallyContinue</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_61.gif" alt="" width="530" height="241" /></p>
<p>Here is an example. The abbreviated output shows that the actual 4D <tt>GraphicsComplex</tt> is quite large.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_62.gif" alt="" width="314" height="23" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_47.gif" alt="" width="473" height="209" /></p>
<p>In the absence of a direct 4D viewer in Version 6 (or any support for <tt>Graphics4D</tt>, for that matter&#8212;hopefully Version 7 will have at least some), we must project into a 3D subspace to view the surface as a <tt>Graphics3D</tt> object. For a given <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_44.gif" alt="" width="24" height="12" /> projection matrix, this is straightforward for the vertices and not too difficult for the normals. Fortunately, having the information of the embedded hypersurface in 4D allows a projection with normals in 3D using the Cauchy-Riemann conditions, which will result in a smooth-looking surface. Because we will use the final function interactively, we use <tt>Compile</tt> to carry out the calculation of the 3D vertex coordinates and the 3D normals as efficiently as possible.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_63.gif" alt="" width="519" height="148" /></p>
<p>The function <tt>to3DGraphicsComplex</tt> carries out the projection from 4D to 3D.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_64.gif" alt="" width="491" height="103" /></p>
<p>Putting the last two functions together, we have <tt>TetraviewPlot</tt>. We give it the option <tt>ColorFunction4D</tt>, which operates on the unscaled 4D coordinates to easily color a surface.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_65.gif" alt="" width="410" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_66.gif" alt="" width="483" height="88" /></p>
<p>Here are a few examples of the function <tt>TetraviewPlot</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_67.gif" alt="" width="471" height="23" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_48.gif" alt="" width="244" height="244" /></p>
<p>The next example colors the surface of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_45.gif" alt="" width="35" height="12" />)) according to values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_46.gif" alt="" width="43" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_68.gif" alt="" width="567" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_49.gif" alt="" width="244" height="244" /></p>
<p>A convenient and natural way to parametrize the projection matrix is to use the six rotation angles between the four coordinate planes in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_47.gif" alt="" width="15" height="15" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_69.gif" alt="" width="580" height="118" /></p>
<p>In the definition for <tt>RiemannSheetParametricPlots4D</tt>, we used the line</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_70.gif" alt="" width="446" height="28" /></p>
<p>to cache the result of the most time-consuming step inside <tt>TetraviewPlot</tt>. This allows us to implement a demonstration that interactively changes the 3D subspace selected.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_71.gif" alt="" width="580" height="19" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_50.gif" alt="" width="104" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Input_72.gif" alt="" width="580" height="99" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Output_51.gif" alt="" width="261" height="262" /></p>
<p>This demonstration gives us a feeling for the 2D hypersurface. Branch point neighborhoods in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_48.gif" alt="" width="43" height="12" /> correspond to flat regions in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_49.gif" alt="" width="40" height="12" />, and vice versa. As a result, the initial small gaps along the cuts of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/Corner10-4_Math_50.gif" alt="" width="43" height="12" /> widen as we look at the 4D surface from different directions.</p>
<p>This ends our short visit into the world of Riemann surface visualizations with <em>Mathematica</em> 6. We will be coming back to this subject in future columns.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="IIa">[1] </a></td>
<td>M. Trott, &#8220;Trott&#8217;s Corner: Visualization of Riemann Surfaces IIa: Compositions of Elementary Transcendental Functions,&#8221; <em>The Mathematica Journal</em>, <strong>7</strong>(4), 2000 pp. 465-496.</td>
</tr>
<tr>
<td class="Reference"><a name="IIb">[2] </a></td>
<td>M. Trott, &#8220;Trott&#8217;s Corner: Visualization of Riemann Surfaces IIb: Compositions of Elementary Transcendental Functions,&#8221; <em>The Mathematica Journal</em>, <strong>8</strong>(1), 2001 pp. 50-62.</td>
</tr>
<tr>
<td class="Reference"><a name="IIc">[3] </a></td>
<td>M. Trott, &#8220;Trott&#8217;s Corner: Visualization of Riemann Surfaces IIc: Compositions of Elementary Transcendental Functions,&#8221; <em>The Mathematica Journal</em>, <strong>8</strong>(3), 2002 pp. 409-432.</td>
</tr>
<tr>
<td class="Reference"><a name="IId">[4] </a></td>
<td>M. Trott, &#8220;Trott&#8217;s Corner: Visualization of Riemann Surfaces IId: Compositions of Elementary Transcendental Functions,&#8221; <em>The Mathematica Journal</em>, <strong>8</strong>(4), 2002 pp. 532-562.</td>
</tr>
<tr>
<td class="Reference"><a name="GuideBook">[5] </a></td>
<td>M. Trott, <em>The Mathematica GuideBook for Numerics</em>, New York: Springer-Verlag, 2006.</td>
</tr>
<tr>
<td class="Reference"><a name="Banchoff">[6] </a></td>
<td>T. F. Banchoff, &#8220;Computer Graphics in Geometric Research,&#8221; in <em>Recent Trends in Mathematics: Conference in Reinhardsbrunn (Reinhardsbrunn 1982)</em>, (H. Kurke, J. Mecke, H. Triebel, and R. Thiele, eds.), Teubner-Texte Math., <strong>50</strong>, Leipzig: Teubner, 1983 pp. 316-327.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">M. Trott, &#8220;The Return of the Riemann Surface,&#8221; <em>The Mathematica Journal</em>, 2011. dx.doi.org/10.3888/tmj.10.4-1.</td>
</tr>
</tbody>
</table>
<p class="TextAboutAuthor"><strong>Michael Trott</strong><br />
Senior Member, Technical Staff<br />
<em>Wolfram Research, Inc.<br />
</em><em><a href="mailto:mtrott@wolfram.com">mtrott@wolfram.com</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/02/the-return-of-the-riemann-surface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Classic Puzzles in Wolfram Demonstrations</title>
		<link>http://www.mathematica-journal.com/2012/02/classic-puzzles-in-wolfram-demonstrations/</link>
		<comments>http://www.mathematica-journal.com/2012/02/classic-puzzles-in-wolfram-demonstrations/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 00:10:32 +0000</pubDate>
		<dc:creator>Todd Akers</dc:creator>
				<category><![CDATA[Volume 10, Issue 4]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=17816</guid>
		<description><![CDATA[Sudoku, today&#8217;s most well-known grid-solving puzzle, was originally invented by Howard Garns in 1978. Almost 30 years later, its popularity suddenly exploded. This column presents logic puzzles of various sorts and challenges readers to solve the puzzles in two ways: by hand and with Mathematica. Solvers are invited to send their code to edp@wolfram.com.
Fifteen Classic [...]]]></description>
			<content:encoded><![CDATA[<p>Sudoku, today&#8217;s most well-known grid-solving puzzle, was originally invented by Howard Garns in 1978. Almost 30 years later, its popularity suddenly exploded. This column presents logic puzzles of various sorts and challenges readers to solve the puzzles in two ways: by hand and with <em>Mathematica. </em>Solvers are invited to send their code to <a href="mailto:edp@wolfram.com">edp@wolfram.com</a>.<span id="more-17816"></span></p>
<h3>Fifteen Classic Puzzles</h3>
<ol class="ItemNumbered">
<li>If a package has one of 50 random baseball cards, how many packages do you need to buy to get a complete set?<br />
(<a href="http://demonstrations.wolfram.com/CouponCollectorProblem/">demonstrations.wolfram.com/CouponCollectorProblem</a>)</li>
<li>A chess king is at one corner of a chessboard. It makes a series of moves that always take it closer to the opposite corner. How many possible paths are there? (<a href="http://demonstrations.wolfram.com/DelannoyPathExhaustionDiagonal/">demonstrations.wolfram.com/DelannoyPathExhaustionDiagonal</a>)</li>
<li>A hallway has 100 lockers, all closed. 100 students are sent down the hall as follows: student 1 opens all the lockers; student 2 closes every other locker, beginning with the second; student 3 changes the state of every third locker, beginning with the third; and so on. After all the students have marched, which lockers remain open?<br />
(<a href="http://demonstrations.wolfram.com/TheLockerProblem/">demonstrations.wolfram.com/TheLockerProblem</a>)</li>
<li>In the Florida Lotto<img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Trademark.gif" alt="" width="12" height="19" />, a player picks 6 numbers out of 1 to 53. Matching 3, 4, 5, or 6 numbers from the drawing wins a prize. What are the odds of winning? (<a href="http://demonstrations.wolfram.com/UrnProblem/">demonstrations.wolfram.com/UrnProblem</a>)</li>
<li>On a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_1.gif" alt="" width="24" height="12" /> grid, plant 10 trees to make 5 lines each containing 4 trees. (<a href="http://demonstrations.wolfram.com/OrchardPlantingProblem/">demonstrations.wolfram.com/OrchardPlantingProblem</a>)</li>
<li>A <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_2.gif" alt="" width="24" height="12" /> grid has 25 &#8220;on&#8221; buttons. Pressing a button changes the state of that button and the surrounding buttons. Can all the buttons be turned &#8220;off&#8221;? (<a href="http://demonstrations.wolfram.com/LightsOutPuzzle/">demonstrations.wolfram.com/LightsOutPuzzle</a>)</li>
<li>Can books similar in size be stacked on the edge of a desk so that the top book is not over the desk at all? (<a href="http://demonstrations.wolfram.com/StackingDominoesToTheLimit/">demonstrations.wolfram.com/StackingDominoesToTheLimit</a>)</li>
<li>McDonald&#8217;s <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_3.gif" alt="" width="7" height="14" /> once sold Chicken McNuggets<img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Trademark.gif" alt="" width="12" height="19" /> in packs of 6, 9, or 20. What is the highest number of McNuggets you cannot buy?<br />
(<a href="http://demonstrations.wolfram.com/McNuggetProblemAndFrobeniusNumbers/">demonstrations.wolfram.com/McNuggetProblemAndFrobeniusNum-bers</a>)</li>
<li>Thirty people are in a room. What is the probability that two of them share a birthday? (<a href="http://demonstrations.wolfram.com/TheBirthdayProblem/">demonstrations.wolfram.com/TheBirthdayProblem</a>)</li>
<li>Wheels of radius 30cm and 40cm are 10cm apart. What is the length of a snug belt that goes around both? (<a href="http://demonstrations.wolfram.com/TwoWheelBelt/">demonstrations.wolfram.com/TwoWheelBelt</a>)</li>
<li>You have a 3 gallon jug and a 5 gallon jug at a well. How can exactly 1 gallon be measured? (<a href="http://demonstrations.wolfram.com/JugProblem/">demonstrations.wolfram.com/JugProblem</a>)</li>
<li>A 30-foot statue is on a 10-foot pedestal. Where should you stand so that the statue itself looks as big as possible from your point of view? (<a href="http://demonstrations.wolfram.com/TheStatueOfRegiomontanus/">demonstrations.wolfram.com/TheStatueOfRegiomontanus</a>)</li>
<li>As a contestant on Monty Hall&#8217;s game show, you are presented with three doors. Behind one door is a new car and behind each of the other two is a goat. You select a door behind which, you hope, is the new car. Monty Hall then opens another door to reveal a goat and asks if you would like to change your selection. Should you switch?<br />
(<a href="http://demonstrations.wolfram.com/MontyHallProblem/">demonstrations.wolfram.com/MontyHallProblem</a>)</li>
<li>You have 12 coins, labeled with letters M, I, T, F, O, L, K, D, A, N, C, and E. One of the coins is fake, and is heavier or lighter than the others. Can you find the fake coin in 3 weighings?<br />
(<a href="http://demonstrations.wolfram.com/The12CoinWeighingProblem/">demonstrations.wolfram.com/The12CoinWeighingProblem</a>)</li>
<li>A 55-gallon barrel, with a diameter of 22.5 inches, is lying on its side. 10 inches of grain is in the barrel. How much grain does the barrel contain? (<a href="http://demonstrations.wolfram.com/SagittaApothemAndChord/">demonstrations.wolfram.com/SagittaApothemAndChord</a>)</li>
</ol>
<h3>Discussion&#8212;Coupon Collecting</h3>
<p>For each of the problems listed above, a link is given to a Wolfram Demonstration that allows for further exploration [<a href="#Nikoli #73">1</a>]. For example, the Coupon Collector Demonstration comes with the following explanatory caption:</p>
<div class="Quote">If a package has one of 50 random baseball cards, how many packages do you need to buy to get a complete set? The expected answer is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_4.gif" alt="" width="65" height="12" /> packages, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_5.gif" alt="" width="19" height="12" /> is the harmonic number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_6.gif" alt="" width="146" height="12" />. Switching from baseball cards to coupons gives the coupon collector problem: if there are <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_7.gif" alt="" width="6" height="12" /> different kinds of coupons and many of them are distributed randomly, the expected number of purchases necessary for a complete set is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Math_8.gif" alt="" width="23" height="12" />.</div>
<p>Code containing a <tt>Manipulate</tt> is provided for each Demonstration, allowing for exploration of the problem with either <em>Mathematica</em> or <em>Mathematica</em> <span class="TI">Player</span>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Input_1.gif" alt="" width="580" height="208" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2011/12/ClassicPuzzles_Output_1.gif" alt="" width="352" height="156" /></p>
<p>All the classic puzzles listed here have been given a similar Demonstration treatment. Is there another classic problem that should be added to The Wolfram Demonstrations Project? If so, please consider adding it at <a href="http://demonstrations.wolfram.com/participate.html">demonstrations.wolfram.com/participate.html</a>. Drop me a line once your new Demonstration has been published.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Nikoli #73">[1] </a></td>
<td>The Wolfram Demonstrations Project, <a href="http://demonstrations.wolfram.com/">demonstrations.wolfram.com</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">E. Pegg Jr., &#8220;Classic Puzzles in Wolfram Demonstrations,&#8221; <em>The Mathematica Journal</em>, 2011. dx.doi.org/10.3888/tmj.10.4-2.</td>
</tr>
</tbody>
</table>
<p class="TextAboutAuthor"><strong>Ed Pegg Jr</strong><br />
Scientific Information Editor<br />
<em>Wolfram Research, Inc.<br />
</em><em><a href="mailto:edp@wolfram.com">edp@wolfram.com</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/02/classic-puzzles-in-wolfram-demonstrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

