Approximating Pi, as an example of FEM method
This page replicates the example in chapter 1.1 of in a book about finite element method《有限元法基础》(张雄,高等教育出版社,2023). The book is a classical Soviet-Chinese style textbook that gives info blandly. Here we give full details.
Compute Some Sine Without Pi
Computing the value of \(\sin()\) generally requires the value of \(\pi\), however, we can still obtain special values by the definition of Sine:
- \(\sin(0)=0\)
- \(\sin(\pi/2)=1\)
These will be our initial condition.
Then we need the Recurrence Relation between \(\sin(a)\) and \(sin(2a)\).
From Multiple-angle and half-angle formulas, we may get \(\sin(2a)=2\sin(a)\cos(a)\), where if \(a<=\pi/2\) then \(\cos(a)=\sqrt{1-\sin(a)^2}\) as in Pythagorean identities. Thus,
Substitute \(n=\sin(2a)^2\) and \(x=2\sin(a)^2\),
Using the Quadratic formula, we can easily get
Substitute the values back,
The \(\pm\) sign depends on value of \(a\). Plot the right side, we may easily know that when \(a<\pi/4\), the sign should be minus.
(* Plotting in Mathematica *)
Plot[{Sqrt[1 + Sqrt[1 - Sin[2 x]^2]], Sqrt[1 - Sqrt[1 - Sin[2 x]^2]], Sqrt[2]*Sin[x]}, {x, 0, 10}]
Then we can get a special sequence of value for \(\sin(\pi/n)\) where \(n\) is power of 2. For example,
$$ \sin(\pi/4)=\frac{\sqrt{1-\sqrt{1-\sin(\pi/2)^2}}}{\sqrt{2}}=0.707107\ . $$ In Mathematica, this can be defined as
f[0] := 0
f[2] := 1
f[n_] := Sqrt[1 - Sqrt[1 - f[n/2]^2]]/Sqrt[2]
Table[{Sin[Pi/Evaluate[2^x]], f[2^x] // N}, {x, 1, 10}] // TableForm
(* Result *)
Sin[\[Pi]/4] 0.707107
Sin[\[Pi]/8] 0.382683
Sin[\[Pi]/16] 0.19509
Sin[\[Pi]/32] 0.0980171
Sin[\[Pi]/64] 0.0490677
Sin[\[Pi]/128] 0.0245412
Sin[\[Pi]/256] 0.0122715
Sin[\[Pi]/512] 0.00613588
Sin[\[Pi]/1024] 0.00306796
Computing the Value Of \(Pi\)
For a circle that are divided to \(n\) parts, the length of each "element line" is \(L_e=d\sin(\pi/n)\) and the total length is thus \(L=\sum L_e = n d\sin(\pi/n)\).
By definition of \(\pi\), we have\(L=d\pi\) and thus \(\pi=n\sin(\pi/n)\).
Finally,
calcPi[n_] := n*f[n] // N
Table[With[{n = 2^p}, {n, DecimalForm[calcPi[n], 16],
DecimalForm[Abs[Pi - calcPi[n]], 5]}], {p, 2, 10}] // TableForm
(* Result: n, Pi, error *)
4 2.82842712474619 0.31317
8 3.061467458920719 0.080125
16 3.121445152258053 0.020148
32 3.136548490545941 0.0050442
64 3.140331156954739 0.0012615
128 3.141277250932757 0.0003154
256 3.141513801144145 0.000078852
512 3.141572940367883 0.000019713
1024 3.141587725279961 0.0000049283
Appendix
% plot the demo
\documentclass[tikz]{standalone}
\usetikzlibrary {angles,quotes,shapes.geometric,arrows.meta}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw[dashed] (O) circle [radius=4cm];
\node [name=s,regular polygon, regular polygon sides=8, minimum size=8cm,magenta,ultra thick] at (O) {};
\foreach \i in {1,2,3,4,5,6,7,8} {
\draw [dashed] (s.center)-- (s.corner \i);
\filldraw (s.corner \i) circle [radius=0.05];
};
\draw (s.corner 2)--(s.corner 3)--(s.corner 4)--(s.corner 5)--(s.corner 6)--(s.corner 7)--(s.corner 8)--(s.corner 1);
\coordinate (L) at (s.corner 1);
\coordinate (R) at (s.corner 2);
\draw [|<->|,magenta,thick] (L) -- node[below=0cm,black] {$d\sin(\pi/n)$} (R);
\draw pic [draw,angle radius=2cm, "$2\pi/n$"] {angle = L--O--R};
\end{tikzpicture}
\end{document}