m (III. Computer Programming)
m (III. Computer Programming)
Line 10: Line 10:
 
A computer would make a great job of checking this, in particular when convergence is slow. It will also allow us to deepen this important business of convergence.
 
A computer would make a great job of checking this, in particular when convergence is slow. It will also allow us to deepen this important business of convergence.
  
Let us compute \ref{eq:e1}: for $n=1$, this is $(1+(1/1))=2$. For $n=2$, this is $(1+(1/2))^2=9/4=2.25$. For $n=3$, this is $(1+(1/3))^3=(4/3)^3=64/27=2.\bar{370}$
+
Let us compute \ref{eq:e1}: for $n=1$, this is $(1+(1/1))=2$. For $n=2$, this is $(1+(1/2))^2=9/4=2.25$. For $n=3$, this is $(1+(1/3))^3=(4/3)^3=64/27=2.\overbar{370}$. Unlike computers, we get pretty tired. So we can ask the computer to do it. This is how one popular computer program, [[Wolfram]]'s [[Mathematica]], would do it:
 +
 
 +
<pre>
 +
Table[N[(1 + 1/n)^n], {n, 1, 10}]
 +
{2., 2.25, 2.37037, 2.44141, 2.48832, 2.52163, 2.5465, 2.56578, \
 +
2.58117, 2.59374}
 +
</pre>
  
 
{{WLP6}}
 
{{WLP6}}

Revision as of 12:41, 8 February 2021

Crash Course in Scientific Computing

III. Computer Programming

Computers are good at computing! We have seen various definitions of Euler's number $e$, of which, in particular:

$$\tag{1}e=\lim_{n\rightarrow\infty}\left(1+{1\over n}\right)^n$$

$$\tag{2}e=\sum_{k=0}^\infty{1\over k !}$$

A computer would make a great job of checking this, in particular when convergence is slow. It will also allow us to deepen this important business of convergence.

Let us compute (1): for $n=1$, this is $(1+(1/1))=2$. For $n=2$, this is $(1+(1/2))^2=9/4=2.25$. For $n=3$, this is $(1+(1/3))^3=(4/3)^3=64/27=2.\overbar{370}$. Unlike computers, we get pretty tired. So we can ask the computer to do it. This is how one popular computer program, Wolfram's Mathematica, would do it:

Table[N[(1 + 1/n)^n], {n, 1, 10}]
{2., 2.25, 2.37037, 2.44141, 2.48832, 2.52163, 2.5465, 2.56578, \
2.58117, 2.59374}