(************** Content-type: application/mathematica **************
Mathematica-Compatible Notebook
This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.
To get the notebook into a Mathematica-compatible application, do
one of the following:
* Save the data starting with the line of stars above into a file
with a name ending in .nb, then open the file inside the
application;
* Copy the data starting with the line of stars above to the
clipboard, then use the Paste menu command inside the application.
Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode. Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.
For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info@wolfram.com
phone: +1-217-398-0700 (U.S.)
Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)
(*CacheID: 232*)
(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[ 40231, 1126]*)
(*NotebookOutlinePosition[ 41365, 1162]*)
(* CellTagsIndexPosition[ 41321, 1158]*)
(*WindowFrame->Normal*)
Notebook[{
Cell[CellGroupData[{
Cell[TextData[{
StyleBox["Math E-21a: Multivariable Calculus, Fall 2003",
FontFamily->"Times New Roman",
FontSlant->"Plain",
FontVariations->{"CompatibilityType"->0}],
StyleBox["\n",
FontFamily->"Times New Roman"],
StyleBox["Mathematica Lab #3",
FontFamily->"Times New Roman",
FontSize->24,
FontSlant->"Plain",
FontVariations->{"CompatibilityType"->0}]
}], "Subsubtitle",
Editable->True,
TextAlignment->Center,
FontFamily->"Courier",
FontWeight->"Bold",
FontColor->GrayLevel[0],
Background->RGBColor[1, 1, 0]],
Cell[CellGroupData[{
Cell["Introduction and Review", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
StyleBox["The purpose of this Mathematica assignment is to introduce you to \
some of the differential equation solving abilitites of ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[". However,before starting, you might find it useful to review the \
introductory material from the first two Mathematica assignments about the \
special notation and formatting rules for Mathematica. In any event, here is \
a brief summary of the more ubiquitous ones:",
FontSize->12]
}], "Text",
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]],
Cell[TextData[{
StyleBox["Entering ",
FontSize->12,
FontWeight->"Bold"],
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Bold",
FontSlant->"Italic"],
StyleBox[" Expressions",
FontSize->12,
FontWeight->"Bold"],
StyleBox["\nTo create a new input cell, position the cursor between two \
existing cells so that ",
FontSize->12],
StyleBox["Mathematica ",
FontSize->12,
FontSlant->"Italic"],
StyleBox["switches the cursor to a horizontal I-beam, click the mouse, and \
then start typing. If you type into an existing output cell, ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" will make a copy of the cell and allow you to edit the content. \
If you have two expressions in the same input cell, separate them by ",
FontSize->12],
StyleBox[";", "Input",
FontSize->12],
StyleBox[" so ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" knows that they are two different expressions and should be \
evaluated separately.",
FontSize->12]
}], "Text",
Editable->True,
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]],
Cell[TextData[{
StyleBox["Evaluating ",
FontSize->12,
FontWeight->"Bold"],
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Bold",
FontSlant->"Italic"],
StyleBox[" Expressions",
FontSize->12,
FontWeight->"Bold"],
StyleBox["\nTo evalute an expression or to have ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" input or read an expression, click anywhere in the input cell \
and press simultaneously the 'shift' and 'enter' key or the 'enter' key on \
the keypad.",
FontSize->12]
}], "Text",
Editable->True,
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]],
Cell[TextData[{
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Bold",
FontSlant->"Italic"],
StyleBox[" Syntax",
FontSize->12,
FontWeight->"Bold"],
StyleBox["\nCapitalize first letter of built-in functions and variables.\n\
\t",
FontSize->12],
StyleBox["Correct: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[0, 0.500008, 0]],
StyleBox["Sin[x], E^Pi ", "Input",
FontSize->12],
StyleBox["\t ",
FontFamily->"Times New Roman",
FontSize->12],
StyleBox["Incorrect: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 0]],
StyleBox[" ",
FontSize->12],
StyleBox["sin[x], e^pi, LOG[e]", "Input",
FontSize->12],
StyleBox["\nUse ",
FontSize->12],
StyleBox["()", "Input",
FontSize->12],
StyleBox[" to group expressions and ",
FontSize->12],
StyleBox["[]", "Input",
FontSize->12],
StyleBox[" to enclose function arguments.\n\t",
FontSize->12],
StyleBox["Correct: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[0, 0.500008, 0]],
StyleBox["(1+2)*3, Sin[Pi], E^Log[5] ", "Input",
FontSize->12],
StyleBox["\t",
FontFamily->"Times New Roman",
FontSize->12],
StyleBox["Incorrect: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 0]],
StyleBox[" ",
FontSize->12],
StyleBox["{[1+2]*3}, Sin(pi), e^ln 5\n", "Input",
FontSize->12],
StyleBox["Use ",
FontSize->12],
StyleBox["[]", "Input",
FontSize->12],
StyleBox[", ",
FontSize->12],
StyleBox["x_", "Input",
FontSize->12],
StyleBox[", and ",
FontSize->12],
StyleBox[":=", "Input",
FontSize->12],
StyleBox[" when defining functions.\n\t",
FontSize->12],
StyleBox["Correct: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[0, 0.500008, 0]],
StyleBox["f[x_]:=g[x]^2+3x", "Input",
FontSize->12],
StyleBox["\t\t ",
FontFamily->"Times New Roman",
FontSize->12],
StyleBox["Incorrect: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 0]],
StyleBox[" ",
FontSize->12],
StyleBox["f(x)=g(x)^2+3x\n", "Input",
FontSize->12],
StyleBox["Remember to evaluate function definitions by pressing \
simultaneously the keys 'shift' and 'enter' or just the key 'enter' on the \
keypad over the cell before using them.",
FontSize->12]
}], "Text",
Editable->True,
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]],
Cell[TextData[{
StyleBox["Implicit Multiplication",
FontSize->12,
FontWeight->"Bold"],
StyleBox["\nSeparate expressions with a space to denote multiplication.\n\t\
",
FontSize->12],
StyleBox["Correct: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[0, 0.500008, 0]],
StyleBox["(-b+Sqrt[b^2-4a c])/(2a)", "Input",
FontSize->12],
StyleBox["\t\t",
FontFamily->"Times New Roman",
FontSize->12],
StyleBox["Incorrect: ",
FontFamily->"Wingdings",
FontSize->12,
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 0]],
StyleBox["(-b+Sqrt[b^2-4ac])/(2a)", "Input",
FontSize->12]
}], "Text",
Editable->True,
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]],
Cell[TextData[{
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Bold",
FontSlant->"Italic"],
StyleBox[" Notebook and Outlines\n",
FontSize->12,
FontWeight->"Bold"],
StyleBox["A notebook is a ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" document. It is organized as an outline as indicated by the \
blue brackets on the right. You can double-click the blue brackets to \
collapse and expand a particular section of the outline. Thus, if your ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" notebook all of a sudden \"disappears,\" most likely, you have \
collapsed the entire notebook. Just double click the right-most blue \
bracket to expand the outline again.",
FontSize->12]
}], "Text",
Editable->True,
FontFamily->"Courier",
FontSize->9,
Background->GrayLevel[0.900008]]
}, Open ]],
Cell[CellGroupData[{
Cell["Differential equations for functions of time ", "Subsection",
Editable->True,
FontFamily->"Courier",
FontSize->12,
Background->RGBColor[1, 0, 0]],
Cell["\<\
The simplest differential equations are those for a function, x(t), of one \
variable t. Of these perhaps the simplest is x'= f(x) where f is a function. \
For example, x(t)= x, or x'= x (1 \[Hyphen] x). Equations of the form x' = \
a x with a=constant are called \"exponential growth\" equations. To see what \
a solution looks like with a=2, have Mathematica evaluate the following:\
\>", "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(New =
NDSolve[{\(x'\)[t] \[Equal] 2\ x[t], x[0] \[Equal] 1},
x, {t, 0, 1}];\)\), "\[IndentingNewLine]",
\(\(Plot[x[t]\ /. \ New, {t, 0, 1}];\)\)}], "Input",
CellLabel->"In[1]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
"Explanation: The special ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" function NDSolve solves differential equations for functions x(t). It has \
the form A= NDSolve[{equation to be solved, initial value for x}, x, {t, \
start time, end time}]. (The equal sign == which should be read here as \
identical to has not to be confused with the equal sign =, which is used to \
assign values. For example x=5 defines x to be 5. Asking then x==5 gives the \
answer True.) Applying NDSolve tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to solve the equation for x(t) from the start time to the end time with \
the given starting value for x. The result A is a rule pointing to an \
interpolating function. We get a function in the variable t from this rule \
with x[t] /. A[[1]] . This function is plotted with the command Plot[x[t] /. \
A[[1]], {t, start time, end time}];"
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(Logistic =
NDSolve[{\(x'\)[t] \[Equal] 2\ x[t]*\((1 - x[t])\),
x[0] \[Equal] 0.01}, x, {t, 0, 5}];\)\), "\n",
\(\(Plot[x[t]\ /. \ Logistic[\([1]\)]\ , {t, 0, 5}];\)\)}], "Input",
CellLabel->"In[3]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell["\<\
To gain practice, change the starting value for the Logistics equation to \
x[0] = -1 and graph the result. Also, try x[0] = 0.5 and x[0] = 2. Do you \
remember enough from Harvard's Math 1b (or its equivalent) to explain the \
behavior of x[t] for these various starting values? For a second example, \
change the equation in the NDSolve entry to x'[t]=Sin[x[t]] and plot \
solutions with x[0]=\[Pi]/4, 2\[Pi]/4,5\[Pi]/4 and 9\[Pi]/4. \
\>", "Text",
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["Differential equations of second order", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell["\<\
The Mathematica's NDSolve function is not limited to solutions of equations \
which involve only one derivative of x. For example, it can handle equations \
of the form x'' + a x' + b x = 0, where a and b are constants, and many \
equations which relate derivatives of even higher order in x to its lower \
order derivatives; for example x''' + x'' sin(x') + cos(x'' x) = 0. \
\>", "Text",
FontFamily->"Courier"],
Cell[TextData[{
"However, to keep matters simple, we consider equations of the form x'' + a \
x' + b x = 0 which you might have seen in Math 116 or elsewhere. They are \
called differential equations of second order. For example, to plot the \
solution to x'' + x' + x = 0 with initial conditions x(0) = 1 and x'(0) = 1, \
ask ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to evaluate: "
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(SecondOrder =
NDSolve[{\(x''\)[t] + \(x'\)[t] + x[t] \[Equal] 0,
x[0] \[Equal] 1, \(x'\)[0] \[Equal] 1},
x, {t, 0, 10}];\)\), "\[IndentingNewLine]",
\(\(Plot[x[t] /. SecondOrder[\([1]\)], {t, 0, 10}];\)\)}], "Input",
CellLabel->"In[8]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
StyleBox["Comments: ",
FontWeight->"Bold"],
"\nWith regard to the formatting here, note that two initial conditions \
must be specified for these equations with two derivatives on x. This is a \
fairly general rule: For an equation of the form n-derivatives of x = \
function of derivatives of order less than n, you must specify the initial \
values of x and its derivatives up to order n-1 or else there won't be a \
unique solution. On the other hand, if you specify more than these n initial \
conditions, then there usually isn't any solution. By copying the preceding \
cell and changing the equation appropriately, have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot solutions to x'' + x' + x = 0, x'' + 2 x' + x = 0 and x'' + 3 x' + \
x = 0, x'' - x' + x = 0 all using the same initial conditions. \nYou might \
notice the different behavior; the initial case corresponds to a damped \
oscillator, the second case to a critically damped, the third to an over \
damped oscillator, the fourth describes a negative damping situation. \
Finally, pick your own values for a and b in x'' + a x' + b = 0 and your own \
initial conditions and have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solutions."
}], "Text",
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["Differential Equations for vector valued functions", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
StyleBox["Mathematica",
FontSlant->"Italic"],
"'s NDSolve function will also solve differential equations for vector \
functions of time. A typical example which involves the first derivative \
only asks for vector function of time, r(t), which solves the equation r'(t) \
= F(r(t)); where F is some given vector field. Of course if r(t) = (x(t), \
y(t)) has two components, then the graph of the solution is 3-dimensional \
since you have to have t, x and y pictured on the same plot. And, if r(t) = \
(x(t), y(t), z(t)) has three components, then there is no way to graph the \
solution as a function of time with all three coordinates pictured. (You \
could just graph versus time the behavior of the x and y coordinates, or just \
the x and z, or just the y and z.) However, in either case, ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" can plot for you the curve traced out by the solution. \nFor example, to \
plot the curve traced out by the solution to the equation \nr\.b4(t) = (-2 \
x(t) + y(t), -2 y(t) \[Hyphen] x(t)), \nwith starting position (x(0) = 1, \
y(0) = 1), ask ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to evaluate "
}], "Text",
TextAlignment->Left,
FontFamily->"Courier"],
Cell[BoxData[{
\(\(VectorEq =
NDSolve[{\(x'\)[t] \[Equal] \(-2\)\ x[t] + y[t], \(y'\)[
t] \[Equal] \(-2\)*y[t] - x[t], x[0] \[Equal] 1,
y[0] \[Equal] 1}, {x, y}, {t, 0,
4}];\)\), "\[IndentingNewLine]",
\(\(ParametricPlot[
Evaluate[{x[t], y[t]}] /. VectorEq[\([1]\)], {t, 0,
4}];\)\)}], "Input",
CellLabel->"In[10]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
StyleBox["Comment:",
FontWeight->"Bold"],
"\nWith regard to the formatting of the expressions in the preceding cell, \
note that the NDSolve[] function has, except for the MaxSteps entry, \
essentially the same form as before, "
}], "Text",
FontFamily->"Courier"],
Cell["\<\
NDSolve[{ equations, initial conditions},{ variable names},{ t, start time, \
end time}, options} .\
\>", "Text",
FontFamily->"Courier"],
Cell[TextData[{
StyleBox["Mathematica",
FontSlant->"Italic"],
" solve the equation by breaking the time interval into some number, N, of \
steps, occuring at some finite subset of times ",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
" and then replacing the differential equation by a difference equation. \
The simplest approximation, called Euler steps, would be r(",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
"+1) = r(",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
") + F(r(",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
")) (",
Cell[BoxData[
\(TraditionalForm\`t\_\(j + 1\)\)]],
" \[Hyphen]",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
"), which clearly indicates how to obtain r(",
Cell[BoxData[
\(TraditionalForm\`t\_\(j + 1\)\)]],
") from r(",
Cell[BoxData[
\(TraditionalForm\`t\_j\)]],
"). So, you must tell ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" the initial value, r(0), or it won't know how to start the process. (",
StyleBox["Mathematica",
FontSlant->"Italic"],
" uses actually much more sophisticated numerical methods than the Euler \
step method just mentioned and even choses the method which it considers the \
best for the equations.)"
}], "Text",
FontFamily->"Courier"],
Cell[TextData[{
StyleBox["Suggestion:",
FontWeight->"Bold"],
"\nExperiment by asking ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to plot the trajectories for solutions of equations of the form \n(",
Cell[BoxData[
\(TraditionalForm\`x\_t\)]],
" = a x + b y, ",
Cell[BoxData[
\(TraditionalForm\`y\_t\)]],
" = c x + d y) for four or five of your own choices for the constants a, b, \
c and d and for the starting point in the x-y plane. For example, take the \
original version above and start it at (1,-1), then (-1,-1) and finally \
(-1,1). \nBy the way, if you choose small values for the constants a,b,c,d, \
you may have to increase the time interval to see more of the trajectory. "
}], "Text",
FontFamily->"Courier"],
Cell[TextData[{
StyleBox["The Lorentz equation:",
FontWeight->"Bold"],
"\nThe Lorenz equation is a famous equation for three dimensional vector \
(x(t),y(t),z(t)). This equation is said to exhibit chaotic properties as the \
trajectories of solutions which start at t = 0 very close to each other \
evolve in drastically different ways. A version of the Lorenz equation is \n\
(x'(t), y'(t), z'(t)) = (10 (y \[Hyphen] x), - x z + 28 x \[Hyphen] y, x + y \
\[Hyphen] 8 z/3). \nTo view a three dimensional plot of the trajectory of the \
solution starting at (0,0.4,0), have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" evaluate the following cell. "
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(Lorentz =
NDSolve[{\(x'\)[t] \[Equal]
10 \((y[t] - x[t])\), \(y'\)[t] \[Equal] \(-x[t]\)\ z[t] +
28 x[t] - y[t], \(z'\)[t] \[Equal] x[t]*y[t] - 8 z[t]/3,
x[0] \[Equal] z[0] \[Equal] 0, y[0] \[Equal] .4}, {x, y, z}, {t,
0, 40}, MaxSteps \[Rule] 5000];\)\), "\[IndentingNewLine]",
\(\(ParametricPlot3D[Evaluate[{x[t], y[t], z[t]} /. Lorentz], {t, 0, 40},
PlotPoints \[Rule] 5000];\)\)}], "Input",
CellLabel->"In[12]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
"(With regards to the formatting: The MaxStep -> 5000 entry tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to increase the default maximal number of step (which is 1000) to 5000. \
In the ParametricPlot[ ] entry, the PlotPoints -> 5000 entry tells \
Mathematica to use 5000 points to plot the trajectory.) Now have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solutions for various other intial conditinos, say (1,0,0), \
(0,1,0), (0,0,1), (1,1,1) or four of your own choosing. Notice that the \
trajectories all seem to converge upon the same, convoluted subset of space. \
This part of space is called the `Lorentz attractor' as it attracts \
trajectories."
}], "Text",
FontFamily->"Courier"],
Cell["\<\
Just for fun, we ask Mathematica to show the endpoint (x(40),y(40),z(40)) at \
the time t=40 as a function of the starting position (a,b,c)=(0,y(0),0), \
where we vary b=y[0]: \
\>", "Text",
FontFamily->"Courier"],
Cell[BoxData[
\(\(EndPoint[a_, b_, c_] :=
Module[{L, f},
L = NDSolve[{\(x'\)[t] \[Equal]
10 \((y[t] - x[t])\), \(y'\)[t] \[Equal] \(-x[t]\)\ z[t] +
28 x[t] - y[t], \(z'\)[t] \[Equal]
x[t]*y[t] - 8 z[t]/3, x[0] \[Equal] a, y[0] \[Equal] b,
z[0] \[Equal] c}, {x, y, z}, {t, 0, 40},
MaxSteps \[Rule] 5000]; \[IndentingNewLine]f[
t_] := \(Evaluate[{x[t], y[t], z[t]} /. L]\)[\([1]\)]; \
f[40]];\)\)], "Input",
CellLabel->"In[14]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell["\<\
(With regards to the formatting: Module[{variables}, commands ] is used to \
make a procedural unit from a set of commands. The variables in the first \
bracket are local variables and not accessible from outside.)\
\>", "Text",
FontFamily->"Courier"],
Cell[TextData[{
"You can observer that even a tiny change of initial conditions of ",
Cell[BoxData[
\(TraditionalForm\`10\^\(-16\)\)]],
" (which in centimeters is 1 million'th of the size of an atom) leads to a \
completely different end point: "
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(EndPoint[0, 0.4, 0]\), "\[IndentingNewLine]",
\(EndPoint[0, 0.4000000000000001, 0]\)}], "Input",
CellLabel->"In[15]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell["\<\
This sensitive dependence on initial conditions is also called \"chaos\". \
Because of its fractal shape of the orbit and this sensitivity, Chaologists \
(scientists studing chaos) call the Lorentz attractor a strange attractor. It \
is used to illustrate the \"butterfly effect\": A small change of initial \
conditions of the atmosphere like the disturbance of a wing of a butterfly \
could produce a storm in a couple of days. Actually, the Lorentz equations \
were derived originally from a physical model for the atmosphere. \
\>", "Text",
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["The advection equation ", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
StyleBox["Mathematica",
FontSlant->"Italic"],
" can also plot solutions to partial differential equations for functions \
u(t, x) which depend on time t, and a spacial coordinate x. One of the \
simplest such equation is the advection equation ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"=-c ",
Cell[BoxData[
\(TraditionalForm\`u\_x\)]],
", where c is a constant. Solutions to this equation describe travelling \
waves. Moreover, given any initial function g(x), there is a unique solution \
to the advection equation, u(t,x), with the property that u(0, x) = g(x). To \
see an example solution, have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" evaluate the following:"
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(Adv\ =
NDSolve[{D[u[x, t], t] \[Equal] \(-2\)\ D[u[x, t], x],
u[x, 0] \[Equal] 1/\((1 + x^2)\), u[\(-20\), t] \[Equal] 1/401,
u[20, t] \[Equal] 1/401},
u, {x, \(-20\), 20}, {t, 0, 9}];\)\), "\[IndentingNewLine]",
\(\(Plot3D[
Evaluate[u[x, t] /. Adv\ [\([1]\)]], {x, \(-20\), 20}, {t, 0, 9},
AxesLabel \[Rule] {"\", "\", "\__"},
PlotRange \[Rule] {0, 1}, PlotPoints \[Rule] 100, Mesh \[Rule] False,
Boxed \[Rule] False];\)\)}], "Input",
CellLabel->"In[17]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
StyleBox["Comments:",
FontWeight->"Bold"],
"\nHere are some comments about the formatting of the expressions in the \
preceding cell: First off, notice that the NDSolve function is still being \
used, even for partial differential equations. In this case, its formatting \
has the following schematic form:\nNDSolve[{equation for function, function \
at the start time, constraints on boundary values}, name of the function, {x, \
lower bound for x, upper bound for x}, {t, start time, end time}]. You should \
also notice how time and space derivatives are indicated in ",
StyleBox["Mathematica",
FontSlant->"Italic"],
". In particular, the operation D[ ] has entries D[function,derivative \
direction], so D[u[t,x], t] tells Mathematica to take the partial derivative \
of u[t,x] in the t-direction, while D[u[t,x],x] tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to take the partial derivative in the x-direction. You should also notice \
that the constant c in this example of the advection equation is set equal to \
2. Notice as well that the input for the NDSolve[ ] command requires not just \
the initial value, u[0,x], but the value of u at an end point of its range. \
Without this input, there wouldn't be a unique solution and ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" would chose its own boundary condition. By the way, you can set this \
boundary condition for u[t,-20] to be any function of t which is consistent \
with the choice of u[0,-20]. We choose the constant function u[t,-20] = \
u[0,-20] for simplicity. \n\nNotice the entries for the Plot3D[ ] command. \
First is Evaluate[x[t] /. Adv[[1]]] which tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" what function to plot. Next in the Plot3D brackets comes \n{x, lower \
bound for x, upper bound for x}, {t, start time, end time}\nwhich should be \
compatible with the values computed in the interpolation function Adv. You \
could use different lower and upper bounds for x, and different start and end \
times for t in the Plot3D command as compared to those used in the NDSolve \
command, but those used in the Plot3D command had better be covered by those \
used in NDSolve, or the interpolated function Adv computed by ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" would not give good values for the desired t and x values. The other \
options in the Plot3D function are of cosmetic nature and could be left away: \
AxisLabel -> {names for the axis on your plot} tells Mathematica how to \
label the axis on the graph. Following this is PlotRange -> {0,1} which \
tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" the range for the u[t,x] axis on the plot. The PlotPoints->100 command \
tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to make a plot with 100 points. Finally, the Mesh -> False and Boxed -> \
False options tell ",
StyleBox["Mathematica ",
FontSlant->"Italic"],
"not to draw the Mesh on the surface and not to draw a box around the \
graph. \n\nTo get a feel for how this all works for the advection equation, \
tell ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to graph the solution to ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"=-2 ",
Cell[BoxData[
\(TraditionalForm\`u\_x\)]],
" with the same initial condition, u[0, x] = 1/(1+",
Cell[BoxData[
\(TraditionalForm\`x\^2\)]],
"). Then, use the single advection equation, ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"=- ",
Cell[BoxData[
\(TraditionalForm\`u\_x\)]],
" with different initial conditions. \nFor example, try the initial \
conditions u[0,x] = Cos[x], or u[0,x] = x/(1+",
Cell[BoxData[
\(TraditionalForm\`x\^2\)]],
"). Then, make up some of your own initial conditions for ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to plot. You might also try ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" = ",
Cell[BoxData[
\(TraditionalForm\`u\_x\)]],
"; thus the sign of c has been changed. "
}], "Text",
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["The heat equation ", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
StyleBox["Mathematica",
FontSlant->"Italic"],
" can also plot solutions to partial differential equations that involve \
more than the first derivatives. An ubiquitous example is the heat equation, \
",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" = c ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
", where c is a positive constant. For example, evaluate the following cell \
to have Mathematica plot the solution to the equation ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" = ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
" for the function u(t,x) whose initial condition at t=0 is \nu(0, x) = \
exp(-",
Cell[BoxData[
\(TraditionalForm\`\(\(\ \)\(x\^2\)\)\)]],
")."
}],
FontFamily->"Courier"],
Cell[BoxData[{
\(\(HeatEq =
NDSolve[{D[u[x, t], t] \[Equal] D[u[x, t], {x, 2}],
u[x, 0] \[Equal] Exp[\(-x^2\)], u[\(-3\), t] \[Equal] 1/E^9,
u[3, t] \[Equal] 1/E^9},
u, {x, \(-3\), 3}, {t, 0, 3}];\)\), "\[IndentingNewLine]",
\(\(Plot3D[
Evaluate[u[x, t] /. HeatEq[\([1]\)]], {x, \(-3\), 3}, {t, 0, 3},
AxesLabel \[Rule] {"\", "\", "\____"},
PlotPoints \[Rule] 100, Mesh \[Rule] False,
Boxed \[Rule] False];\)\)}], "Input",
CellLabel->"In[21]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
StyleBox["Comments: ",
FontWeight->"Bold"],
"\nThere are only two significant formatting changes here. The first \
involves the entry to the D[ ] command for the x-derivative. Notice that the \
entry now reads D[u[t, x], {x, 2}]. Indeed, the entry {x, 2} here tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to take two derivatives of x. If you want, say four derivaties, you would \
replace this {x, 2} with {x, 4}. For one derivative, you could replace {x,1} \
by x. The second change here is the use of the boundary conditions for u[t, \
+3], u[t,-3], now at both endpoints of the range instead of at just one. Note \
that you can specify any pair of functions of time for u[t,-3] and u[t,3] as \
long as they are consistent with the initial conditions. We chose both to be \
constant functions to keep things simple. "
}],
FontFamily->"Courier"],
Cell[TextData[{
StyleBox["Suggestion:",
FontWeight->"Bold"],
"\nTo get some experience with plotting heat equation solutions, have \
Mathematica plot the solutions to ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" = 2 ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
" and ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" = ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
" equation and experiment with different initial conditions. For example, \
try u[0,x] = 2 Exp[-",
Cell[BoxData[
\(TraditionalForm\`x\^2\)]],
"] and try some of your own initial conditions. You may have to change your \
x=3 (rsp. x=-3) boundary conditions to keep it consistent with the t=0 \
initial conditions. "
}],
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["The wave equation", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
"The NDSolve command can also be used to solve equations which involve more \
than one time derivative and more than one space derivative. An important \
example is the wave equation, ",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
"= c ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
", where the square root of c has the interpretation as the velocity of the \
wave. (If c<0, this equation behaves very differently and is called Laplace's \
equation.) Now, the wave equation takes two derivatives of u, and so one \
might expect (by analogy with the equation ",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
" + a ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
" + b u), that the t=0 values for u and for ",
Cell[BoxData[
\(TraditionalForm\`u\_\(\(t\)\(\ \)\)\)]],
" must be supplied in order to find a unique solution. This is indeed the \
case. Thus, to have Mathematica plot a solution to ",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
"= c ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
", it is necessary to enter functions for u[0,x] and ",
Cell[BoxData[
\(TraditionalForm\`u\_\(\(t\)\(\ \)\)\)]],
"[0,x]. In the following cell, these are taken to by Sin[4 x] and 0:\n"
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(Waves =
NDSolve[{D[u[x, t], {t, 2}] \[Equal] D[u[x, t], {x, 2}],
u[x, 0] \[Equal]
Sin[4*Pi*x], \(\(Derivative[0, 1]\)[u]\)[x, 0] \[Equal] 0,
u[0, t] \[Equal] u[1, t]},
u, {x, 0, 1}, {t, 0, 1}];\)\), "\[IndentingNewLine]",
\(\(Plot3D[Evaluate[u[x, t] /. Waves[\([1]\)]], {x, 0, 1}, {t, 0, 1},
AxesLabel \[Rule] {"\", "\", "\____"},
PlotRange \[Rule] {\(-2\), 2}, PlotPoints \[Rule] 100,
Mesh \[Rule] False, Boxed \[Rule] False];\)\)}], "Input",
CellLabel->"In[23]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
"There are three formatting changes here that you should note. First, the \
entry to the D[] operation for the time derivative has D[u[t, x],{t, 2}] \
which, as you probably guessed, tells ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to take two time derivatives now, not one. Second, since there are now \
second order partial derivatives with respect to t, I have to specify not \
just the initial t=0 condition for u, but also for its time derivative. The \
condition for u at t = 0 is specified by writing u[0, x] = function of x. We \
took Sin[4 \[Pi] x] to be the function of x here. Meanwhile, the initial \
condition for the time derivative of u is specified by writing \
Derivative[u][0, x] = function of x. For this example, we took the constant \
function 0. Third, we have changed the boundary conditions for u[t,0] and \
u[t,1]. Instead of setting both to a constant, we told ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to set u[t,-1] to equal u[t,1]. We could also have set both to zero, or \
each to a different function of t as long as these functions are compatible \
with both the initial condition for u(0,x) and ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"(0,x). By the way, we could also have set u[t, -1] = u[t, 1] for the heat \
equation boundary condition. We did so here and not there just to add \
something new to the story. To get some experience with ",
StyleBox["Mathematica",
FontSlant->"Italic"],
"'s solutions to the wave equation, have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solutions to ",
Cell[BoxData[
\(TraditionalForm\`\(\(u\)\(\ \)\)\_tt\)]],
" = ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
" for with \nu[0,x] = Cos[2 \[Pi] x] and ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0, x] = 0. \nThen have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solution with \nu[0, x] = Cos[4 \[Pi] x] and u_t[0, x] = 0. \n\
Below, we let now ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solution with \nu[0, x] = Exp[ -",
Cell[BoxData[
\(TraditionalForm\`x\^2\)]],
"] and ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0,x] = 0. \n"
}], "Text",
FontFamily->"Courier"],
Cell[BoxData[{
\(\(Waves =
NDSolve[{D[u[x, t], {t, 2}] \[Equal] D[u[x, t], {x, 2}],
u[x, 0] \[Equal]
Exp[\(-x^2\)], \(\(Derivative[0, 1]\)[u]\)[x, 0] \[Equal] 0,
u[\(-10\), t] \[Equal] u[10, t]},
u, {x, \(-10\), 10}, {t, 0, 10}];\)\), "\[IndentingNewLine]",
\(\(Plot3D[
Evaluate[u[x, t] /. Waves[\([1]\)]], {x, \(-10\), 10}, {t, 0, 10},
AxesLabel \[Rule] {"\", "\", "\____"},
PlotRange \[Rule] {\(-2\), 2}, PlotPoints \[Rule] 100,
Mesh \[Rule] False, Boxed \[Rule] False];\)\)}], "Input",
CellLabel->"In[25]:=",
CellFrame->True,
Background->GrayLevel[0.849989]],
Cell[TextData[{
"Next, have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solutions for the wave equations ",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
"= 4 ",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
", with the same initial conditions u[0,x] = Exp[-",
Cell[BoxData[
\(TraditionalForm\`x\^2\)]],
"] and ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0, x] = 0. \nBy the way, solutions to the wave equation ",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
" = ",
Cell[BoxData[
\(TraditionalForm\`u\_\(\(xx\)\(\ \)\)\)]],
"can also be multiplied by constants and and added together to get new \
solutions. For example, have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot the solutions to the wave equation with the initial conditions \n\
u[0, x] = 2 Sin[\[Pi] x], ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0, x] = 0 \nand then have it plot the solution with \nu[0, x] = 4 Sin[ \
\[Pi] x], ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0, x] = 0. \nFinally, have it plot the solution with the initial \
condition \nu[0, x] = Sin[\[Pi] x] + Sin[4 \[Pi] x], ",
Cell[BoxData[
\(TraditionalForm\`u\_t\)]],
"[0, x] = 0. "
}], "Text",
FontFamily->"Courier"]
}, Open ]],
Cell[CellGroupData[{
Cell["Exercise", "Subsection",
Editable->True,
FontFamily->"Courier",
Background->RGBColor[1, 0, 0]],
Cell[TextData[{
"Have ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" plot a solution for a wave equation with the schematic form \n",
Cell[BoxData[
\(TraditionalForm\`u\_tt\)]],
"=",
Cell[BoxData[
\(TraditionalForm\`u\_xx\)]],
"+ f(u), where you choose the function f and the initial conditions. For \
example, you can take f = 0 as we did above, or you can take something fancy. \
In general, take a function which is small because otherwise, you will \
experience blowup's. You may use the boundary conditions u(x,-10) = u(x,10), \
or change these as well."
}], "Text",
FontFamily->"Courier",
Background->RGBColor[1, 0, 1]],
Cell[BoxData[{
\(Harvard\ Extension\ School, Math\ E21a\ - \ Fall\ 2003\), "\n",
\(Mathematica\ Labs\ modified\ by\ Robert\ Winters\ from\ notebooks\ \
developed\ by\ Greg\ Landweber\ \), "\n",
\(and\ Paul\ Hsu\ \((1998/
1999)\)\ for\ Harvard\ University'\ s\ \ Mathematics\ 21
a\ \ \(\(course\)\(.\)\)\)}], "Input",
PageWidth->WindowWidth,
CellFrame->{{0, 0}, {0, 0.5}},
TextAlignment->Left,
FontFamily->"Arial",
FontWeight->"Plain",
FontVariations->{"CompatibilityType"->0}]
}, Open ]]
}, Open ]]
},
FrontEndVersion->"4.1 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 723}},
AutoGeneratedPackage->None,
WindowSize->{1003, 698},
WindowMargins->{{0, Automatic}, {Automatic, 0}},
PrintingCopies->1,
PrintingPageRange->{Automatic, Automatic},
PrintingOptions->{"PrintingMargins"->{{54, 54}, {72, 72}},
"PaperSize"->{612, 792},
"PaperOrientation"->"Portrait",
"PrintCellBrackets"->False,
"PrintRegistrationMarks"->True,
"PrintMultipleHorizontalPages"->False,
"PostScriptOutputFile":>FrontEnd`FileName[{"home", "knill"}, "lab3.ps", \
CharacterEncoding -> "WindowsANSI"],
"Magnification"->1},
Magnification->1,
StyleDefinitions -> "Textbook.nb"
]
(*******************************************************************
Cached data follows. If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of the file. The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[1727, 52, 559, 18, 77, "Subsubtitle"],
Cell[CellGroupData[{
Cell[2311, 74, 121, 3, 59, "Subsection"],
Cell[2435, 79, 631, 15, 76, "Text"],
Cell[3069, 96, 1214, 40, 123, "Text"],
Cell[4286, 138, 681, 24, 85, "Text"],
Cell[4970, 164, 2749, 100, 244, "Text"],
Cell[7722, 266, 776, 28, 94, "Text"],
Cell[8501, 296, 938, 28, 120, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[9476, 329, 159, 4, 58, "Subsection"],
Cell[9638, 335, 438, 7, 59, "Text"],
Cell[10079, 344, 283, 7, 66, "Input"],
Cell[10365, 353, 956, 18, 112, "Text"],
Cell[11324, 373, 307, 7, 66, "Input"],
Cell[11634, 382, 488, 8, 76, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[12159, 395, 136, 3, 59, "Subsection"],
Cell[12298, 400, 427, 7, 59, "Text"],
Cell[12728, 409, 440, 10, 60, "Text"],
Cell[13171, 421, 355, 8, 66, "Input"],
Cell[13529, 431, 1315, 24, 197, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[14881, 460, 148, 3, 59, "Subsection"],
Cell[15032, 465, 1258, 24, 205, "Text"],
Cell[16293, 491, 452, 11, 66, "Input"],
Cell[16748, 504, 289, 7, 68, "Text"],
Cell[17040, 513, 148, 4, 25, "Text"],
Cell[17191, 519, 1305, 39, 96, "Text"],
Cell[18499, 560, 768, 18, 136, "Text"],
Cell[19270, 580, 710, 14, 153, "Text"],
Cell[19983, 596, 580, 11, 86, "Input"],
Cell[20566, 609, 755, 15, 95, "Text"],
Cell[21324, 626, 226, 5, 42, "Text"],
Cell[21553, 633, 626, 13, 126, "Input"],
Cell[22182, 648, 266, 5, 42, "Text"],
Cell[22451, 655, 296, 7, 42, "Text"],
Cell[22750, 664, 201, 5, 66, "Input"],
Cell[22954, 671, 579, 9, 76, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[23570, 685, 121, 3, 59, "Subsection"],
Cell[23694, 690, 771, 19, 78, "Text"],
Cell[24468, 711, 639, 13, 106, "Input"],
Cell[25110, 726, 4144, 90, 583, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[29291, 821, 116, 3, 59, "Subsection"],
Cell[29410, 826, 775, 24, 77, InheritFromParent],
Cell[30188, 852, 604, 13, 106, "Input"],
Cell[30795, 867, 894, 16, 129, InheritFromParent],
Cell[31692, 885, 771, 24, 77, InheritFromParent]
}, Open ]],
Cell[CellGroupData[{
Cell[32500, 914, 115, 3, 59, "Subsection"],
Cell[32618, 919, 1309, 33, 135, "Text"],
Cell[33930, 954, 651, 13, 106, "Input"],
Cell[34584, 969, 2299, 54, 350, "Text"],
Cell[36886, 1025, 685, 14, 106, "Input"],
Cell[37574, 1041, 1296, 40, 211, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[38907, 1086, 106, 3, 59, "Subsection"],
Cell[39016, 1091, 663, 17, 100, "Text"],
Cell[39682, 1110, 521, 12, 75, "Input"]
}, Open ]]
}, Open ]]
}
]
*)
(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)
__