Lec2 227 08 - University of...
Transcript of Lec2 227 08 - University of...
![Page 1: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/1.jpg)
Lecture 2
Our goal here is to begin to learn to use Mathematica while at the same time use it to explore the
concepts in the text. You are encouraged to confirm the Mathematica results and the mechanical issue
of running the program, entering the commands, etc., i.e., run your own session of Mathematica and
enter these commands. Mathematica has pretty good built-in Help and you are strngly encouraged to
use it to look-up definitions of functions, find new functions, etc. The key stroke instructing Mathemat-
ica to perform a command (or evaluate an expression) is the combination shift-enter. The command to
open a text line to annotate your work is Alt-7.
From Eq. 2.5 we use the "sum" function in Mathematica to consider the (finite) sum
In[1]:= Sum@x^n, 8n, 4<D
Out[1]= x + x2
+ x3
+ x4
Alternatively we can enter the same expression with
In[2]:= Sum@x^n, 8n, 1, 4<D
Out[2]= x + x2
+ x3
+ x4
Note the general feature that Mathematica always begins the names of pre-installed functions with
capital letters, puts the arguments in square brackets, []'s, and uses curly brackets, {}'s, to define param-
eters for the function; here to sum over the index n from 1 to 4 (i.e., {n,4} = {n,1,4}).
Now define the infinite version (note how Mathematica likes to label the "quantity" infinity; it can also be
entered with the symbol ¥). In defining a function we use the underscore, _, to label the arguments (on
the left-hand-side) and the symbol ":=" (and not just "=")
In[3]:= S@x_D := Sum@x^n, 8n, Infinity<D
To ask Mathematica to perform the sum we simply type the name of the function (with no underscoring),
In[4]:= S@xD
Out[4]= -
x
-1 + x
This is a common result that Mathematica does not simplify automatically to the expected analytic
expression. If you expect that simplification is possible, you can ask Mathematica to look for it. There
is a handy shorthand if you want to perform an operation of the previous expression - just represent it
by the % symbol.
In[5]:= Simplify@%D
Out[5]= -
x
-1 + x
Given the current order in which the commands have been evaluated, this last command is the same as
In[6]:= Simplify@S@xDD
Out[6]= -
x
-1 + x
This the result of Eq.(2.10). For comparison we can also evaluate the sum starting with 1, the power
zero, as in Eq.(2.9), the so-called geometric series
![Page 2: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/2.jpg)
This the result of Eq.(2.10). For comparison we can also evaluate the sum starting with 1, the power
zero, as in Eq.(2.9), the so-called geometric series
In[7]:= Sum@x^n, 8n, 0, 4<D
Out[7]= 1 + x + x2
+ x3
+ x4
In[8]:= Sum@x^n, 8n, 0, ¥<D
Out[8]=
1
1 - x
An essential strength of the Mathematica software is the ability to analytically perform this infinite
summation for a general variable x, as here. On the other hand you have to be careful not to be misled
by the result. In particular, for |x| < 1 the infinite series defines the function indicated. However, while
the functions is well defined for |x| > 1, the infinite series itself is divergent. We can study the issue of
convergence by looking at the behavior of the finite (truncated) series and then the remainder. First
define the finite series as a function of both x and N.
In[9]:= SN@N_, x_D := Sum@x^n, 8n, 1, N<D
In[10]:= SN@4, xD
Out[10]= x + x2
+ x3
+ x4
So let's use our plotting ability to check the behavior of this function as a function of N for fixed values
of x, e.g., x = 0.5.
In[11]:= Plot@SN@N, 0.5D, 8N, 1, 20<D
Out[11]=
10 15 20
0.85
0.90
0.95
1.00
Let's clean this up a bit and provide labels.
2 Lec2_227_08.nb
![Page 3: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/3.jpg)
In[12]:= Plot@SN@N, 0.5D, 8N, 1, 20<, PlotRange ® 80, 1<,
AxesLabel ® 8N, SN<, AxesOrigin -> 80, 0<D
Out[12]=
0 5 10 15 20
N
0.2
0.4
0.6
0.8
1.0
SN
It clearly converges by N around 15. Now lets try a few values of x.
In[13]:= Plot@8SN@N, 0.3D, SN@N, 0.5D, SN@N, 0.7D, SN@N, 0.9D<, 8N, 1, 20<,
PlotRange ® 80, 1<, AxesLabel ® 8N, SN<, AxesOrigin -> 80, 0<D
Out[13]=
0 5 10 15 20
N
0.2
0.4
0.6
0.8
1.0
SN
Clearly both the number the series converges to varies with x and the actual converge properties vary
with the x value, but the details are difficult to see in this plot. To clean up the plot we extend the limits
and the axes.
Lec2_227_08.nb 3
![Page 4: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/4.jpg)
In[14]:= Plot@8SN@N, 0.3D, SN@N, 0.5D, SN@N, 0.7D, SN@N, 0.9D<, 8N, 1, 50<,
PlotRange ® 80, 10<, AxesLabel ® 8N, SN<, AxesOrigin -> 80, 0<D
Out[14]=
0 10 20 30 40 50
N
2
4
6
8
10
SN
However, note that
In[15]:= Plot@SN@N, 1.1D, 8N, 1, 20<, PlotRange ® 80, 50<,
AxesLabel ® 8N, SN<, AxesOrigin -> 80, 0<D
Out[15]=
0 5 10 15 20
N
10
20
30
40
50
SN
So for |x| > 1 we see the finite sum diverging as N gets large. To focus on the question of convergence/-
divergence can look at the remainder of all the terms in the infinite series after the Nth term, RN = S -
SN.
In[16]:= RN@N_, x_D := Sum@x^n, 8n, 1 + N, Infinity<D
In[17]:= RN@N, xD
Out[17]=
x1+N
1 - x
In[18]:= SN@N, xD + RN@N, xD
Out[18]=
x1+N
1 - x
+
x H-1 + xNL-1 + x
A bit messy so simplify.
4 Lec2_227_08.nb
![Page 5: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/5.jpg)
In[19]:= Simplify@SN@N, xD + RN@N, xDD
Out[19]= -
x
-1 + x
The expected analytic result for the full sum. Consider the remainder numerically.
In[20]:= RN@50, .3D
Out[20]= -2.22045 ´ 10-16
Mathematica has trouble recognizing the convergence but we can look for it graphically
In[21]:= Plot@RN@N, 0.3D, 8N, 1, 20<, PlotRange ® 80, 1<,
AxesLabel ® 8N, RN<, AxesOrigin -> 80, 0<D
Unset::wrsym : Symbol N is Protected. �
Out[21]=
0 5 10 15 20
N
0.2
0.4
0.6
0.8
1.0
RN
Note again that Mathematica struggles to perform the sum numerically, but still suggests that the
remainder shrinks with increasing N. Now consider the 4 x values used above
In[22]:= Plot@8RN@N, 0.3D, RN@N, 0.5D, RN@N, 0.7D, RN@N, 0.9D<, 8N, 1, 50<,
PlotRange ® 80, 1<, AxesLabel ® 8N, RN<, AxesOrigin -> 80, 0<D
Out[22]=
0 10 20 30 40 50
N
0.2
0.4
0.6
0.8
1.0
RN
As expected all the remainders head to zero for N®¥, although even on the current scale the remain-
der has only shrunk to about 0.05 at N = 50. Clearly this is not very satisfactory and is why, even with
computers available, we also need the analytic tests for convergence discussed in Lecture 2.
Lec2_227_08.nb 5
![Page 6: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/6.jpg)
As expected all the remainders head to zero for N®¥, although even on the current scale the remain-
der has only shrunk to about 0.05 at N = 50. Clearly this is not very satisfactory and is why, even with
computers available, we also need the analytic tests for convergence discussed in Lecture 2.
What about the case x = 1
In[23]:= Plot@RN@N, 1.0D, 8N, 1, 20<, PlotRange ® 80, 1<,
AxesLabel ® 8N, RN<, AxesOrigin -> 80, 0<D
Sum::div : Sum does not converge. �
Sum::div : Sum does not converge. �
Sum::div : Sum does not converge. �
General::stop : Further output of Sum::div will be suppressed during this calculation. �
Out[23]=
0 5 10 15 20
N
0.2
0.4
0.6
0.8
1.0
RN
So in this case Mathematica knows that something is wrong.
Another way to look at is in terms of the limit, N ® ¥ (where we expect a zero answer for convergence)
In[24]:= Limit@RN@N, 0.5D, N ® ¥DOut[24]= 0.
So Mathematica does not handle this well. On the other hand once we have "summed" the general sum
In[25]:= RN@N, xD
Out[25]=
x1+N
1 - x
We can use this form to take the largeN limit for fixed x easily (note the substitution command /.x-
>value)
In[26]:=
x1+N
-1 + x
�. x ® 0.9
Out[26]= -10. 0.91+N
Take the limit
In[27]:= LimitB-
x1+N
-1 + x
�. x ® 0.9, N ® ¥F
Out[27]= 0.
So the series converges. At the boundary x = 1 we have
6 Lec2_227_08.nb
![Page 7: Lec2 227 08 - University of Washingtonstaff.washington.edu/sdellis/Phys2278/Lec2_227_08.pdfLec2_227_08.nb 5. As expected all the remainders head to zero for N޴, although even on](https://reader035.fdocuments.us/reader035/viewer/2022070812/5f0b1b567e708231d42ee19b/html5/thumbnails/7.jpg)
In[28]:= LimitB-
x1+N
-1 + x
�. x ® 1.0, N ® ¥F
Power::infy : Infinite expression
1
0.
encountered. �
Out[28]= ComplexInfinity
So this expression clearly diverges, and for x > 1
In[29]:= LimitB-
x1+N
-1 + x
�. x ® 1.1, N ® ¥F
Out[29]= -¥
We can also see this behavior in the plot of the summed series S[x], i.e., the divergence as x
approaches 1.
In[30]:= Plot@S@xD, 8x, -2, 2<, AxesLabel ® 8x, S<D
Sum::div : Sum does not converge. �
Sum::div : Sum does not converge. �
Sum::div : Sum does not converge. �
General::stop : Further output of Sum::div will be suppressed during this calculation. �
Out[30]=
-2 -1 1 2
x
1
2
3
4
5
S
So if we carefully evaluate the infinite series representing the remainder and takes its limit, N®¥ ,
Mathematica will accurately tell us about the convergence properties of the series. On the other hand,
we often have difficulty proceeding just numerically. The analytic analysis we have discussed in the
Lecture is essentially for proceeding either by hand or via Mathematica. To make use of series, we
need to understand when they make sense and when they do not via analytic methods.
Lec2_227_08.nb 7