mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
misc
This commit is contained in:
parent
b4bfde153e
commit
a9a73319a3
6 changed files with 339 additions and 5 deletions
|
@ -0,0 +1,279 @@
|
|||
\documentclass[aspectratio=169,hyperref={pdfpagelabels=false}]{beamer}
|
||||
\usepackage{lmodern}
|
||||
|
||||
\usepackage[utf8]{inputenc} % this is needed for german umlauts
|
||||
\usepackage[ngerman]{babel} % this is needed for german umlauts
|
||||
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
|
||||
|
||||
\usepackage{braket} % needed for \Set
|
||||
\usepackage{algorithm,algpseudocode}
|
||||
|
||||
\usepackage{verbatim}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{arrows,shapes}
|
||||
|
||||
% Define some styles for graphs
|
||||
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=20pt,inner sep=0pt]
|
||||
\tikzstyle{selected vertex} = [vertex, fill=red!24]
|
||||
\tikzstyle{blue vertex} = [vertex, fill=blue!24]
|
||||
\tikzstyle{edge} = [draw,thick,-]
|
||||
\tikzstyle{weight} = [font=\small]
|
||||
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
|
||||
\tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20]
|
||||
|
||||
% see http://deic.uab.es/~iblanes/beamer_gallery/index_by_theme.html
|
||||
%\usetheme{Frankfurt}
|
||||
\usefonttheme{professionalfonts}
|
||||
|
||||
% disables bottom navigation bar
|
||||
\beamertemplatenavigationsymbolsempty
|
||||
|
||||
% http://tex.stackexchange.com/questions/23727/converting-beamer-slides-to-animated-images
|
||||
\setbeamertemplate{navigation symbols}{}%
|
||||
|
||||
\newcommand{\alertline}{%
|
||||
\usebeamercolor[fg]{normal text}%
|
||||
\only{\usebeamercolor[fg]{alerted text}}}
|
||||
|
||||
|
||||
\begin{document}
|
||||
\pgfdeclarelayer{background}
|
||||
\pgfsetlayers{background,main}
|
||||
\newcommand\hlight[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=blue!50,rounded corners,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};}
|
||||
\newcommand\tocalculate[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=green!50,rounded corners,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};}
|
||||
|
||||
\begin{frame}
|
||||
\begin{minipage}[b]{0.30\linewidth}
|
||||
\centering
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
\alertline<1> L &= \alertline<1>\begin{pmatrix}
|
||||
0 & 0 & 0\\
|
||||
0 & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{minipage}
|
||||
\hspace{0.5cm}
|
||||
\begin{minipage}[b]{0.60\linewidth}
|
||||
\centering
|
||||
\begin{algorithm}[H]
|
||||
\begin{algorithmic}
|
||||
\Function{Cholesky}{$A \in \mathbb{R}^{n \times n}$}
|
||||
\alertline<1>\State $L = \Set{0} \in \mathbb{R}^{n \times n}$ \Comment{Initialisiere $L$}\\
|
||||
|
||||
\alertline<2>\alertline<4>\For{($k=1$; $\;k \leq n$; $\;k$++)}
|
||||
\alertline<3>\State $L_{k,k} = \sqrt{A_{k,k} - \sum_{i=1}^{k-1} L_{k,i}^2}$
|
||||
\For{($i=k+1$; $\;i \leq n$; $\;i$++)}
|
||||
\State $L_{i,k} = \frac{A_{i,k} - \sum_{j=1}^{k-1} L_{i,j} \cdot L_{k,j}}{L_{k,k}}$
|
||||
\EndFor
|
||||
\EndFor
|
||||
\alertline<5>\State \Return $L$
|
||||
\EndFunction
|
||||
\end{algorithmic}
|
||||
\caption{Cholesky-Zerlegung}
|
||||
\label{alg:seq1}
|
||||
\end{algorithm}
|
||||
\end{minipage}
|
||||
\end{frame}
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
\hlight{1} & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
\tocalculate{0} & 0 & 0\\
|
||||
0 & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
\tocalculate{1} & 0 & 0\\
|
||||
0 & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Calculate L_2,1
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
\hlight{2} & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
\tocalculate{0} & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
\hlight{1} & 0 & 0\\
|
||||
\tocalculate{2} & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
\tocalculate{2} & 0 & 0\\
|
||||
0 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Calculate L_3,1
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
\hlight{3} & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & 0 & 0\\
|
||||
\tocalculate{0} & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
\hlight{1} & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & 0 & 0\\
|
||||
\tocalculate{3} & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Calculate L_2,2
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & \hlight{8} & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & \tocalculate{0} & 0\\
|
||||
3 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
\hlight{2} & \tocalculate{8} & 0\\
|
||||
3 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & \tocalculate{8} & 0\\
|
||||
3 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= \hlight{4}
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & \tocalculate{4} & 0\\
|
||||
3 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
|
||||
|
||||
\begin{frame}
|
||||
\begin{align*}
|
||||
A &= \begin{pmatrix}
|
||||
1 & 2 & 3\\
|
||||
2 & 8 & 14\\
|
||||
3 & 14 & 34
|
||||
\end{pmatrix}\\
|
||||
L &= \begin{pmatrix}
|
||||
1 & 0 & 0\\
|
||||
2 & \tocalculate{2} & 0\\
|
||||
3 & 0 & 0
|
||||
\end{pmatrix}\\
|
||||
tmp &= 0
|
||||
\end{align*}
|
||||
\end{frame}
|
||||
\end{document}
|
35
source-code/Pseudocode/Cholesky-Zerlegung/Animation/Makefile
Normal file
35
source-code/Pseudocode/Cholesky-Zerlegung/Animation/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
SOURCE = Animation
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 500
|
||||
|
||||
make:
|
||||
pdflatex $(SOURCE).tex -output-format=pdf
|
||||
make clean
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
|
||||
|
||||
gif:
|
||||
pdfcrop $(SOURCE).pdf
|
||||
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
|
||||
make clean
|
||||
|
||||
png:
|
||||
make
|
||||
make svg
|
||||
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
|
||||
|
||||
transparentGif:
|
||||
convert $(SOURCE).pdf -transparent white result.gif
|
||||
make clean
|
||||
|
||||
svg:
|
||||
make
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE).svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
|
||||
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
|
||||
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
|
||||
rm $(SOURCE)2.svg
|
|
@ -0,0 +1,18 @@
|
|||
def getL(A):
|
||||
n = len(A)
|
||||
L = [[0 for i in range(n)] for j in range(n)]
|
||||
print(L)
|
||||
print("")
|
||||
|
||||
for k in range(n):
|
||||
L[k][k] = (A[k][k] - sum([L[k][i]**2 for i in range(k)]))**0.5
|
||||
for i in range(k+1, n):
|
||||
L[i][k] = (A[i][k]
|
||||
- sum([L[i][j]*L[k][j] for j in range(k)])) \
|
||||
/ L[k][k]
|
||||
print("L_%i%i = A%i%i - sum(L_...)/L_%i%i) = %i" % (i, k, i, k, k, k, L[i][k]))
|
||||
return L
|
||||
|
||||
A = [[1,2,3],[2,8,14],[3,14,34]]
|
||||
|
||||
print getL(A)
|
Loading…
Add table
Add a link
Reference in a new issue