aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-02-15 22:31:33 +0100
committerAdrian Kummerlaender2017-02-15 22:31:33 +0100
commit0efe63fd3d478c55c4aba127c68d66be5da5a57e (patch)
treeff21fd583e820f9b37b89c555582e91becffb960
parent499e86e0ef9a88a3ad96b8e842c42ea9fb6ba73f (diff)
downloadmath_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar.gz
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar.bz2
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar.lz
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar.xz
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.tar.zst
math_reference_sheets-0efe63fd3d478c55c4aba127c68d66be5da5a57e.zip
Add two example code listings
-rw-r--r--content/numerik_1.tex53
-rw-r--r--zusammenfassung.tex1
2 files changed, 53 insertions, 1 deletions
diff --git a/content/numerik_1.tex b/content/numerik_1.tex
index 98bae5b..7721889 100644
--- a/content/numerik_1.tex
+++ b/content/numerik_1.tex
@@ -566,7 +566,9 @@ Hierbei ist $h_{j+1} := t_{j+1} - t_j$ die Länge des Teilintervalls $[t_j,t_{j+
Zweimalige Intergration liefert an dieser Stelle $s_j$, die Integrationskonstanten lassen sich aus den Interpolationsbedingungen berechnen.
-\section*{Some Matlab Basics}
+\vfill
+
+\section*{Ein paar Matlab Grundlagen}
\begin{lstlisting}[frame=single,language=Matlab]
A = [ 1 0 ; 0 1 ] % = eye(2)
@@ -579,3 +581,52 @@ A(2,:) % = [ 3 1 ]
A(:,1) % = [ 1 ; 3 ]
A.^2 % = [ 1 0 ; 9 1 ]
\end{lstlisting}
+
+\subsection*{Beispiel: LR-Zerlegung}
+
+\begin{lstlisting}[frame=single,language=Matlab]
+function [A, L, R] = lr(A)
+ [w,h] = size(A);
+
+ if w ~= h
+ error('A is not a square matrix')
+ end
+
+ for k = 1:w-1
+ if abs(A(k,k)) < eps
+ error('No LU-decomposition');
+ end
+
+ A(k+1:w,k) = A(k+1:w,k) / A(k,k);
+ A(k+1:w,k+1:w) = A(k+1:w,k+1:w)
+ - A(k+1:w,k)
+ * A(k,k+1:w);
+ end
+
+ L = tril(A,-1) + eye(w);
+ R = triu(A);
+end
+\end{lstlisting}
+
+
+\subsection*{Beispiel: Vorwärtssubstitution}
+
+\begin{lstlisting}[frame=single,language=Matlab]
+function z = forwardSubstitution(L, b)
+ [w,h] = size(L);
+
+ if w ~= h
+ error('L is not a square matrix')
+ end
+
+ if length(b) ~= w
+ error('Size of b != size of L')
+ end
+
+ z = zeros(h,1);
+
+ for i = 1:h
+ z(i) = ( b(i) - L(i,:)*z ) / L(i,i);
+ end
+end
+\end{lstlisting}
diff --git a/zusammenfassung.tex b/zusammenfassung.tex
index 90c9b45..61d3a60 100644
--- a/zusammenfassung.tex
+++ b/zusammenfassung.tex
@@ -18,6 +18,7 @@
\setcounter{MaxMatrixCols}{20}
\lstset{basicstyle=\ttfamily\footnotesize}
+\lstset{showstringspaces=false}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}