]> hackdaworld.org Git - lectures/latex.git/commitdiff
more
authorhackbard <hackbard>
Tue, 28 Jun 2005 15:56:35 +0000 (15:56 +0000)
committerhackbard <hackbard>
Tue, 28 Jun 2005 15:56:35 +0000 (15:56 +0000)
computational_physics/cp.tex
computational_physics/fak1.c [new file with mode: 0644]
computational_physics/fak2.c [new file with mode: 0644]

index 7b52a7a3c9867b1c387ccd14a4f18a4dd8629543..a320c48f92d678157b631540eafc861a8de91000 100644 (file)
@@ -116,26 +116,47 @@ $\Rightarrow$ study and implementation of numerical algorithms
   \end{itemstep}
 \end{slide}}
 
-\overlays{3}{
-\begin{slide}{warning}
+\overlays{4}{
+\begin{slide}{warning - machine accuracy $\epsilon_m$}
   \begin{itemstep}
     \item numerical precision of 64-bit floating point \\
-          {\small ieee floating point format:} $v = -1^s 2^{-e} m$
-          \[
+          ieee floating point format: $v = -1^s 2^{-e} m$ 
+         \[
           \begin{array}{lll}
           s: & \textrm{signe} & \textrm{1 bit} \\
           m: & \textrm{mantissa} & \textrm{52 bit} \\
           e: & \textrm{exponent} & \textrm{11 bit} \\
           \end{array}
           \]
-    \item foo
-    \item bar
+    \item $\epsilon_m$: smallest floating point with $1 + \epsilon_m \neq 1$ \\
+          $\epsilon_m \approx 2 \times 10^{-18}$ \hspace{2pt} (roundoff error)
+    \item $N$ arithmetic operations $\Rightarrow$ error of order $N \epsilon_m$
+    \item subtraction of very nearly equal numbers\\
+          (difference in few significant low-order bits)
   \end{itemstep}
 \end{slide}}
 
-\begin{slide}{}
+\overlays{6}{
+\begin{slide}{warning - truncation error}
+  \begin{itemstep}
+    \item discrete approximation of continuous quantity
+    \item truncation error $\equiv$ discrepancy between true answer and practical calculation
+    \item persists even on hypothetical perfect computer ($\epsilon_m = 0$)
+    \item machine independent, characteristic of used algorithm
+    \item numerical analysis: minimizing truncation error
+    \item unstable method: roundoff error interacting at early stage
+  \end{itemstep}
+\end{slide}}
 
-\end{slide}
+\overlays{4}{
+\begin{slide}{warning - recursive functions}
+  \begin{itemstep}
+    \item avoid recursive functions!
+          \verbatiminput{fak1.c}
+    \item better:
+          \verbatiminput{fak2.c}
+  \end{itemstep}
+\end{slide}}
 
 \begin{slide}{computational techniques}
 techniques discussed in the talk:
@@ -174,4 +195,115 @@ techniques \textcolor{red}{not yet} discussed in the talk:\footnote{if time is a
 \hspace{6cm}
 \end{slide}
 
+\overlays{2}{
+\begin{slide}{rough discretization}
+  \begin{itemstep}
+    \item example: homogenous field of force $\vec{F} = (0,-mg)$ \\
+         \begin{tabular}{ll}
+         equation of motion: & $\vec{F} = m \vec{a} = m \frac{d^2 \vec{r}}{dt^2}$ \\
+         initial condition: & $\vec{r}(t=0) = \vec{r_0} = (x_0,y_0)$ \\
+                            & $\frac{d \vec{r}}{dt}|_{t=0} = (v_{x_0},v_{y_0})$ \\
+         \end{tabular}
+    \item algorithm using discretized time ($T_{total} = N \tau$):
+          \begin{tabular}{lll}
+          $x^1 = x_0;$ & $y^1 = y_0;$ & \\
+         $v^1_x = v_{x_0};$ & $v^1_y = v_{y_0};$ & \\
+         loop: & $x^2 = x^1 + \tau v^1_x;$ & $y^2 = y^1 + \tau v^1_y;$ \\
+               & $v^2_x = v^1_x;$ & $v^2_y = v^1_y + (-mg) \tau;$ \\
+               & $x^1 = x^2;$ & $y^1 = y^2$ \\
+               & $v^1_x = v^2_x;$ & $v^1_y = v^2_y;$ \\
+         \end{tabular}
+  \end{itemstep}
+\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
+%\overlays{3}{
+%\begin{slide}{}
+%  \begin{itemstep}
+%    \item 
+%    \item 
+%    \item
+%  \end{itemstep}
+%\end{slide}}
+
 \end{document}
diff --git a/computational_physics/fak1.c b/computational_physics/fak1.c
new file mode 100644 (file)
index 0000000..6031845
--- /dev/null
@@ -0,0 +1,4 @@
+int fak(n) {
+    if(n==1) return 1;
+    else return n*fak(n-1);
+}
diff --git a/computational_physics/fak2.c b/computational_physics/fak2.c
new file mode 100644 (file)
index 0000000..b749ccf
--- /dev/null
@@ -0,0 +1,8 @@
+int fak(n) {
+    int help=1;
+    while(n>1) {
+      help=help*n;
+      n=n-1;
+    }
+return help;
+}