Compare commits
4
Commits
77a16d71f2
...
29cb962c06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29cb962c06 | ||
|
|
e82157488c | ||
|
|
fcce9d30d6 | ||
|
|
bb73cc103e |
@@ -1,3 +1,6 @@
|
|||||||
[submodule "sose2020/ana/lectures"]
|
[submodule "sose2020/ana/lectures"]
|
||||||
path = sose2020/ana/lectures
|
path = sose2020/ana/lectures
|
||||||
url = https://git.flavigny.de/christian/ana-lecture
|
url = https://git.flavigny.de/christian/ana-lecture
|
||||||
|
[submodule "sose2020/num/hdnum"]
|
||||||
|
path = sose2020/num/hdnum
|
||||||
|
url = https://parcomp-git.iwr.uni-heidelberg.de/Teaching/hdnum
|
||||||
|
|||||||
+71
@@ -24,6 +24,7 @@
|
|||||||
\RequirePackage{totcount}
|
\RequirePackage{totcount}
|
||||||
\RequirePackage{calc}
|
\RequirePackage{calc}
|
||||||
\RequirePackage{wasysym}
|
\RequirePackage{wasysym}
|
||||||
|
\RequirePackage{environ}
|
||||||
|
|
||||||
\usetikzlibrary{quotes, angles}
|
\usetikzlibrary{quotes, angles}
|
||||||
|
|
||||||
@@ -149,3 +150,73 @@
|
|||||||
|
|
||||||
% contradiction
|
% contradiction
|
||||||
\newcommand{\contr}{\text{\Large\lightning}}
|
\newcommand{\contr}{\text{\Large\lightning}}
|
||||||
|
|
||||||
|
\ExplSyntaxOn
|
||||||
|
|
||||||
|
% S-tackrelcompatible ALIGN environment
|
||||||
|
% some might also call it the S-uper ALIGN environment
|
||||||
|
% uses regular expressions to calculate the widest stackrel
|
||||||
|
% to put additional padding on both sides of relation symbols
|
||||||
|
\NewEnviron{salign}
|
||||||
|
{
|
||||||
|
\begin{align}
|
||||||
|
\lec_insert_padding:V \BODY
|
||||||
|
\end{align}
|
||||||
|
}
|
||||||
|
% starred version that does no equation numbering
|
||||||
|
\NewEnviron{salign*}
|
||||||
|
{
|
||||||
|
\begin{align*}
|
||||||
|
\lec_insert_padding:V \BODY
|
||||||
|
\end{align*}
|
||||||
|
}
|
||||||
|
|
||||||
|
% some helper variables
|
||||||
|
\tl_new:N \l__lec_text_tl
|
||||||
|
\seq_new:N \l_lec_stackrels_seq
|
||||||
|
\int_new:N \l_stackrel_count_int
|
||||||
|
\int_new:N \l_idx_int
|
||||||
|
\box_new:N \l_tmp_box
|
||||||
|
\dim_new:N \l_tmp_dim_a
|
||||||
|
\dim_new:N \l_tmp_dim_b
|
||||||
|
\dim_new:N \l_tmp_dim_needed
|
||||||
|
|
||||||
|
% function to insert padding according to widest stackrel
|
||||||
|
\cs_new_protected:Nn \lec_insert_padding:n
|
||||||
|
{
|
||||||
|
\tl_set:Nn \l__lec_text_tl { #1 }
|
||||||
|
% get all stackrels in this align environment
|
||||||
|
\regex_extract_all:nnN { \c{stackrel}{(.*?)}{(.*?)} } { #1 } \l_lec_stackrels_seq
|
||||||
|
% get number of stackrels
|
||||||
|
\int_set:Nn \l_stackrel_count_int { \seq_count:N \l_lec_stackrels_seq }
|
||||||
|
\int_set:Nn \l_idx_int { 1 }
|
||||||
|
\dim_set:Nn \l_tmp_dim_needed { 0pt }
|
||||||
|
% iterate over stackrels
|
||||||
|
\int_while_do:nn { \l_idx_int <= \l_stackrel_count_int }
|
||||||
|
{
|
||||||
|
% calculate width of text
|
||||||
|
\hbox_set:Nn \l_tmp_box {$\seq_item:Nn \l_lec_stackrels_seq { \l_idx_int + 1 }$}
|
||||||
|
\dim_set:Nn \l_tmp_dim_a {\box_wd:N \l_tmp_box}
|
||||||
|
% calculate width of relation symbol
|
||||||
|
\hbox_set:Nn \l_tmp_box {$\seq_item:Nn \l_lec_stackrels_seq { \l_idx_int + 2 }$}
|
||||||
|
\dim_set:Nn \l_tmp_dim_b {\box_wd:N \l_tmp_box}
|
||||||
|
% check if 0.5*(a-b) > minimum padding, if yes updated minimum padding
|
||||||
|
\dim_compare:nNnTF
|
||||||
|
{ 1pt * \dim_ratio:nn { \l_tmp_dim_a - \l_tmp_dim_b } { 2pt } } > { \l_tmp_dim_needed }
|
||||||
|
{ \dim_set:Nn \l_tmp_dim_needed { 1pt * \dim_ratio:nn { \l_tmp_dim_a - \l_tmp_dim_b } { 2pt } } }
|
||||||
|
{ }
|
||||||
|
\quad
|
||||||
|
% increment list index by three, as every stackrel produces three list entries
|
||||||
|
\int_incr:N \l_idx_int
|
||||||
|
\int_incr:N \l_idx_int
|
||||||
|
\int_incr:N \l_idx_int
|
||||||
|
}
|
||||||
|
% replace all relations with align characters (&) and add the needed padding
|
||||||
|
\regex_replace_all:nnN
|
||||||
|
{ (\c{approx}&|&\c{approx}|\c{equiv}&|&\c{equiv}|=&|&=|\c{le}&|&\c{le}|\c{ge}&|&\c{ge}|&\c{stackrel}{.*?}{.*?}|\c{stackrel}{.*?}{.*?}&|&\c{neq}|\c{neq}&) }
|
||||||
|
{ \c{kern} \u{l_tmp_dim_needed} \1 \c{kern} \u{l_tmp_dim_needed} }
|
||||||
|
\l__lec_text_tl
|
||||||
|
\l__lec_text_tl
|
||||||
|
}
|
||||||
|
\cs_generate_variant:Nn \lec_insert_padding:n { V }
|
||||||
|
\ExplSyntaxOff
|
||||||
|
|||||||
+1
-1
Submodule sose2020/ana/lectures updated: e4c6c9e0fa...f4c36cb129
Submodule
+1
Submodule sose2020/num/hdnum added at 206ffcacaf
Binary file not shown.
@@ -125,8 +125,8 @@
|
|||||||
|
|
||||||
\begin{aufgabe}
|
\begin{aufgabe}
|
||||||
\begin{enumerate}[a)]
|
\begin{enumerate}[a)]
|
||||||
\item Die Matrix ist eine $N-1\times N-1$ Matrix, da eine Gleichung für jeden Knoten
|
\item Die Matrix ist eine $N^2-1 \times N^2-1$ Matrix, da eine Gleichung für jeden der $N^2$
|
||||||
bis auf den Referenzknoten existiert.
|
Knoten, bis auf den Referenzknoten existiert.
|
||||||
\item Jeder Knoten hat entweder 2 (Ecken), 3 (Außenkanten) oder 4 (im Inneren) ein oder
|
\item Jeder Knoten hat entweder 2 (Ecken), 3 (Außenkanten) oder 4 (im Inneren) ein oder
|
||||||
ausgehende Kanten. Die mit der Pumpe verbundenen Knoten, haben jeweils eine Kante mehr.
|
ausgehende Kanten. Die mit der Pumpe verbundenen Knoten, haben jeweils eine Kante mehr.
|
||||||
Die zugehörigen Zeilen haben damit immer $1$ $+$ Anzahl der verbundenen Kanten Einträge ungleich
|
Die zugehörigen Zeilen haben damit immer $1$ $+$ Anzahl der verbundenen Kanten Einträge ungleich
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,279 @@
|
|||||||
|
\documentclass[uebung]{../../../lecture}
|
||||||
|
|
||||||
|
\title{Einführung in die Numerik: Übungsblatt 4}
|
||||||
|
\author{Leon Burgard, Christian Merten}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\punkte
|
||||||
|
|
||||||
|
\begin{aufgabe}
|
||||||
|
\begin{enumerate}[a)]
|
||||||
|
\item Beh.:
|
||||||
|
\[
|
||||||
|
\Vert f \Vert_{\infty} = \max_{x \in [0,1]} |f(x)|, \quad f \in C^{0}([0,1], \R)
|
||||||
|
.\] ist eine Norm auf $C^{0}([0,1], \R)$.
|
||||||
|
\begin{proof}
|
||||||
|
Seien $f, g \in C^{0}([0,1], \R)$.
|
||||||
|
\begin{enumerate}[(N1)]
|
||||||
|
\item Es ist $\displaystyle \Vert f \Vert_{\infty} = \max_{x \in [0,1]} |f(x)| \ge 0$.
|
||||||
|
Außerdem ist
|
||||||
|
\[
|
||||||
|
\Vert f \Vert_{\infty} = 0 \implies \max_{x \in [0,1]} \underbrace{|f(x)|}_{\ge 0}
|
||||||
|
= 0 \implies f(x) = 0 \quad \forall x \in [0,1] \implies f = 0 \in C^{0}([0,1], \R)
|
||||||
|
.\]
|
||||||
|
\item Sei $\alpha \in \R$. Dann folgt
|
||||||
|
\[
|
||||||
|
\Vert \alpha f \Vert_{\infty} = \max_{x \in [0,1]} |\alpha f(x)|
|
||||||
|
= \max_{x \in [0,1]} \underbrace{|\alpha|}_{\ge 0}
|
||||||
|
\underbrace{|f(x)|}_{\ge 0}
|
||||||
|
= |\alpha| \max_{x \in [0,1]} |f(x)|
|
||||||
|
= |\alpha| \Vert f \Vert_{\infty}
|
||||||
|
.\]
|
||||||
|
\item Es ist
|
||||||
|
\[
|
||||||
|
\Vert f + g \Vert_{\infty} = \max_{x \in [0,1]} |f(x) + g(x)|
|
||||||
|
\le \max_{x \in [0,1]}
|
||||||
|
\left( \underbrace{|f(x)|}_{\ge 0} + \underbrace{|g(x)|}_{\ge 0} \right)
|
||||||
|
= \max_{x \in [0,1]} |f(x)| + \max_{x \in [0,1]} |g(x)|
|
||||||
|
= \Vert f \Vert_{\infty} + \Vert g \Vert_{\infty}
|
||||||
|
.\]
|
||||||
|
\end{enumerate}
|
||||||
|
\end{proof}
|
||||||
|
\item Beh.:
|
||||||
|
\[
|
||||||
|
\Vert f \Vert_{1} = \max_{x \in [0,1]} |f(x)|, \quad f \in C^{0}([0,1], \R)
|
||||||
|
.\] ist eine Norm auf $C^{0}([0,1], \R)$.
|
||||||
|
\begin{proof}
|
||||||
|
Seien $f, g \in C^{0}([0,1], \R)$.
|
||||||
|
\begin{enumerate}[(N1)]
|
||||||
|
\item Es ist $\displaystyle \Vert f \Vert_{1} =
|
||||||
|
\int_{0}^{1} \underbrace{|f(x)|}_{\ge 0} \d x \ge 0$.
|
||||||
|
Außerdem ist wegen der Monotonie des R.-Integrals:
|
||||||
|
\[
|
||||||
|
\Vert f \Vert_{1} = 0 \implies \int_{0}^{1} \underbrace{|f(x)|}_{\ge 0} \d x
|
||||||
|
= 0
|
||||||
|
\implies f(x) = 0 \quad \forall x \in [0,1] \implies f = 0 \in C^{0}([0,1], \R)
|
||||||
|
.\]
|
||||||
|
\item Sei $\alpha \in \R$. Dann folgt mit der Linearität des R.-Integrals
|
||||||
|
\[
|
||||||
|
\Vert \alpha f \Vert_{1}
|
||||||
|
= \int_{0}^{1} |\alpha f(x)| \d x
|
||||||
|
= \int_{0}^{1} |\alpha| |f(x)| \d x
|
||||||
|
= |\alpha| \int_{0}^{1} |f(x)| \d x
|
||||||
|
= |\alpha| \Vert f \Vert_{1}
|
||||||
|
.\]
|
||||||
|
\item Es ist
|
||||||
|
\[
|
||||||
|
\Vert f + g \Vert_{1}
|
||||||
|
= \int_{0}^{1} |f(x) + g(x)| \d x
|
||||||
|
\le \int_{0}^{1} |f(x)| \d x + \int_{0}^{1} |g(x)| \d x
|
||||||
|
= \Vert f \Vert_{1} + \Vert g \Vert_{1}
|
||||||
|
.\]
|
||||||
|
\end{enumerate}
|
||||||
|
\end{proof}
|
||||||
|
\item Für die gegebene Funktionenfolge gilt für $k \in \N$:
|
||||||
|
\[
|
||||||
|
\Vert u_k \Vert_{\infty} = \max_{x \in [0,1]} |u_k(x)|
|
||||||
|
= \max_{x \in [x_{k+1}, x_k]} \sin\left( \frac{x_k - x}{x_{k} - x_{k+1}}\pi \right) = 1
|
||||||
|
.\] Für die 1-Norm folgt
|
||||||
|
\begin{align*}
|
||||||
|
\Vert u_k \Vert_{1} &= \int_{0}^{1} u_k(x) \d x \\
|
||||||
|
&= \int_{x_{k+1}}^{x_k} \sin\left( \frac{x_k - x}{ x_k - x_{k+1} } \pi\right) \d x \\
|
||||||
|
&= \left[ \frac{x_k - x_{k+1}}{\pi} \cos\left( \frac{x_k - x}{x_k - x_{k+1}} \pi \right) \right]
|
||||||
|
\Big|_{x_{k+1}}^{x_k} \\
|
||||||
|
&= 2 \frac{x_k - x_{k+1}}{\pi}
|
||||||
|
\intertext{Mit $x_k = \frac{1}{k}$ folgt}
|
||||||
|
\Vert u_k \Vert_1 &= \frac{2}{\pi} \left( \frac{1}{k} - \frac{1}{k+1} \right) \\
|
||||||
|
&= \frac{2}{\pi} \left( \frac{1}{k^2 +k} \right) \\
|
||||||
|
&\xrightarrow{k \to \infty} 0
|
||||||
|
.\end{align*}
|
||||||
|
Beh.: $\Vert \cdot \Vert_1$ und $\Vert \cdot \Vert_\infty$ sind nicht äquivalent.
|
||||||
|
|
||||||
|
\begin{proof}
|
||||||
|
Ang.: $\Vert \cdot \Vert_1$ und $\Vert \cdot \Vert_\infty$ seien äquivalent, dann existiert
|
||||||
|
ein $m \in \R$, s.d. $\forall f \in C^{0}([0,1], \R)$ gilt
|
||||||
|
\[
|
||||||
|
m \Vert f \Vert_{\infty} \le \Vert f \Vert_1
|
||||||
|
\quad \text{also insbes.} \quad m \Vert u_{k} \Vert_{\infty} \le \Vert u_k \Vert_1
|
||||||
|
\quad \forall k \in \N
|
||||||
|
.\]
|
||||||
|
Wegen $\Vert u_k \Vert = 1$ $\forall k \in \N$, folgt also
|
||||||
|
\[
|
||||||
|
m \le \Vert u_k\Vert_1 \quad \forall k \in \N \quad \contr \text{ zu } \Vert u_k \Vert
|
||||||
|
\xrightarrow{k \to \infty} 0
|
||||||
|
.\] Also sind $\Vert \cdot \Vert_1$ und $\Vert \cdot \Vert_\infty$ nicht äquivalent.
|
||||||
|
\end{proof}
|
||||||
|
\end{enumerate}
|
||||||
|
\end{aufgabe}
|
||||||
|
|
||||||
|
\begin{aufgabe}
|
||||||
|
\begin{enumerate}[(i)]
|
||||||
|
\item Beh.: $\Vert \cdot \Vert_F$ ist eine Norm auf $\mathbb{K}^{n \times n}$.
|
||||||
|
\begin{proof}
|
||||||
|
Sei $A \in \mathbb{K}^{n \times n}$ beliebig.
|
||||||
|
\begin{enumerate}[(N1)]
|
||||||
|
\item Es ist $\displaystyle \Vert A \Vert_F = \left( \sum_{i,j=1}^{n} \underbrace{|a_{ij}|^2}_{\ge 0} \right)^{\frac{1}{2}} \ge 0 $. Außerdem gilt
|
||||||
|
\[
|
||||||
|
\Vert A \Vert_F = 0 \implies
|
||||||
|
\left(\sum_{i,j=1}^{n} \underbrace{|a_{ij}|^2}_{\ge 0} \right)^{\frac{1}{2}}
|
||||||
|
\implies a_{ij} = 0 \quad \forall i,j=1,\ldots n
|
||||||
|
\implies A = 0
|
||||||
|
.\]
|
||||||
|
\item Sei $\alpha \in \mathbb{K}$ beliebig. Dann ist
|
||||||
|
\[
|
||||||
|
\Vert \alpha A \Vert_F = \left( \sum_{i,j=1}^{n} |\alpha a_{ij}|^2 \right)^{\frac{1}{2}}
|
||||||
|
= \left( |\alpha|^2 \sum_{i,j=1}^{n} |a_{ij}|^2 \right)^{\frac{1}{2}}
|
||||||
|
= |\alpha| \Vert A \Vert_F
|
||||||
|
.\]
|
||||||
|
\item Sei $B \in \mathbb{K}^{n\times n}$. Durch Identifikation
|
||||||
|
von Matrizen aus $\mathbb{K}^{n \times n}$ mit der Frobeniusnorm
|
||||||
|
und Vektoren aus $\mathbb{K}^{n \cdot n}$ mit der Euklidschen Norm, gilt die
|
||||||
|
Cauchy-Schwarz-Ungleichung. Dann folgt
|
||||||
|
\begin{salign*}
|
||||||
|
\Vert A + B \Vert_F^2 &= \sum_{i,j=1}^{n} |a_{ij} + b_{ij}|^2 \\
|
||||||
|
&= \sum_{i,j=1}^{n} |a_{ij}^2 + 2 a_{ij}b_{ij} + b_{ij}^2| \\
|
||||||
|
&\le \sum_{i,j=1}^{n} |a_{ij}|^2 + 2\sum_{i,j=1}^{n} |a_{ij} b_{ij}|
|
||||||
|
+ \sum_{i,j=1}^{n} |b_{ij}|^2 \\
|
||||||
|
&\stackrel{\text{C.S.U.}}{\le } \Vert A \Vert_F^2
|
||||||
|
+ 2 \Vert A \Vert_F \Vert B \Vert_F + \Vert B \Vert_F^2 \\
|
||||||
|
&= \left( \Vert A \Vert_F + \Vert B \Vert_F \right)^2
|
||||||
|
.\end{salign*}
|
||||||
|
Damit folgt die Behauptung.
|
||||||
|
\end{enumerate}
|
||||||
|
\end{proof}
|
||||||
|
\item Beh.: $\forall A \in \mathbb{K}^{n \times n}$, $x \in \mathbb{K}^{n}$ gilt
|
||||||
|
\[
|
||||||
|
\Vert A x \Vert_{2} \le \Vert A \Vert_F \Vert x \Vert_2
|
||||||
|
.\]
|
||||||
|
\begin{proof}
|
||||||
|
Seien $A \in \mathbb{K}^{n \times n}$ und $x \in \mathbb{K}^{n}$ beliebig.
|
||||||
|
$A_i$ bezeichne die $i$-te Zeile der Matrix $A$.
|
||||||
|
Dann gilt
|
||||||
|
\begin{salign*}
|
||||||
|
\Vert A x \Vert_{2}^2 &= \sum_{i=1}^{n} \left( \sum_{j=1}^{n} |a_{ij}x_j| \right)^2 \\
|
||||||
|
&= \sum_{i=1}^{n} (A_i, x)_2^2 \\
|
||||||
|
&\stackrel{\text{C.S.U.}}{\le } \sum_{i=1}^{n} \Vert A_i \Vert_2^2 \Vert x \Vert_2^2 \\
|
||||||
|
&= \Vert x \Vert_2^2 \sum_{i=1}^{n} \Vert A_i \Vert_{2}^2 \\
|
||||||
|
&= \Vert x \Vert_2^2 \sum_{i=1}^{n} \sum_{j=1}^{n} |a_i|^2 \\
|
||||||
|
&= \Vert x \Vert_2^2 \Vert A \Vert_F^2
|
||||||
|
.\end{salign*}
|
||||||
|
Damit folgt die Behauptung.
|
||||||
|
\end{proof}
|
||||||
|
\item Beh.: $\forall A, B \in \mathbb{K}^{n \times n}$ gilt
|
||||||
|
\[
|
||||||
|
\Vert A B \Vert_F \le \Vert A \Vert_F \Vert B \Vert_F
|
||||||
|
.\]
|
||||||
|
\begin{proof}
|
||||||
|
Seien $A \in \mathbb{K}^{n \times n}$ und $x \in \mathbb{K}^{n}$ beliebig.
|
||||||
|
$A_i$ bezeichne die $i$-te Zeile der Matrix $A$, $B_j$ die $j$-te Spalte (!)
|
||||||
|
der Matrix $B$.
|
||||||
|
Dann gilt
|
||||||
|
\begin{salign*}
|
||||||
|
\Vert A B \Vert_{F}^2 &= \sum_{i,j=1}^{n} \left| \sum_{k=1}^{n} a_{ik}b_{kj} \right|^2 \\
|
||||||
|
&= \sum_{i,j=1}^{n} (A_i, B_j)_2^2 \\
|
||||||
|
&\stackrel{\text{C.S.U.}}{\le } \sum_{i,j=1}^{n} \Vert A_i \Vert_2^2 \Vert B_j \Vert_2^2 \\
|
||||||
|
&= \sum_{i=1}^{n} \Vert A_i \Vert_2^2 \sum_{j=1}^{n} \Vert B_j \Vert_{2}^2 \\
|
||||||
|
&= \Vert A \Vert_F \Vert B \Vert_F
|
||||||
|
.\end{salign*}
|
||||||
|
\end{proof}
|
||||||
|
\end{enumerate}
|
||||||
|
\end{aufgabe}
|
||||||
|
|
||||||
|
\begin{aufgabe}
|
||||||
|
\begin{enumerate}[a)]
|
||||||
|
\item Auszug aus \textit{rohrleitungsnetzwerk.cc}
|
||||||
|
\begin{lstlisting}[language=C++, title=Funktion zum Aufstellen der Matrix, captionpos=b]
|
||||||
|
// Funktion zum Aufstellen der Matrix
|
||||||
|
template<class NumberType>
|
||||||
|
void flussMatrix( hdnum::DenseMatrix<NumberType> &A ) {
|
||||||
|
int M( A.rowsize() );
|
||||||
|
int N( A.colsize() );
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
// Numerierung wie auf Zettel 3 nur mit 0 beginnend
|
||||||
|
// also v_0, ... ,v_(N^2-1)
|
||||||
|
// der Referenzknoten v_r hat Druck 0
|
||||||
|
|
||||||
|
// berechnung der kantenlaenge
|
||||||
|
int n = floor(sqrt(N+1));
|
||||||
|
|
||||||
|
for(int i = 0; i < N; i++) {
|
||||||
|
int edges = 0;
|
||||||
|
if ((i+1)%n != 0) { // nicht linker rand
|
||||||
|
edges++;
|
||||||
|
if (i-1 >= 0) A(i, i-1) = -1; // falls nicht der referenzknoten
|
||||||
|
}
|
||||||
|
if ((i+2)%n != 0) { // nicht rechter rand
|
||||||
|
edges++;
|
||||||
|
A(i, i+1) = -1;
|
||||||
|
}
|
||||||
|
if (i+n < N) { // nicht unterer rand
|
||||||
|
edges++;
|
||||||
|
A(i, i+n) = -1;
|
||||||
|
}
|
||||||
|
if (i-n >= -1) { // nicht oberer rand
|
||||||
|
edges++;
|
||||||
|
if (i-n >= 0) A(i, i-n) = -1; // falls nicht der referenzknoten
|
||||||
|
}
|
||||||
|
A(i, i) = edges;
|
||||||
|
}
|
||||||
|
}\end{lstlisting}
|
||||||
|
\item In \lstinline{DenseMatrix} sind schon die Zeilen- und Spaltensummennorm definiert.
|
||||||
|
Auszug aus \textit{rohrleitungsnetzwerk.cc}
|
||||||
|
|
||||||
|
\begin{lstlisting}[language=C++, title=Frobeniusnorm, captionpos=b]
|
||||||
|
// Funktion zur Berechnung der Frobenius-Norm einer Matrix
|
||||||
|
template<class NumberType>
|
||||||
|
NumberType frobeniusNorm(const hdnum::DenseMatrix<NumberType> &A) {
|
||||||
|
// Error checking
|
||||||
|
int M(A.rowsize());
|
||||||
|
int N(A.colsize());
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
NumberType result=0.0;
|
||||||
|
|
||||||
|
// iteriere ueber alle zeilen und spalten, quadriere die elemente und summiere
|
||||||
|
for (int i=0; i < N; i++) {
|
||||||
|
for (int j=0; j < N; j++) {
|
||||||
|
result += pow(A(i,j), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ziehe wurzel aus summe
|
||||||
|
return sqrt(result);
|
||||||
|
}\end{lstlisting}
|
||||||
|
|
||||||
|
\item Auszug aus \textit{rohrleitungsnetzwerk.cc}
|
||||||
|
\begin{lstlisting}[language=C++, title=Eigenwertberechnung, captionpos=b]
|
||||||
|
// Funktion zur Berechnung des betragsgrößten Eigenwertes mit Potenzmethode
|
||||||
|
template<class NumberType>
|
||||||
|
NumberType maxEigenwert(const hdnum::DenseMatrix<NumberType> &A) {
|
||||||
|
// Error checking
|
||||||
|
int M(A.rowsize());
|
||||||
|
int N(A.colsize());
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
// start vektor
|
||||||
|
hdnum::Vector<NumberType> r(N);
|
||||||
|
r[0] = 1;
|
||||||
|
// work copy
|
||||||
|
hdnum::Vector<NumberType> r_tmp(N);
|
||||||
|
hdnum::Vector<NumberType> diff(N);
|
||||||
|
// fuehre iterationsschritt 10000 mal aus
|
||||||
|
for (int k=0; k<10000; k++) {
|
||||||
|
A.mv(r_tmp, r); // r_tmp = Ar
|
||||||
|
r_tmp /= r_tmp.two_norm(); // normiere r_tmp
|
||||||
|
r = r_tmp;
|
||||||
|
}
|
||||||
|
A.mv(r_tmp, r);
|
||||||
|
// berechne eigenwert mit rayleigh quotient
|
||||||
|
return (r * r_tmp)/r.two_norm_2();
|
||||||
|
}\end{lstlisting}
|
||||||
|
\end{enumerate}
|
||||||
|
\end{aufgabe}
|
||||||
|
|
||||||
|
\end{document}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
// Kompilieren mit:
|
||||||
|
//
|
||||||
|
// g++ -I../hdnum/ -o rohrleitungsnetzwerk rohrleitungsnetzwerk.cc
|
||||||
|
//
|
||||||
|
// Das setzt voraus, dass ihr Programm in einem Ordner parallel zur
|
||||||
|
// entpackten HDNum Bibliothek liegt.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include "hdnum.hh"
|
||||||
|
|
||||||
|
|
||||||
|
// Funktion zum Aufstellen der Matrix
|
||||||
|
template<class NumberType>
|
||||||
|
void flussMatrix( hdnum::DenseMatrix<NumberType> &A ) {
|
||||||
|
int M( A.rowsize() );
|
||||||
|
int N( A.colsize() );
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
// Numerierung wie auf Zettel 3 nur mit 0 beginnend
|
||||||
|
// also v_0, ... ,v_(N^2-1)
|
||||||
|
// der Referenzknoten v_r hat Druck 0
|
||||||
|
|
||||||
|
// berechnung der kantenlaenge
|
||||||
|
int n = floor(sqrt(N+1));
|
||||||
|
|
||||||
|
for(int i = 0; i < N; i++) {
|
||||||
|
int edges = 0;
|
||||||
|
if ((i+1)%n != 0) { // nicht linker rand
|
||||||
|
edges++;
|
||||||
|
if (i-1 >= 0) A(i, i-1) = -1; // falls nicht der referenzknoten
|
||||||
|
}
|
||||||
|
if ((i+2)%n != 0) { // nicht rechter rand
|
||||||
|
edges++;
|
||||||
|
A(i, i+1) = -1;
|
||||||
|
}
|
||||||
|
if (i+n < N) { // nicht unterer rand
|
||||||
|
edges++;
|
||||||
|
A(i, i+n) = -1;
|
||||||
|
}
|
||||||
|
if (i-n >= -1) { // nicht oberer rand
|
||||||
|
edges++;
|
||||||
|
if (i-n >= 0) A(i, i-n) = -1; // falls nicht der referenzknoten
|
||||||
|
}
|
||||||
|
A(i, i) = edges;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Funktion zur Berechnung der Frobenius-Norm einer Matrix
|
||||||
|
template<class NumberType>
|
||||||
|
NumberType frobeniusNorm(const hdnum::DenseMatrix<NumberType> &A) {
|
||||||
|
// Error checking
|
||||||
|
int M(A.rowsize());
|
||||||
|
int N(A.colsize());
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
NumberType result=0.0;
|
||||||
|
|
||||||
|
// iteriere ueber alle zeilen und spalten, quadriere die elemente und summiere
|
||||||
|
for (int i=0; i < N; i++) {
|
||||||
|
for (int j=0; j < N; j++) {
|
||||||
|
result += pow(A(i,j), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ziehe wurzel aus summe
|
||||||
|
return sqrt(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Funktion zur Berechnung des betragsgrößten Eigenwertes mit Potenzmethode
|
||||||
|
template<class NumberType>
|
||||||
|
NumberType maxEigenwert(const hdnum::DenseMatrix<NumberType> &A) {
|
||||||
|
// Error checking
|
||||||
|
int M(A.rowsize());
|
||||||
|
int N(A.colsize());
|
||||||
|
if(M!=N)
|
||||||
|
HDNUM_ERROR("Matrix muss quadratisch sein!");
|
||||||
|
|
||||||
|
// start vektor
|
||||||
|
hdnum::Vector<NumberType> r(N);
|
||||||
|
r[0] = 1;
|
||||||
|
// work copy
|
||||||
|
hdnum::Vector<NumberType> r_tmp(N);
|
||||||
|
hdnum::Vector<NumberType> diff(N);
|
||||||
|
// fuehre iterationsschritt 10000 mal aus
|
||||||
|
for (int k=0; k<10000; k++) {
|
||||||
|
A.mv(r_tmp, r); // r_tmp = Ar
|
||||||
|
r_tmp /= r_tmp.two_norm(); // normiere r_tmp
|
||||||
|
r = r_tmp;
|
||||||
|
}
|
||||||
|
A.mv(r_tmp, r);
|
||||||
|
// berechne eigenwert mit rayleigh quotient
|
||||||
|
return (r * r_tmp)/r.two_norm_2();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hauptprogramm
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Anzahl der Knoten
|
||||||
|
const int N(10);
|
||||||
|
std::cout << "Knotenanzahl N: " << N << std::endl;
|
||||||
|
|
||||||
|
// Größe der Matrix
|
||||||
|
const int n(N*N-1);
|
||||||
|
|
||||||
|
// Datentyp für die Matrix
|
||||||
|
typedef double REAL;
|
||||||
|
|
||||||
|
// Matrix initialisieren
|
||||||
|
hdnum::DenseMatrix<REAL> A(n,n);
|
||||||
|
|
||||||
|
// Pretty-printing einmal setzen für alle Matrizen
|
||||||
|
A.scientific(false);
|
||||||
|
A.width(15);
|
||||||
|
|
||||||
|
flussMatrix(A);
|
||||||
|
if (N<=4)
|
||||||
|
std::cout << A << std::endl;
|
||||||
|
|
||||||
|
// Bei Schwierigkeiten mit Teilaufgabe a) können Sie Teilaufgaben b)
|
||||||
|
// und c) mit folgender Matrix testen
|
||||||
|
int size_b = 3;
|
||||||
|
hdnum::DenseMatrix<REAL> B(size_b,size_b);
|
||||||
|
for (std::size_t i=0; i<size_b; ++i)
|
||||||
|
{
|
||||||
|
for (std::size_t j=0; j<size_b; ++j)
|
||||||
|
{
|
||||||
|
B[i][j] = i+j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "Zeilen-Summen-Norm: " << A.norm_infty() << std::endl;
|
||||||
|
std::cout << "Spalten-Summen-Norm: " << A.norm_1() << std::endl;
|
||||||
|
std::cout << "Frobenius-Norm: " << frobeniusNorm(A) << std::endl;
|
||||||
|
std::cout << "Maximaler Eigenwert: " << maxEigenwert(A) << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user