├── .gitignore ├── .travis.yml ├── Makefile ├── ana1 ├── ana.ora ├── ana1.org ├── cheatsheet │ └── cheatsheet.tex ├── complex_numbers.org ├── continous_functions.org ├── differential_calculus.org ├── introduction.org ├── sequence.org ├── series.org ├── sets.org └── tutorial │ ├── Uebungsblatt_0.pdf_ignore │ ├── fetch.sh │ └── link ├── ana2 ├── ana2.org ├── differentiation.org ├── lebesque_integration.org ├── metric_norm.org ├── ordinary_differential_equations.org └── tutorial │ └── fetch.sh ├── ana3 ├── ana3.org └── tutorial │ ├── 01.org │ └── 02.org ├── bib.bib ├── compile.sh ├── cp0 ├── cp0.org └── tutorial │ ├── 1 │ ├── 01_cp_1_heinemann_rosendahl_rall.pdf │ ├── 02_cp_1_heinemann_rosendahl_rall.pdf │ ├── cp_1_heinemann_rosendahl_rall.pdf │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── header.org │ ├── integrand-eps-converted-to.pdf │ └── test-eps-converted-to.pdf │ ├── 2 │ ├── cp_2_heinemann_rosendahl_rall.pdf │ ├── euler_1-eps-converted-to.pdf │ ├── euler_2-eps-converted-to.pdf │ ├── euler_3-eps-converted-to.pdf │ ├── euler_4_1-eps-converted-to.pdf │ ├── euler_4_2-eps-converted-to.pdf │ ├── euler_4_3-eps-converted-to.pdf │ ├── euler_e-eps-converted-to.pdf │ ├── euler_error-eps-converted-to.pdf │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── header.org │ ├── leapfrog_error-eps-converted-to.pdf │ └── vverlet_error-eps-converted-to.pdf │ ├── 3 │ ├── dist-eps-converted-to.pdf │ ├── energy-eps-converted-to.pdf │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── figure_eight-eps-converted-to.pdf │ ├── header.org │ ├── traj_3-eps-converted-to.pdf │ ├── traj_4-eps-converted-to.pdf │ └── traj_5-eps-converted-to.pdf │ ├── 4 │ ├── eps-eps-converted-to.pdf │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ └── header.org │ ├── 5 │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ └── header.org │ ├── 6 │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ └── header.org │ ├── 7 │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ └── header.org │ ├── 8 │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── header.org │ └── plot.pdf │ ├── 9 │ ├── 05xy-eps-converted-to.pdf │ ├── 05xz-eps-converted-to.pdf │ ├── 115xy-eps-converted-to.pdf │ ├── 115xz-eps-converted-to.pdf │ ├── 13456xy-eps-converted-to.pdf │ ├── 13456xz-eps-converted-to.pdf │ ├── 235xy-eps-converted-to.pdf │ ├── 235xz-eps-converted-to.pdf │ ├── 26_full-eps-converted-to.pdf │ ├── 26_reduced-eps-converted-to.pdf │ ├── 29xy-eps-converted-to.pdf │ ├── 29xz-eps-converted-to.pdf │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ └── header.org │ ├── 10 │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── header.org │ ├── hist_100.pdf │ ├── hist_10000.pdf │ ├── hist_1000000.pdf │ ├── hist_10000000.pdf │ └── pi-eps-converted-to.pdf │ ├── .gitignore │ ├── header.org │ └── template │ ├── exercise.org │ ├── exercise.pdf │ ├── exercise_pre.pdf │ ├── header.org │ ├── integrand-eps-converted-to.pdf │ └── test-eps-converted-to.pdf ├── deploy.sh ├── emacs_config.el ├── ex1 ├── cheatsheet │ └── cheatsheet.tex ├── collisions.org ├── conservation_laws.org ├── deformation.org ├── ex1.ora ├── ex1.org ├── forcelaws.org ├── free_rotation.org ├── introduction.org ├── mechanics.org ├── ridid_body.org ├── system_mass_points.org ├── thermodynamics.org ├── tutorial │ ├── fetch.sh │ ├── link │ └── notes │ │ ├── tutorial.ora │ │ └── tutorial.org └── work_energy_power.org ├── ex2 ├── ac.org ├── cheatsheet │ └── cheatsheet.tex ├── electromagnetic_waves.org ├── electrostatics.org ├── ex2.org ├── induction.org ├── magnetostatics.org ├── mass_in_b_field.org └── tutorial │ └── fetch.sh ├── ex3 ├── cheatsheet │ └── cheatsheet.tex ├── ex3.org └── tutorial │ ├── 6 │ ├── Untitled.ipynb │ └── p │ ├── 7 │ └── Untitled.ipynb │ ├── 8 │ └── Untitled.ipynb │ ├── 9 │ └── Untitled.ipynb │ └── 10 │ ├── qmfdm │ ├── cy.py │ └── qmfdm.py │ └── ssfm │ └── ssfm.py ├── ex4 ├── cheatsheet │ ├── cheatsheet.tex │ └── cheatsheet_t.tex └── ex4.org ├── ex5 ├── demos │ └── grid_dynamics.py ├── ex5.org └── tutorial │ ├── 1.art │ ├── 10.gnuplot │ ├── 11.art │ ├── 12.art │ ├── 12.py │ ├── 2.art │ ├── 3.art │ ├── 5.art │ ├── 6.art │ ├── 6_ewald.png │ ├── 6_ewald.svg │ ├── 6_ewald.svg.2018_11_29_21_10_14.0.svg │ ├── 6_ewald.svg.2018_11_29_21_10_43.0.svg │ ├── 6_ewald.svg.2018_11_29_21_11_12.0.svg │ ├── 7.art │ ├── 8.art │ ├── 9.art │ ├── 9.py │ ├── __pycache__ │ └── constant.cpython-36.pyc │ ├── black.art │ ├── blatt_5.jpg │ ├── blatt_5.png │ ├── brillouin.png │ ├── brillouin.svg │ └── constant.py ├── header_common.org ├── header_de.org ├── header_en.org ├── ipi ├── container.org ├── datatypes.org ├── differences.org ├── functional_programming.org ├── introduction.org ├── ipi.org ├── itertators.org ├── machine_code.org ├── procedural_programming.org ├── references.org ├── stack_model.org ├── substitution_model.org └── tutorial │ ├── 10 │ ├── image.cpp │ ├── image.hpp │ ├── kaleidoscope.cpp │ └── point.cpp │ ├── 11 │ ├── conway.cpp │ ├── image.hpp │ ├── my_simulation.mpg │ ├── point_template.cpp │ ├── polynomial.cpp │ └── simulation.mpg │ ├── 12 │ ├── image.hpp │ ├── image_rgb.hpp │ ├── koordinaten.cpp │ └── mandelbrot.cpp │ ├── 01 │ ├── 01.org │ ├── 1.tikz │ └── Heinemann.zip │ ├── 03 │ ├── common.h │ ├── ostern.cpp │ ├── potenz.cpp │ ├── sinus.cpp │ └── weekday.cpp │ ├── 04 │ ├── common.h │ ├── email.cpp │ ├── kubikwurzel.cpp │ ├── kubikwurzel.org │ ├── palindrom.cpp │ └── pythagoras.cpp │ ├── 05 │ ├── common.h │ ├── mix.cpp │ ├── ordered_insert.cpp │ ├── perfect_shuffle.cpp │ └── text.hpp │ ├── 06 │ ├── common.h │ ├── decrypt.cpp │ ├── decrypted_text.txt │ ├── encrypted_text.txt │ ├── format_numbers.cpp │ ├── format_numbers.hpp │ ├── sort_versions.cpp │ └── sort_versions.hpp │ ├── 07 │ ├── UB7.org │ ├── common.h │ └── sort_template.cpp │ ├── 08 │ ├── UB8.org │ ├── archimedes.cpp │ ├── common.h │ └── perfect_shuffle_to_k.cpp │ ├── 09 │ ├── draw.py │ ├── gifts.cpp │ ├── gifts.txt │ ├── rec.cpp │ ├── rectangle.cpp │ └── rectangle.png │ ├── link │ └── tutorial ├── keys.enc ├── la1 ├── algebra.org ├── basics.org ├── basis_change.org ├── basis_dimension.org ├── determinants.org ├── introduction.org ├── la1.org ├── linear_map.org ├── linear_systems.org ├── linear_systems_matrices.org ├── matrix.org ├── polynomial.org ├── quotient_space.org ├── sub_vector_space.org ├── tutorial │ ├── 12 │ │ ├── solution.dvi │ │ └── solution.org │ ├── fetch.sh │ └── link └── vector_space.org ├── la2 ├── bilinear_form.org ├── divisibility.org ├── dual_vector.org ├── eigen_values.org ├── euclidean_rings.org ├── euclidic_groups.org ├── inner_product_space.org ├── la2.org ├── orthogonal_group.org ├── quadratic_groups.org ├── spectral_theorem.org └── tutorial │ └── fetch.sh ├── math_introduction └── math_introduction.org ├── mmp1 ├── cheatsheet │ └── cheatsheet.tex └── mmp1.org ├── numerik ├── error_analysis.org ├── interpolation_approximation.org ├── introduction.org ├── linear_systems.org ├── nonlinear_system.org ├── numeric_integration.org ├── numerik.org └── tutorial │ ├── Lagrange_Interpolation.ipynb │ ├── blatt01.ipynb │ ├── blatt01.org │ ├── blatt02.ipynb │ ├── blatt03.ipynb │ ├── blatt04.ipynb │ ├── blatt06.ipynb │ ├── blatt07.ipynb │ ├── blatt08.ipynb │ ├── blatt10.ipynb │ └── fetch.sh ├── theo1 ├── central_forces.org ├── collision.org ├── conservation_laws.org ├── expanded_gravitation.org ├── harmonic_oscillator.org ├── mass_points.org ├── newton_mechanics.org ├── overview.org ├── pseudo_forces.org ├── symmetries.org ├── theo.ora ├── theo1.ora ├── theo1.org └── tutorial │ ├── UB0.pdf_ignore │ └── fetch.sh ├── theo2 ├── canonic_transformation_integrability_chaos.org ├── d_alembert.org ├── differential_forms_hamilton.org ├── hamilton.org ├── inertia_tensor.org ├── lagrange_variation.org ├── oscillations.org ├── poisson_bracket.org ├── spinning_tops.org ├── symmetries_conservation_laws.org ├── theo2.org └── tutorial │ └── fetch.sh ├── theo3 ├── theo3.org └── tutorial │ ├── 03.ora │ └── 03.png ├── theo4 └── theo4.org └── tsp ├── tsp.org └── tutorial ├── 1.kra ├── 10.art ├── 11.art ├── 2.art ├── 3.art ├── 5.art ├── 7.art ├── 8.art ├── 9.art └── black.art /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | *blx.bib 3 | ltximg 4 | *.thm 5 | *.log 6 | *.lof 7 | *.aux 8 | *.gz 9 | *.lot 10 | *.out 11 | *.bbl 12 | *.blg 13 | *.toc 14 | *.bcf 15 | *.bbl 16 | *.run.xml 17 | *.fdb_latexmk 18 | *.fls 19 | *.ora~ 20 | *.bak 21 | 22 | \#*\# 23 | /.emacs.desktop 24 | /.emacs.desktop.lock 25 | *.elc 26 | auto-save-list 27 | tramp 28 | .\#* 29 | 30 | _minted* 31 | secrets 32 | cookies.txt 33 | *.swp 34 | *\~ 35 | bin 36 | pages 37 | pdfs 38 | *.tex 39 | *.tex~ 40 | *.pdf 41 | pdf_key 42 | *.pg 43 | *.pgm 44 | *.xdv 45 | *.new 46 | *.mp4 47 | 48 | !*/cheatsheet/*.tex 49 | 50 | # lectures with no content 51 | vlsi 52 | astro1 53 | astro2 54 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | group: deprecated-2017Q2 2 | dist: trusty 3 | sudo: required 4 | before_script: 5 | - sudo add-apt-repository -y ppa:ubuntu-elisp/ppa 6 | - sudo apt-get update -qq 7 | - sudo apt-get install --force-yes emacs-snapshot emacs-snapshot-el texinfo 8 | 9 | - emacs --version 10 | install: 11 | - sudo apt-get install python-pygments realpath 12 | script: bash ./deploy.sh 13 | env: 14 | global: 15 | - COMMIT_AUTHOR_EMAIL: "robin.ole.heinemann@t-online.de" 16 | language: generic 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) 2 | tex_files = $(call rwildcard, , *.tex) 3 | pdf_files = $(tex_files:.tex=.pdf) 4 | pdf_files_continous = $(tex_files:.tex=.pdfc) 5 | clean_files = $(tex_files:.tex=.does_not_exist) 6 | 7 | .PHONY : FORCE_MAKE 8 | 9 | %.does_not_exist: %.tex 10 | latexmk --pdf -cd -c -pdflatex="lualatex -8bit %O %S" $< 11 | 12 | %.pdf: %.tex FORCE_MAKE 13 | # latexmk -lualatex -cd --silent --shell-escape -pdflatex="lualatex -8bit %O %S" $< 14 | latexmk --pdf -cd --shell-escape -pdflatex="lualatex -8bit %O %S" $< 15 | # latexmk -lualatex -cd -c -pdflatex="lualatex -8bit %O %S" $< 16 | 17 | all: $(pdf_files) 18 | 19 | %.pdfc: %.tex 20 | latexmk --pdf -cd --interaction=nonstopmode -pvc --shell-escape -pdflatex="lualatex -8bit %O %S" $< 21 | 22 | continuous: $(pdf_files_continous) 23 | 24 | .PHONY: clean clobber 25 | clean: $(clean_files) 26 | find . -mindepth 2 -maxdepth 2 -name '*.pdf' -delete 27 | 28 | clobber: $(clean_files) 29 | -------------------------------------------------------------------------------- /ana1/ana.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ana1/ana.ora -------------------------------------------------------------------------------- /ana1/complex_numbers.org: -------------------------------------------------------------------------------- 1 | * Komplexe Zahlen 2 | *Motivation:* $x^2 + 1 = 0$ nicht lösbar in $\mathbb{R}$ \\ 3 | Wir betrachten die Menge der Paare $\{x,y\} = \mathbb{R}\times\mathbb{R}$ auf denen die Addition und Multiplikation wie folgt definiert ist: 4 | - <> (KA) $\{x_1,y_1\} + \{x_2,y_2\} = \{x_1 + x_2, y_2 + y_2\}$ 5 | - <> (KM) $\{x_1,y_1\} \cdot \{x_2,y_2\} = \{x_1 x_2 - y_1 y_2, x_1 y_2 + x_2 y_1\}$ 6 | ** Komplexer Zahlenkörper 7 | 1. Die Menge der Paare $z = \{x,y\} \in \mathbb{R}\times\mathbb{R}$ mit Addition [[KA]] und Multiplikation [[KM]] bildet den Körper $\mathbb{C}$ der *komplexen Zahlen* mit den neutralen Elementen $\{0,0\}$ und $\{1,0\}$ 8 | 2. Die Gleichung $z^2 + \{1,0\} = \{0,0\}$ hat in $\mathbb{C}$ zwei Lösungen, welche mit $\I:= \{0,\pm 1\}$ bezeichnet werden 9 | 3. Der Körper $\mathbb{R}$ ist mit der Abbildung $x\in\mathbb{R}:x\mapsto\{x,0\}\in\mathbb{C}$ isomorph zu einem Unterkörper von $\mathbb{C}$ 10 | *** Beweis 11 | 1. Die Gültigkeit des Kommutativitäts-, Assoziativs-, und Distributivitätsgesetzes verifiziert man durch Nachrechnen. \\ 12 | Neutrale Elemente: Wir lösen die Gleichung $a + z = \{0,0\}$ für beliebige gegebene $a\in\mathbb{C},a=\{a_1,a_2\}$ 13 | \[\implies z = \{-a_1, -a_2\}\] 14 | \[a\cdot z = \{1,0\}\] 15 | \[z = \frac{1}{a}:=\{\frac{a_1}{a_1^2 + a_2^2},-\frac{a_2}{a_1^2 + a_2^2}\},~\text{weil}~a\cdot\frac{1}{a}\] 16 | \[\text{weil}~a\frac{1}{a}=\{a_1\frac{a_1}{a_1^2 + a_2^2} + \frac{a_2^2}{a_1^2 + a_2^2},\frac{a_1 a_2}{a_1^2 + a_2^2} - \frac{a_2 a_1}{a_1^2 + a_2^2}\}\] 17 | 2. $i:= \{0,1\}$ hat die Eigenschaft 18 | \[1 + \I^2 = \{1,0\} + \{0^2 - 1^2, 0\} = \{0,0\} \implies 1+\I^2 = 0\] 19 | Ähnlich $1 + (-\I)^2 = 0$ 20 | 3. Die Zuordnung $x\in\mathbb{R}:x\mapsto\{x,0\}\in\mathbb{C}$ bildet $\mathbb{R}$ bijektiv auf eine Untermenge von $\mathbb{C}$ ab, welche bezüglich der komplexen Addition und Multiplikation wieder ein Körper ist $\hfill\square$ 21 | ** Notation 22 | $z = \{x,y\} =: x + \I y,~x,y\in\mathbb{R}$ 23 | - $x$ ist Realteil $x = \Re{z}$ 24 | - $y$ ist Imaginärteil $x = \Im{z}$ 25 | \[z_1 + z_2 = (x_1 + \I y_1) + (x_2 + \I y_2) = \underbrace{x_1 + x_2}_{\Re (z_1 + z_2)} + \I\underbrace{(y_1 + y_2)}_{\Im (z_1 + z_2)}\] 26 | \[z_1 z_2 = (x_1 + \I y_1)(x_1 + \I y_2) = x_1 x_2 + \I y_1 x_2 + \I y_2 x_1 + (\I y_1)(\I y_2) = \underbrace{x_1 x_2 - y_1 y_2}_{\Re (z_1 z_2)} + \I\underbrace{(x_1y_2 + y_1 x_2)}_{\Im (z_1,z_2)}\] 27 | ** TODO Graphische Darstellung 28 | ** Bemerkung 29 | Die reellen Zahlen sind durch $\Im z = 0$ charakterisiert. 30 | \[z_1 = z_2 \implies x_1 + \I y_i = x_2 + \I y_2 \iff x_1 = x_2,y_1 = y_2\] 31 | ** Korollar 1.59 32 | Jede quadratische Gleichung 33 | \[z^2+p z + q = 0,~p,q\in\mathbb{R}\] 34 | besitzt in $\mathbb{C}$ genau zwei Lösungen 35 | \[z_{1,2} = \begin{cases} -\frac{1}{2}\pm \frac{1}{2}\sqrt{p^2 - 4q} & p^2 \geq 4q \\ -\frac{1}{2}\pm \I\frac{1}{2}\sqrt{\abs{p^2 - 4q}} & p^2 - 4q < 0 \end{cases} \] 36 | ** Fundamentalsatz der Algebra 37 | Jede algebraische Gleichung der Form \[z^n + \sum_{i = 0}^{n - 1} a_i z^i = 0\] 38 | hat in $\mathbb{C}$ mindestens eine Lösung. Beweis \rightarrow Funktionstheorie 39 | ** Betrag 40 | Für komplexe Zahlen lässt sich ein Absolutbetrag definieren 41 | \[r = \abs{z} = \sqrt{x^2 + y^2}\] 42 | Damit: 43 | \begin{align} 44 | x &=& r\cos{\alpha} \\ 45 | y &=& r\sin{\alpha} \\ 46 | z &=& x + \I y = r(\cos{\alpha} + \I\sin{\alpha}) \\ 47 | \end{align} 48 | ** Konjugation 49 | Zu einem $z = x + \I y\in\mathbb{C}$ definieren wir eine konjugierte komplexe Zahl \[\bar z = x - \I y \in\mathbb{C}\] 50 | Dann gilt \[\abs{z}^2 = x^2 + y^2 = z\bar z\] 51 | Aus der Definition: 52 | - $\overline{z_1 + z_2} = \overline{z_1} + \overline{z_2}$ 53 | - $\overline{z_1 * z_2} = \overline{z_1} * \overline{z_2}$ 54 | - $x = \frac{z + \bar z}{2}$ 55 | - $y = \frac{z - \bar z}{2\I}$ 56 | -------------------------------------------------------------------------------- /ana1/introduction.org: -------------------------------------------------------------------------------- 1 | * Einleitung 2 | Webseite www.biostruct.uni-heidelberg.de/Analysis1.php 3 | Klausurzulassung: 50% 4 | Klausur 18.2.2017 9-12Uhr 5 | -------------------------------------------------------------------------------- /ana1/tutorial/Uebungsblatt_0.pdf_ignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ana1/tutorial/Uebungsblatt_0.pdf_ignore -------------------------------------------------------------------------------- /ana1/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `seq 1 15`; 3 | do 4 | wget -O Uebungsblatt_$i.pdf http://www.biostruct.uni-hd.de/pdffileAnalysis1/Uebungsblatt_$i.pdf 5 | done 6 | find . -size 0 -delete 7 | -------------------------------------------------------------------------------- /ana1/tutorial/link: -------------------------------------------------------------------------------- 1 | http://www.biostruct.uni-hd.de/Analysis1.php 2 | -------------------------------------------------------------------------------- /ana2/ana2.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Analysis II (Marciniak-Czochra) 3 | 4 | #+INCLUDE: "../header_de.org" :minlevel 1 5 | #+LATEX_HEADER: \theoremsymbol{} 6 | #+LATEX_HEADER: \theoremstyle{nonumberplain} 7 | #+LATEX_HEADER: \renewtheorem{remark}{Bemerkung} 8 | #+LATEX_HEADER: \theoremstyle{} 9 | #+LATEX_HEADER: \renewtheorem*{ex*}{Beispiel} 10 | 11 | #+INCLUDE: "metric_norm.org" :minlevel 1 12 | #+INCLUDE: "differentiation.org" :minlevel 1 13 | #+INCLUDE: "ordinary_differential_equations.org" :minlevel 1 14 | #+INCLUDE: "lebesque_integration.org" :minlevel 1 15 | -------------------------------------------------------------------------------- /ana2/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `seq 1 15`; 3 | do 4 | wget -O Uebungsblatt_$i.pdf http://www.biostruct.uni-hd.de/pdffileAnalysis1/Uebungsblatt_$i.pdf 5 | done 6 | find . -size 0 -delete 7 | -------------------------------------------------------------------------------- /ana3/tutorial/01.org: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | a 4 | \[X = \{1,2,3,4\}\] 5 | \[\mathcal{D} = \{\emptyset, X, \{1,2\}, \{3,4\}, \{1,3\}, \{2,4\}\}\] 6 | b 7 | $Ω := ℕ$ 8 | \[\mathcal{A}:= \{A ⊆ Ω \mid A \text{ endlich oder } A^C \text{ endlich}\}\] 9 | zz. $\mathcal{A}$ ist Algebra aber keine \(σ\)-Algebra 10 | #+begin_proof latex 11 | - $ℕ ∈ \mathcal{A}$, denn $ℕ^C = \emptyset$ endlich 12 | - $A ∈ \mathcal{A} ⇒ A^C ∈ A$ trivial 13 | - $A, B ∈ \mathcal{A}$, dann ist 14 | - für $A, B$ endlich auch $(A ∪ B)$ endlich 15 | - für (ohne Beschränkung der Allgemeinheit) $A^C$ endlich ist 16 | \[(A ∪ B) = (\underbrace{A^C ∩ B^C}_{\text{endlich}})^C\] 17 | $⇒$ $A ∪ B ∈ \mathcal{A}$ 18 | $⇒$ $\mathcal{A}$ ist Algebra. \\ 19 | Aber betrachte die Folgle 20 | \[(A_n)_{n ∈ ℕ} = (\{2n\}_{n ∈ ℕ}) ⊆ \mathcal{A}\] 21 | $⇒ \bigcup_{n ∈ ℕ} A_n = 2ℕ$ ist unendlich und $(2ℕ)^C$ ist ebenfalls unendlich. Also ist $A$ keine \(σ\)-Algebra 22 | #+end_proof 23 | c 24 | \(f: Ω \to Ω', \mathcal{A}' σ\)-Algebra auf $Ω'$ \\ 25 | zz: 26 | \[f^{-1}(\mathcal{A}') := \{f^{-1}(A) \mid A ∈ \mathcal{A}'\}\] 27 | ist \(σ\)-Algebra auf $Ω$. 28 | #+begin_proof latex 29 | - $Ω ∈ f^{-1}(\mathcal{A}')$, denn $Ω = f^{-1}(Ω')$ und $Ω' ∈ \mathcal{A}'$ (\(σ\)-Algebra) 30 | - $A ⊂ f^{-1}(\mathcal{A}') ⇒ ∃ A' ∈ \mathcal{A}': A = f^{-1}(A')$ 31 | \[⇒ A^C = f^{-1}(A')^C = f^{-1}(A^{\prime C}) ∈ f^{-1}(\mathcal{A}')\] 32 | denn $A^{\prime C} ⊂ \mathcal{A}'$ 33 | - $(A_k)_{k ∈ ℕ} ⊆ f^{-1}(\mathcal{A'}) ⇒ ∃ (A'_k)_{k ∈ ℕ} ⊆ \mathcal{A}': A_k = f^{-1}(A_k')$ 34 | \[⇒ \bigcup_{k ∈ ℕ} A_k = \bigcup_{k ∈ ℕ} f^{-1}(A_k') = f^{-1}(\bigcup_{k ∈ ℕ} A_k') ∈ f^{-1}(\mathcal{A}')\] 35 | #+end_proof 36 | 2 37 | $X, Ω ⊆ \mathcal{P}(X), \mathcal{D}(Ω)$ erzeugendes Dynkin-System \\ 38 | zz: wenn $\mathcal{D}(Ω)$ stabil gegeüber $\bigcap$ beziehungsweise $\bigcup$ ist, dann ist $\mathcal{D}(Ω)$ eine \(σ\)-Algebra 39 | #+begin_proof latex 40 | $X ∈ \mathcal{D}(Ω), A ∈ \mathcal{D}(Ω) ⇒ A^C ∈ \mathcal{D}(Ω)$ klar. $(A_n)_{n ∈ ℕ} ⊆ \mathcal{D}(Ω)$, setze 41 | \[B_i := \begin{cases} A_1 & i = 1\\ A_{i} \setminus \bigcup_{k = 1}^{i - 1} A_k \end{cases}\] 42 | dann ist $(B_n)_{n ∈ ℕ}$ eine paarweise disjunkte Folge und 43 | \[\bigcup_{n ∈ ℕ} A_n = \bigcup_{n ∈ ℕ} B_n\] 44 | damit genügt es zu zeigen, dass $B_n ∈ \mathcal{D}(Ω) ∀ n ∈ ℕ$ 45 | \begin{align*} 46 | B_n &= A_n \setminus (\bigcup_{n = 1}^{n - 1} A_k) = A_n ∩ (\bigcup_{n = 1}^{n - 1})^C \\ 47 | &= A_n ∩ (\bigcap_{k= 1}^{n - 1} A_k^C) ∈ \mathcal{D}(Ω), \text{wenn stabil gegenüber } \bigcap \\ 48 | &= (A_n^C ∪ (\bigcap_{k= 1}^{n - 1} A_k))^C ∈ \mathcal{D}(Ω), \text{wenn stabil gegenüber } \bigcup \\ 49 | \end{align*} 50 | #+end_proof 51 | 3 52 | $X, \mathcal{E} ⊆ \mathcal{P}(X), \emptyset, X ∈ \mathcal{E}$, \\ 53 | $ρ: \mathcal{E} \to [0, ∞], ρ(\emptyset) = 0$ 54 | \[\to μ^{\ast}(A) = \inf \{\sum_{k ∈ ℕ} ρ(A_k) \mid (A_k)_{k ∈ ℕ} ⊆ \mathcal{E}, A ⊆ \bigcup_{k ∈ ℕ} A_k\}\] 55 | a 56 | zz: $μ^{\ast}\mid_{\mathcal{E}} \leq ρ$ 57 | #+begin_proof latex 58 | $A ⊂ \mathcal{E}, A_1 := A, A_k = \emptyset, k \geq 2$ 59 | \begin{align*} 60 | ⇒ A &⊆ \bigcup_{k ∈ ℕ} A_k \\ 61 | ⇒ μ^{\ast}(A) &\leq \sum_{k ∈ ℕ} ρ(A_k) = ρ(A) 62 | \end{align*} 63 | #+end_proof 64 | b 65 | Sei $τ$ ein äußeres Maß auf $X$ mit $τ|_{\mathcal{E}} \leq ρ$ 66 | zz: $τ \leq μ^{\ast}$ 67 | #+begin_proof latex 68 | $A ⊆ X$ und $(A_k)_{k ∈ ℕ} ⊆ \mathcal{E}$, sodass 69 | \[A ⊆ \bigcup_{k ∈ ℕ} A_k\] 70 | dann ist 71 | \begin{align*} 72 | τ(A) &\leq τ(\bigcup_{k ∈ ℕ} A_k) \leq \sum_{k ∈ ℕ} τ(A_k) \leq \sum_{k ∈ ℕ} ρ(A_k) \\ 73 | \text{aber } μ^{\ast}(A) &= \inf \{\sum_{k ∈ ℕ} ρ(A_k) \mid (A_k)_{k} ⊆ \mathcal{E}, A ⊆ \bigcup_{k ∈ ℕ} A_k\} \\ 74 | ⇒ τ(A) &\leq μ^{\ast}(A) 75 | \end{align*} 76 | #+end_proof 77 | 4 78 | $Ω, \mathcal{A}$ \(σ\)-Algebra, $μ: \mathcal{A} \to [0,∞]$ mit $μ(\emptyset) = 0, A, B ∈ \mathcal{A}$ disjunkt gilt 79 | \[μ(A ∪ B) = μ(A) + μ(B)\] 80 | und $μ$ ist \(σ\)-subadditiv gegenüber parweiser disjunkter Folgen. \\ 81 | zz: $μ$ ist ein Maß 82 | #+begin_proof latex 83 | Sei $(A_k)_{k ∈ ℕ} ⊆ \mathcal{A}$ mit $A_i ∩ A_j = \emptyset$ für $i = j$ und betrachte zu festem $m ∈ ℕ$ 84 | \begin{align*} 85 | \sum_{k ∈ ℕ} μ(A_k) &\geq μ(\bigcup_{k ∈ ℕ} A_k) = μ(\bigcup_{k \leq m} A_k ∪ \bigcup_{k > m} A_k) = μ(\bigcup_{k \leq m} A_k) + μ(\bigcup_{k > m) A_k) \\ 86 | &\geq μ(\bigcup_{k \leq m}) A_k = \sum_{k = 1}^{m} μ(A_k) 87 | \end{align*} 88 | Somit folgt die Behauptung mit $m \to ∞$. 89 | #+end_proof 90 | -------------------------------------------------------------------------------- /bib.bib: -------------------------------------------------------------------------------- 1 | @article{broglie1924xxxv, 2 | title={XXXV. A tentative theory of light quanta}, 3 | author={Broglie, Louis de}, 4 | journal={Philosophical Magazine Series 6}, 5 | volume={47}, 6 | number={278}, 7 | pages={446--458}, 8 | year={1924}, 9 | publisher={Taylor \& Francis} 10 | } -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | files=$(find . -maxdepth 3 -type f -name '*.org') 4 | 5 | configfile=$(realpath emacs_config.el) 6 | 7 | for file in $files 8 | do 9 | grep TITLE $file > /dev/null || continue 10 | emacs $file --batch -l $configfile -f org-latex-export-to-latex --kill 11 | done 12 | 13 | make -j5 14 | -------------------------------------------------------------------------------- /cp0/tutorial/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*/ 3 | !*.pdf 4 | !*.org 5 | !header.org 6 | !.gitignore 7 | -------------------------------------------------------------------------------- /cp0/tutorial/1/01_cp_1_heinemann_rosendahl_rall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/01_cp_1_heinemann_rosendahl_rall.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/02_cp_1_heinemann_rosendahl_rall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/02_cp_1_heinemann_rosendahl_rall.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/cp_1_heinemann_rosendahl_rall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/cp_1_heinemann_rosendahl_rall.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/integrand-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/integrand-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/1/test-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/1/test-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/hist_100.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/hist_100.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/hist_10000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/hist_10000.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/hist_1000000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/hist_1000000.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/hist_10000000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/hist_10000000.pdf -------------------------------------------------------------------------------- /cp0/tutorial/10/pi-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/10/pi-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/cp_2_heinemann_rosendahl_rall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/cp_2_heinemann_rosendahl_rall.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_1-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_1-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_2-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_2-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_3-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_3-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_4_1-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_4_1-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_4_2-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_4_2-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_4_3-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_4_3-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_e-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_e-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/euler_error-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/euler_error-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/leapfrog_error-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/leapfrog_error-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/2/vverlet_error-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/2/vverlet_error-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/dist-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/dist-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/energy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/energy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/figure_eight-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/figure_eight-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/traj_3-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/traj_3-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/traj_4-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/traj_4-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/3/traj_5-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/3/traj_5-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/4/eps-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/4/eps-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/4/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/4/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/4/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/4/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/5/exercise.org: -------------------------------------------------------------------------------- 1 | #+INCLUDE: ../header.org 2 | #+TITLE: Exercise sheet 5 3 | #+AUTHOR: by Robin Heinemann (group 4), Paul Rosendahl (group 4) 4 | #+LATEX_HEADER: \newcommand{\rust}{\textit{rust}\xspace} 5 | 6 | * Tridiagonal matrices 7 | Consider the following linear system 8 | \begin{equation*} 9 | \begin{pmatrix}b_1 & c_1 & 0 & 0 & \dots & 0 & 0 & 0 & 0 \\ a_2 & b_2 & c_2 & 0 & \dots & 0 & 0 & 0 & 0 \\ 0 & a_3 & b_3 & c_3 & \dots & 0 & 0 & 0 & 0 \\ \vdots & \vdots & \vdots & \vdots & & \vdots & \vdots & \vdots & \vdots \\ 0 & 0 & 0 & 0 & \dots & a_{n - 2} & b_{n - 2} & c_{n - 2} & 0 \\ 0 & 0 & 0 & 0 & \dots & 0 & a_{n - 1} & b_{n - 1} & c_{n - 1} \\ 0 & 0 & 0 & 0 & \dots & 0 & 0 & a_n & b_n\end{pmatrix} \cvec{x_1; x_2; x_3 \vdots; x_{n - 2}; x_{n - 1}; x_n} = \cvec{y_1; y_2; y_3 \vdots; y_{n - 2}; y_{n - 1}; y_n} 10 | \end{equation*} 11 | where $n ∈ ℕ$. This can be solved using Gaussian elimination. To transform the matrix to a upper triangular matrix the following algorithm can be used 12 | \begin{align*} 13 | \tilde b_1 &= b_1 \\ 14 | \tilde y_1 &= y_1 \\ 15 | \tilde b_{i + 1} &= b_{i + 1} - \frac{a_{i + 1}}{\tilde b_i} c_i \\ 16 | \tilde y_{i + 1} &= y_{i + 1} - \frac{a_{i + 1}}{\tilde b_i} \tilde y_i \\ 17 | \end{align*} 18 | This results in the following linear system with the same solution as the original system 19 | \begin{equation*} 20 | \begin{pmatrix}\tilde b_1 & c_1 & 0 & 0 \\ 0 & \ddots & \ddots & 0 \\ 0 & \ddots & \ddots & c_{n - 1} \\ 0 & 0 & 0 & \tilde b_n\end{pmatrix} \cvec{x_1; \vdots; \vdots; x_n} = \cvec{\tilde y_1; \vdots; \vdots; \tilde y_n} 21 | \end{equation*} 22 | This can be solved using a simple backward substitution 23 | \begin{align*} 24 | x_n &= \frac{\tilde y_n}{\tilde b_n} \\ 25 | x_{i - 1} &= \frac{1}{\tilde b_{i - 1}}(\tilde y_{i - 1} - c_{n - 1} x_{i}) 26 | \end{align*} 27 | This algorithm is used to solve the linear system where $a_i = \num{-1}, b_i = \num{2}, c_i = \num{-1}, y_i = \num{0.1} ∀ i ∈ \{1, \dots, n\}$. The solution is the used to calculate the right-hand-side, which should be 28 | $\num{0.1}$ for every entry. The calculated values comes quite close to the expected $\num{0.1}$, with the biggest relative error being $\num{3.1e-15} \approx 30 · \text{eps}$. This means the error is still quite close to 29 | the minimal possible error. For most applications a error this small will probably be irrelevant. 30 | #+caption: rust implementation of gauss elimination for a tridiagonal matrix 31 | #+ATTR_LATEX: :placement [Hp] 32 | #+begin_src rust :tangle "gauss_tridiag.rs" :results raw output :exports both :colnames yes :long-listing 33 | use std::ops::{Div, Mul, SubAssign, AddAssign, Sub, DivAssign}; 34 | 35 | type Vector = Vec; 36 | 37 | fn tridiag(a: &Vector, b: &mut Vector, c: &mut Vector, y: &mut Vector) -> Vector 38 | where T: Div + SubAssign + Mul + Sub + Copy 39 | { 40 | let n = y.len(); 41 | 42 | for i in 0..(n - 1) { 43 | let f = a[i] / b[i]; 44 | 45 | b[i + 1] -= f * c[i]; 46 | y[i + 1] -= f * y[i]; 47 | } 48 | 49 | let mut x = y.clone(); 50 | 51 | x[n - 1] = y[n - 1] / b[n - 1]; 52 | 53 | for i in 1..n { 54 | let ii = n - i - 1; 55 | 56 | x[ii] = (y[ii] - c[ii] * x[ii + 1]) / b[ii]; 57 | } 58 | 59 | x 60 | } 61 | 62 | fn main() { 63 | let n = 10; 64 | let mut a = vec![-1.0; n - 1]; 65 | let mut b = vec![2.0; n]; 66 | let mut c = vec![-1.0; n - 1]; 67 | let mut y = vec![0.1; n]; 68 | 69 | let x = tridiag(&a, &mut b, &mut c, &mut y); 70 | 71 | let a = vec![-1.0; n - 1]; 72 | let b = vec![2.0; n]; 73 | let c = vec![-1.0; n - 1]; 74 | let mut yy = vec![0.0; n]; 75 | 76 | yy[0] = b[0] * x[0] + c[0] * x[1]; 77 | yy[n - 1] = a[n - 2] * x[n - 2] + b[n - 1] * x[n - 1]; 78 | for i in 1..(n - 1) { 79 | yy[i] = a[i - 1] * x[i - 1] + b[i] * x[i] + c[i] * x[i + 1]; 80 | } 81 | 82 | println!("|$x_n$|$y'_n$"); 83 | println!("|-"); 84 | 85 | for i in 0..n { 86 | println!("| {} | {}", x[i], yy[i]); 87 | } 88 | } 89 | #+end_src 90 | 91 | #+caption: solution of the linear system and right-hand-side calculated from the solution 92 | #+attr_latex: :booktabs 93 | #+ATTR_LATEX: :placement [H] 94 | #+RESULTS: 95 | | $x_n$ | $y'_n$ | 96 | |--------------------+---------------------| 97 | | 0.5 | 0.09999999999999998 | 98 | | 0.9 | 0.09999999999999987 | 99 | | 1.2000000000000002 | 0.09999999999999987 | 100 | | 1.4000000000000006 | 0.10000000000000031 | 101 | | 1.5000000000000007 | 0.10000000000000009 | 102 | | 1.5000000000000007 | 0.10000000000000031 | 103 | | 1.4000000000000004 | 0.09999999999999987 | 104 | | 1.2000000000000002 | 0.10000000000000009 | 105 | | 0.8999999999999999 | 0.09999999999999976 | 106 | | 0.4999999999999999 | 0.09999999999999987 | 107 | 108 | * Additional notes 109 | All programs written are written using the programming language \rust. Extra dependencies (\rust \textit{crates}) will be listed in a comment in the first line. 110 | To get the source files of each program just unzip this \textit{pdf} file. You will find directories for every 111 | program in this file. To execute one of the programs run \texttt{cargo run} in it's directory. All plots are made with \textit{gnuplot}. 112 | This document was written in \textit{org-mode} and converted to \textit{pdf}. The corresponding \textit{org-mode} sources can also be found by unzipping this \textit{pdf} file. 113 | -------------------------------------------------------------------------------- /cp0/tutorial/5/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/5/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/5/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/5/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/6/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/6/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/6/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/6/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/7/exercise.org: -------------------------------------------------------------------------------- 1 | #+INCLUDE: ../header.org 2 | #+TITLE: Exercise sheet 7 3 | #+AUTHOR: by Robin Heinemann (group 4), Paul Rosendahl (group 4) 4 | #+LATEX_HEADER: \newcommand{\rust}{\textit{rust}\xspace} 5 | #+LATEX_HEADER: \newcommand{\mathematica}{\textit{Mathematica}\xspace} 6 | 7 | * Population dynamics 8 | We study the system 9 | \[\dd{N}{t} = r N(1 - N / K) - \frac{B N^2}{A^2 + N^2}\] 10 | where $r, K, A, B$ are real positive constants. First we transform the system 11 | into a dimensionless system. It is obvious that $[A] = [N]$, we choose $n = N/A$ as 12 | dimensionless version of $N$. Let $τ = t / t_c$ be the dimensionless version of $t$. 13 | Substituting $N = n A$ and $t = τ t_c$ into the equation we obtain 14 | \begin{align*} 15 | \frac{A}{t_c} \dd{n}{τ} &= r A n(1 - A n / K) - \frac{B n^2 A^2}{A^2 + n^2 A} \\ 16 | \dd{n}{τ} &= r t_c n(1 - A n/K) - t_c \frac{B}{A} \frac{n^2}{1 + n^2} \\ 17 | \intertext{We choose $t_c = A / B ⇒ τ = t B / A$ to remove the factor befor the $n^2$ term} 18 | \dd{n}{τ} &= r \frac{A}{B} n(1 - \frac{A}{K}n) - \frac{n^2}{1 + n^2} 19 | \intertext{This leaves two dimensionless factors, we define two dimensionless constants} 20 | ρ &= r \frac{A}{B} \\ 21 | κ &= \frac{A}{K} \\ 22 | ⇒ \dd{n}{τ} &= ρ n(1 - κn) - \frac{n^2}{1 + n^2} 23 | \end{align*} 24 | $n$ is stationary, when $\partial_{τ} n$ is zero 25 | \begin{align*} 26 | ⇒ ρ n (1 - κ n) - \frac{n^2}{1 + n^2} &= 0 \\ 27 | ρ n (1 + n^2)(1 - κ n) - n^2 &= 0 \\ 28 | n(ρ(1 + n^2)(1 - κ n) - n) &= 0 29 | \end{align*} 30 | \[⇒ n = 0 ∨ ρ(1 + n^2)(1 - κ n) - n = 0\] 31 | The solutions of the second equation can be calculated using by \mathematica. 32 | #+caption: mathematica code for calculating the solution of the second equation 33 | #+ATTR_LATEX: :placement [Hp] 34 | #+begin_src mathematica :exports code :colnames yes :long-listing 35 | Manipulate[Solve[x*(r*(x^2 + 1) (x/8 - 1) - x) == 0, x], {r, 0, 2, 0.01}] 36 | #+end_src 37 | Changing $ρ$ shows that when $ρ$ is $\leq \num{0.44}$ there are three, or rather four stationary points. 38 | And for $ρ \geq \num{0.45}$ there is only one (two when counting $n = 0$) stationary point. 39 | Plotting the equation makes it easy to determine whether the stationary point is stable or unstable. 40 | If the derivative increases when $n$ gets bigger by a small value, $n$ will further increase and 41 | the stationary point is unstable. The same happens, if the derivative decreases when $n$ gets 42 | smaller by a small value, then $n$ will decrease further. The equation can be plotted easily using 43 | \mathematica. 44 | #+caption: mathematica code for calculating the solution of the second equation 45 | #+ATTR_LATEX: :placement [Hp] 46 | #+begin_src mathematica :exports code :colnames yes :long-listing 47 | Manipulate[Plot[x*(r*(x^2 + 1) (x/8 - 1) - x), {x, -20, 20}], {r, 0, 2, 0.01}] 48 | #+end_src 49 | Using this we can determine 50 | - the smallest stationary point is stable (derivative decreases if $n$ increases / increases if $n$ decreases) 51 | - the second smallest stationary point is unstable (derivative increases if $n$ increases) 52 | - the stationary point at $n = 0$ is stable (derivative decreases if $n$ increases / increases if $n$ decreases) 53 | - the biggest stationary point is unstable (derivative increases if $n$ increases) 54 | (if $r \geq \num{0.45}$ the smallest two stationary points are not real anymore, but the stability of the other two does not change) 55 | -------------------------------------------------------------------------------- /cp0/tutorial/7/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/7/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/7/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/7/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/8/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/8/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/8/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/8/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/8/plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/8/plot.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/05xy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/05xy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/05xz-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/05xz-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/115xy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/115xy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/115xz-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/115xz-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/13456xy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/13456xy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/13456xz-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/13456xz-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/235xy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/235xy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/235xz-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/235xz-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/26_full-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/26_full-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/26_reduced-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/26_reduced-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/29xy-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/29xy-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/29xz-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/29xz-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/9/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/9/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/template/exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/template/exercise.pdf -------------------------------------------------------------------------------- /cp0/tutorial/template/exercise_pre.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/template/exercise_pre.pdf -------------------------------------------------------------------------------- /cp0/tutorial/template/integrand-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/template/integrand-eps-converted-to.pdf -------------------------------------------------------------------------------- /cp0/tutorial/template/test-eps-converted-to.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/cp0/tutorial/template/test-eps-converted-to.pdf -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # Exit with nonzero exit code if anything fails 3 | 4 | function doCompile { 5 | ./compile.sh 6 | } 7 | 8 | # Enable case-insensitive pattern matching. 9 | shopt -s nocasematch 10 | 11 | get_download_url() { 12 | echo "https://raw.githubusercontent.com/rroohhh/travis-texlive/master/texlive.tar.xz" 13 | } 14 | 15 | 16 | echo "Downloading portable TeX Live installation..." 17 | curl -s $( get_download_url ) | tar -xJC "${HOME}" 18 | 19 | # Ensure PATH points to the platform-specific binaries. 20 | if [[ "${TRAVIS_OS_NAME:-}" == "linux" ]]; then 21 | export PATH="${HOME}/texlive/bin/x86_64-linux:${PATH}" 22 | else 23 | export PATH="${HOME}/texlive/bin/x86_64-darwin:${PATH}" 24 | fi 25 | 26 | git clone https://code.orgmode.org/bzg/org-mode.git 27 | cd org-mode 28 | make autoloads 29 | make 30 | sudo make install 31 | cd .. 32 | rm -rf org-mode 33 | 34 | # Save some useful information 35 | SHA=`git rev-parse --verify HEAD` 36 | 37 | # Clone the existing gh-pages for this repo into out/ 38 | # Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) 39 | git clone https://github.com/hd-notes/pdfs.git pdfs 40 | git clone --recursive https://github.com/hd-notes/hd-notes.github.io.git pages 41 | 42 | # Clean out existing contents 43 | # TODO(robin): auto run fetch scripts 44 | # rm -rf pdfs/**/* || exit 0 45 | rm -rf pages/index.html || exit 0 46 | 47 | # Run our compile script 48 | doCompile 49 | 50 | # Pull requests and commits to other branches shouldn't try to deploy, just build to verify 51 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 52 | echo "Skipping deploy; just doing a build." 53 | exit 0 54 | fi 55 | 56 | # copy the pdfs 57 | find . ! -path "./pdfs/*" ! -path "./pages/*" -name '*.pdf' -exec dirname {} \; | xargs -I {} mkdir -p pdfs/{} 2> /dev/null 58 | find . ! -path "./pdfs/*" ! -path "./pages/*" -name '*.pdf' -exec cp {} pdfs/{} \; 59 | 60 | # Now let's go have some fun with the cloned repo 61 | echo "updating pdfs" 62 | cd pdfs 63 | git config user.name "Travis CI" 64 | git config user.email "$COMMIT_AUTHOR_EMAIL" 65 | 66 | # If there are no changes to the compiled out (e.g. this is a README update) then just bail. 67 | # if [ -z `git diff --exit-code` ]; then 68 | # echo "No changes to the output on this push; exiting." 69 | # exit 0 70 | # fi 71 | 72 | # Commit the "changes", i.e. the new version. 73 | # The delta will show diffs between new and old versions. 74 | git add . 75 | git commit -m "travis auto compile: ${SHA}" 76 | 77 | # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc 78 | openssl aes-256-cbc -K $encrypted_fcdac90c3348_key -iv $encrypted_fcdac90c3348_iv -in ../keys.enc -out keys -d 79 | 80 | head -c3243 keys > pdf_key 81 | tail -c3247 keys > ../pages/pages_key 82 | chmod 600 pdf_key 83 | eval `ssh-agent -s` 84 | ssh-add pdf_key 85 | 86 | # Now that we're all set up, we can push. 87 | git push git@github.com:hd-notes/pdfs.git 88 | # git push origin master 89 | 90 | cd .. 91 | 92 | echo "updating pages" 93 | # sleep a bit to give github some time 94 | sleep 1 95 | cd pages 96 | #cd pdfs 97 | #git pull 98 | #cd .. 99 | # TODO(robin): why does this not work? (maybe git is too old?) 100 | git submodule update --remote --merge 101 | ./generate.sh ../ 102 | 103 | git config user.name "Travis CI" 104 | git config user.email "$COMMIT_AUTHOR_EMAIL" 105 | 106 | # If there are no changes to the compiled out (e.g. this is a README update) then just bail. 107 | # if [ -z `git diff --exit-code` ]; then 108 | # echo "No changes to the output on this push; exiting." 109 | # exit 0 110 | # fi 111 | 112 | # Commit the "changes", i.e. the new version. 113 | # The delta will show diffs between new and old versions. 114 | git add . 115 | git commit -m "travis auto update: ${SHA}" 116 | 117 | # Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc 118 | # ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" 119 | # ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" 120 | # ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} 121 | # ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} 122 | 123 | chmod 600 pages_key 124 | ssh-add -D 125 | ssh-add pages_key 126 | 127 | # Now that we're all set up, we can push. 128 | git push git@github.com:hd-notes/hd-notes.github.io.git 129 | # git push origin master 130 | -------------------------------------------------------------------------------- /emacs_config.el: -------------------------------------------------------------------------------- 1 | (with-eval-after-load 'ox-latex 2 | (add-to-list 'org-latex-classes 3 | '("koma-article" 4 | "\\documentclass{scrartcl}" 5 | ("\\section{%s}" . "\\section*{%s}") 6 | ("\\subsection{%s}" . "\\subsection*{%s}") 7 | ("\\subsubsection{%s}" . "\\subsubsection*{%s}") 8 | ("\\paragraph{%s}" . "\\paragraph*{%s}") 9 | ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))) 10 | 11 | (setq org-latex-listings 'minted) 12 | (setq org-latex-minted-options 13 | '(("tabsize" "4"))) 14 | 15 | -------------------------------------------------------------------------------- /ex1/collisions.org: -------------------------------------------------------------------------------- 1 | * Stöße 2 | Für ein abgeschlossenes System gilt: (keine äußere Kräfte) \\ 3 | Impulserhaltung: 4 | \[\sum_{i = 1}^{n} \v p_i = \sum_{i = 1}^{n} \v p_i'\] 5 | Energieerhaltung: 6 | \[\sum_{i = 1}^{n} E_i = \sum_{i = 1}^{n} E_i'\] 7 | ** Kollinearer elastischer Stoß 8 | Es gilt: 9 | \begin{align*} 10 | m_1 v_1 + m_2 v_2 = m_1 v_1' + m_2 v_2' \\ 11 | \frac{1}{2} m_1 v_1^2 + \frac{1}{2} m_2 v_2^2 = \frac{1}{2} m_1 v_1^{\prime 2} + \frac{1}{2} m_2 v_2^{\prime 2} \\ 12 | \intertext{$\implies$ Lösung (ohne Herleitung)} 13 | v_1' = \frac{v_1(m_1 - m_2) + 2m_2 v_2}{m_1 + m_2} \\ 14 | v_2' = \frac{v_2(m_2 - m_1) + 2m_1 v_1}{m_1 + m_2} 15 | \end{align*} 16 | Geschwindigkeit nach Kollinearer elastisch Stoß 17 | Tipp zur Herleitung: Betrachte Bewegung relativ zur Schwerpunktsbewegung (siehe z.B. Demtröders) 18 | 19 | Hier Betrachtung von Spezialfällen. \\ 20 | Betrachtung von Spezialfällen ist immer wichtig! Hilft beim Verständnis physikalischer Zusammenhänge 21 | 1. $m_1 = m_2 = m, r_1 > 0, v_2 = 0$ 22 | \[v_1' = \frac{2 m v_2}{2 m} = v_2 = 0, v_2' = \frac{2m r_1}{2 m} = v_1\] 23 | 2. $m_1 = m, m_2 = 2 m, v_1 > 0, v_2 > 0$ 24 | \begin{align*} 25 | v_1' = \frac{v_1 (- m)}{3 m} = - \frac{1}{3}v_1 \\ 26 | v_2' = \frac{2m v_1}{3 m} = \frac{2}{3}v_1 \\ 27 | \end{align*} 28 | 3. $m_1 = m, m_2 = 3m, v_1 = v > 0, v_2 = -v$ 29 | \begin{align*} 30 | v_1' = \frac{v(m - 2m) - 2(3m) v}{4m} = \frac{v(-2m - 6m)}{4m} = -2v \\ 31 | v_2' = \frac{-v(2m - m) + 2mv}{2m} = \frac{v(-2m + 2m)}{3m} = 0 32 | \end{align*} 33 | 4. $m_1 = m, m_2 \to \infty, v_1 = v, v_2 = 0$ 34 | \begin{align*} 35 | v_1' = \frac{v(-m_2)}{m_2} = -v \tag{da $m_1$ vernachlässigbar} \\ 36 | v_2' = \frac{2 m_1 v}{m_2} = 0 \tag{da $m_1 \ll m_2$} 37 | \end{align*} 38 | 5. $m_1 = m, m_2$ sehr groß!, $v_1 = 0, v_2 = v$ 39 | \[v_1' = \frac{2m_2 v}{m_2} = 2v,\quad v_2' = \frac{v m_2}{m_2} = v\] 40 | ** Betrachtung im Schwerpunktsystem 41 | Es gilt: 42 | \begin{align*} 43 | v_s = \frac{m_1 v_1 + m_2 v_2}{m_1 + m_2} \\ 44 | \intertext{Geschwindigkeiten im Schwerpunktsystem:} 45 | v_1^\ast = v_1 - v_s = \frac{m_2 v_1 - m_2 v_2}{m_1 + m_2} \\ 46 | v_2^\ast = v_2 - v_s = \frac{m_1 v_2 - m_1 v_1}{m_1 + m_2} \\ 47 | \intertext{daraus folgt:} 48 | p_1^\ast = m_1 v_1^\ast = \frac{m_1 m_2}{m_1 + m_2} (v_1 - v_2) \\ 49 | p_2^\ast = m_2 v_2^\ast = \frac{m_1 m_2}{m_1 + m_2} (v_2 - v_1) \\ 50 | \intertext{Das heißt vor dem Stoß gilt:} 51 | p_1^\ast = -p_2^\ast 52 | E_{kin,1}^\ast = \frac{1}{2} m(v_1^\ast)^2 = \frac{(p_1^\ast)^2}{2m_1} 53 | E_{kin,2}^\ast = \frac{(p_2^\ast)^2}{2m_2} 54 | \intertext{nach dem Stoß:} 55 | \intertext{Impulserhaltung:} 56 | p_s^\ast = p_1^\ast + p_2^\ast = p_1^{*\prime} + p_2^{ *\prime} = 0 \rightarrow p_1^{*\prime} = -p_2^{*\prime} \\ 57 | \intertext{Energieerhaltung:} 58 | E_{ges}^\ast = E_{kin,1}^\ast + E_{kin,2}^\ast = E_{kin,1}^{\ast\prime} + E_{kin,2}^{\ast\prime} \\ 59 | \intertext{Außerdem:} 60 | p_1^{\ast\prime} = \frac{p_1^\ast (m_1 - m_2) + 2 m_1 p_2^\ast}{m_1 + m_2} = -p_1^\ast, p_2^{\ast\prime} = -p_2^{\ast} 61 | \intertext{daraus folgt:} 62 | E_{kin,1}^{\ast\prime} = E_{kin,1}^\ast \\ 63 | E_{kin,2}^{\ast\prime} = E_{kin,2}^\ast \\ 64 | \end{align*} 65 | Im Schwerpunktsystem findet bei elastischen Stößen keine Energieübertragung statt. Aber: Impulse werden ausgetauscht 66 | *** Nicht-zentraler, elastischer Stoß im Schwerpunktsystem 67 | \begin{align*} 68 | \v p_s^\ast = 0, \v p_1^\ast = -\v p_2^\ast \\ 69 | \v p_s^{\ast\prime} = -\v p_2^{\ast\prime}, \abs{\v p_1^\ast = \abs{\v p_1^{\ast\prime}}} \\ 70 | \end{align*} 71 | Im Schwerpunktsystem sind für ein abgeschlossenes System zweier Massenpunkte ein- und auslaufende kollinear und vom Betrag her gleich 72 | ** Inelastische Stöße 73 | Betrachte $2$ Kugeln 74 | - Massen: $m_1, m_2$ 75 | - Geschwindigkeit: $v_1 = v, v_2 = 0$ 76 | - Impulserhaltung: 77 | \begin{align*} 78 | m_1 v &= (m_1 + m_2) v' \\ 79 | v' &= \frac{m}{m_1 + m_2} v 80 | \end{align*} 81 | - Energiebilanz: 82 | \[E_{kin} = \frac{1}{2} m_1 v^2, E_{kin}' = \frac{1}{2} (m_1 + m_2) (\frac{m_1}{m_1 + m_2})^2 v^2 = \frac{1}{2} \frac{m_1^2}{m_1 + m_2}v^2 < E_{kin}\] 83 | Beim inelastischen Stoß geht mechanische Energie verloren, sie wird beim Stoß in andere Energieformen (zum Beispiel Wärme) umgewandelt. (siehe Thermodynamik) 84 | Interessant: 85 | Betrachtung im Schwerpunktsystem. 86 | \begin{align*} 87 | m_1 v_1^\ast - m_2 v_2^\ast = (m_1 + m_2) v^{\ast\prime} \\ 88 | \intertext{da $p_1^\ast = -p_2^\ast$} 89 | (m_1 + m_2) v^{\ast\prime} = 0 \\ 90 | E_{kin}^{\ast\prime} = \frac{1}{2}(m_1 + m_2)(v^{\ast\prime})^2 = 0 91 | \end{align*} 92 | Im Schwerpunktsystem findet beim inelastischen Stoß eine vollständige Umwandlung der kinetischen Energie statt. \\ 93 | Allgemein: 94 | \begin{align*} 95 | \intertext{falls $\v F_{außen} =0$} 96 | E_{kin,1} + E_{kin,2} = E_{kin,1}' + E_{kin,2}' + Q 97 | \sum \v p_i &= \sum \v p'_i = \text{const} \\ 98 | \sum E_{kin,i} &= \sum E'_{kin,i} + Q \\ 99 | Q &= 0 \tag*{elastisch} \\ 100 | Q &> 0 \tag*{inelastisch} \\ 101 | Q &< 0 \tag*{superelastisch} \\ 102 | \end{align*} 103 | -------------------------------------------------------------------------------- /ex1/conservation_laws.org: -------------------------------------------------------------------------------- 1 | * Erhaltungssätze 2 | ** Energieerhaltung 3 | Für konservative Kräfte gilt: 4 | \[\Delta E_{kin} = -\Delta E_{pot} = \int_1^2 \v F\d \v r\] 5 | das heißt: die kinetische Energie ergibt sich allein aus der Potentialdifferenz und ist unabhängig vom durchlaufenen Weg. 6 | \begin{align*} 7 | E_{kin}(2) - E_{kin}(1) = E_{pot}(1) - E_{pot}(2) \\ 8 | E_{kin}(1) + E_{pot}(1) = E_{kin}(2) + E_{pot}(2) = \ldots =~\text{const} \\ 9 | \end{align*} 10 | *** Doppelbahn 11 | \begin{align*} 12 | E_{pot}(1) = m\cdot g\cdot h \\ 13 | E_{pot}(1) = E_{pot(2')} = 0 \\ 14 | \rightarrow \\ 15 | E_{kin}(2) = E_{kin}(2') = \frac{1}{2}m v^2 \\ 16 | \end{align*} 17 | Bemerkung: Berechnung von $v$ mit Newtonschen Gesetzen deutlich komplexer 18 | *** Energieerhaltungssatz der Newtonschen Mechanik 19 | \[E_{pot} + E_{kin} = E_{ges} = ~\text{const}\] 20 | $E_{ges}$ = mechanische Gesamtenergie \\ 21 | das heißt: In einem konservativen Kraftfeld ist die Summe aus potentieller und kinetischer Energie 22 | eines Massenpunktes zu jeder Zeit konstant 23 | 24 | Wichtig: gilt nur für konservative Kraftfelder (Beim Auftreten nicht-konservativer, dissipativer Kräfte wird 25 | mechanische Energie in Wärme umgewandelt) 26 | *** Energiediagramme 27 | Häufig: Potentielle Energie abhängig von Ort $x$ oder Abstand $r$ \\ 28 | Hilfreich: Diskussion mittels Energiediagramme 29 | **** Kugelbahn 30 | - Abhängig von $E_{ges}$ kann sich die Kugel nur in bestimmten Bereichen aufhalten 31 | - Gleichgewichtslage: Kugel ruht, es wirken keine Kräfte, das heißt 32 | \[F = -\dd{E_{pot}}{x} = 0, ~\text{bzw}~ \v F = -\grad E_{pot} = 0\] 33 | 34 | Drei Fälle: 35 | 1. Stabiles bzw. Metastabiles Gleichgewicht: Potentialkurve hat ein Minimum 36 | 2. labiles Gleichgewicht: Potentialkurve hat ein Maximum 37 | 3. Indifferentes Gleichgewicht: Flacher Verlauf der Potentialkurve 38 | **** Lennard-Jones-Potential 39 | Potential zur Beschreibung von molekularen Bindungen 40 | \[E_{pot} = V_0 (\frac{r}{r_0})^{-12} - 2(\frac{r}{r_0})^{-6}\] 41 | (Dipol-Dipol-Wechselwirkung, Van-der-Waals Kräfte) 42 | **** Mechanischer Verstärker 43 | \[E_{pot}' = m g h = \underarrow[\rho]{Dichte} \overarrow[(a b c)]{Volumen} g h\] 44 | mit $h = \frac{1}{2}c$ \\ 45 | Fallender Dominostein: $E_{pot} \to E_{kin}$ \\ 46 | Startposition: (Meta)stabiles Gleichgewicht \\ 47 | das heißt: Dominosteine müssen über einen Potentialberg angehoben werden. Danach ist die kinetische Energie 48 | ausreichend, um den nächsten Stein über Potentialschwelle zu heben. 49 | Verstärkungsfaktor: \\ 50 | Skalierung zwischen den Steinen: Alle Längen $\times \sqrt{2}$ \\ 51 | Potentielle Energie für Stein $m$: 52 | \begin{align*} 53 | E_{pot} &= \rho(a^{(n)}b^{(n)}c^{(n)}) h^{(n)} g = (\sqrt{2})^4 E_{pot}^{(n-1)} \\ 54 | E_{pot}^{(1)} &= m g h \\ 55 | \implies E_pot^{(13)} &= 4^{12} E_{pot}^{(1)} \\ 56 | \intertext{$\implies$ Verstärkungsfaktor $\approx \SI{1.7e7}{}$} 57 | \end{align*} 58 | 59 | -------------------------------------------------------------------------------- /ex1/ex1.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex1/ex1.ora -------------------------------------------------------------------------------- /ex1/free_rotation.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex1/free_rotation.org -------------------------------------------------------------------------------- /ex1/introduction.org: -------------------------------------------------------------------------------- 1 | * Einleitung 2 | ** Eigenschaften der Physik 3 | Physik ist _nicht_ axiomatisch! 4 | - Nicht alle Gesetze der Natur sind bekannt. 5 | - Die bekannten Naturgesetze sind _nicht_ unumstößlich 6 | - unfertig 7 | - empirisch 8 | - quantitativ 9 | - experimentell 10 | - überprüfbar 11 | - braucht Mathematik 12 | - Gefühl für Größenordnungen und rationale Zusammenhänge 13 | *** Beispiel 14 | Fermi-Probleme: 15 | - Anzahl der Klavierstimmer in Chicago? 16 | - Anzahl der Autos in einem 10km Stau? 17 | - Anzahl von Fischen im Ozean 18 | 19 | ** Maßeinheiten 20 | Internationales Einheitensystem (SI) 21 | *** Basisgrößen 22 | | Größe | Einheit | Symbol | 23 | |-------+-----------+----------------| 24 | | Länge | Meter | $\si{\meter}$ | 25 | | Masse | Kilogramm | $\si{\kg}$ | 26 | | Zeit | Sekunden | $\si{\second}$ | 27 | **** Meter 28 | Strecke, die das Licht im Vakuum während der Dauer von $\frac{1}{299792458}\si{\second}$ durchläuft. 29 | **** Sekunde 30 | Das \(\SI{9192631770}{}\)-fache der Periodendauer der am Übergang zwischen den beiden Hyperfeinstukturniveaus des Grundzustandes von Atomen des Nukulids $Cs_{133}$ entsprechenden Strahlung. 31 | **** Kilogramm 32 | Das Kilogramm ist die Einheit der Masse, es ist gleich der Masse des internationalen Kilogrammprototyps (ist scheiße). 33 | ***** Avogadroprojekt 34 | \[N_A = \frac{M V n}{m}\] 35 | $N_A$: Avogardokonstante ($N_A = \SI{6.0221415e23}{}$) 36 | *** Weitere Größen 37 | | Größe | Einheit | Symbol | 38 | |-------------+---------+-----------------| 39 | | Strom | Ampere | $\si{\ampere}$ | 40 | | Temperatur | Kelvin | $\si{\kelvin}$ | 41 | | Lichtstärke | Candla | $\si{\candela}$ | 42 | -------------------------------------------------------------------------------- /ex1/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IFS=$'\n' 4 | 5 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/moodle) --delete-after https://elearning2.uni-heidelberg.de/login/index.php 6 | 7 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://elearning2.uni-heidelberg.de/course/view.php?id=13147' | pcregrep -o1 '(https:\/\/elearning2\.uni-heidelberg\.de\/mod\/resource\/view\.php\?id=\d*?)"> \d*. Übungsblatt') 8 | 9 | rm *.pdf 10 | 11 | for pdf in $pdfs 12 | do 13 | wget --content-disposition --load-cookies cookies.txt $pdf 14 | done 15 | -------------------------------------------------------------------------------- /ex1/tutorial/link: -------------------------------------------------------------------------------- 1 | https://elearning2.uni-heidelberg.de/course/view.php?id=13147 2 | -------------------------------------------------------------------------------- /ex1/tutorial/notes/tutorial.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex1/tutorial/notes/tutorial.ora -------------------------------------------------------------------------------- /ex1/tutorial/notes/tutorial.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Experimentalphysik Übung (R. Weis) 3 | #+LATEX_HEADER: \usepackage{siunitx} 4 | #+LATEX_HEADER: \usepackage{fontspec} 5 | #+LATEX_HEADER: \sisetup{load-configurations = abbrevations} 6 | #+LATEX_HEADER: \newcommand{\estimates}{\overset{\scriptscriptstyle\wedge}{=}} 7 | #+LATEX_HEADER: \usepackage{mathtools} 8 | #+LATEX_HEADER: \DeclarePairedDelimiter\abs{\lvert}{\rvert}% 9 | #+LATEX_HEADER: \DeclarePairedDelimiter\norm{\lVert}{\rVert}% 10 | #+LATEX_HEADER: \DeclareMathOperator{\Exists}{\exists} 11 | #+LATEX_HEADER: \DeclareMathOperator{\Forall}{\forall} 12 | #+LATEX_HEADER: \def\cvec#1{\left(\vcenter{\halign{\hfil$##$\hfil\cr \cvecA#1;;}}\right)} 13 | #+LATEX_HEADER: \def\cvecA#1;{\if;#1;\else #1\cr \expandafter \cvecA \fi} 14 | #+LATEX_HEADER: \renewcommand{\d}{\mathrm{d}} 15 | #+LATEX_HEADER: \newcommand{\f}[2]{{\frac{#1}{#2}}} 16 | #+LATEX_HEADER: \renewcommand{\v}[1]{\vec{#1}} 17 | #+LATEX_HEADER: \usepackage{tikz} 18 | #+LATEX_HEADER: \usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings} 19 | 20 | * Aufgabe 3 21 | \[s_z = \frac{1}{2}a t^2 + v_0 t\] 22 | \[s = v(t - t_v)\] 23 | 3 Möglichkeiten: 24 | 1. zu langsam 25 | 2. "zu" schnell 26 | 3. "perfekt" richtig $\implies$ gesucht 27 | 28 | \[\frac{1}{2}a t^2 + v_0 t = v_p (t - t_v)\] 29 | \[\implies t_{1,2} = \frac{v_p - v_0 \pm \sqrt{(v_0 - v_p)^2 - 2 a v_p t_v}}{a}\] 30 | 31 | \[(v_0 - v_p)^2 - 2 a v_p t_v = 0\] 32 | \rightarrow $v_p$ 33 | 34 | \[a t + v_0 = v_p \implies t = \frac{v_p - v_0}{a}\] 35 | \[v_p = v_0 + at_v \pm \sqrt{(at_v + v_0)^2 - v_0^2} \approx \SI{11.9}{\meter\per\second}\] 36 | 37 | \[x(t) = t v_{x0} = t v_0 \cos{\alpha}\] 38 | \[y(t) = t v_0 \sin{\alpha} - \frac{1}{2}gt^2\] 39 | \[x(T) = d\quad d = T v_0 \cos{\alpha} \implies t = \frac{d}{v_0 \cos{\alpha}}\] 40 | \[y(T) = \frac{d \sin{\alpha}}{\cos{alpha}} - \frac{1}{2} g \frac{d^2}{v_0^2 \cos^2{\alpha}}\] 41 | \[\implies v_0 = \sqrt{\frac{g d^2}{2\cos^2\alpha(d\tan\alpha - h)}}\] 42 | \[\Delta h = \frac{D_L - D_B}{2}\] 43 | \[v_0 = \sqrt{\frac{g d^2}{2\cos^2\alpha(a\tan \alpha - (h + \Delta h))}}\] 44 | -------------------------------------------------------------------------------- /ex2/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IFS=$'\n' 4 | 5 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/moodle) --delete-after https://elearning2.uni-heidelberg.de/login/index.php 6 | 7 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://elearning2.uni-heidelberg.de/course/view.php?id=14332' | pcregrep --buffer-size 10M -o1 '(https:\/\/elearning2\.uni-heidelberg\.de\/mod\/resource\/view\.php\?id=\d*?)"> \d*. Übungsblatt') 8 | 9 | echo $pdfs 10 | 11 | rm *.pdf 12 | 13 | for pdf in $pdfs 14 | do 15 | wget --content-disposition --load-cookies cookies.txt $pdf 16 | done 17 | -------------------------------------------------------------------------------- /ex3/tutorial/10/qmfdm/cy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import scipy.optimize as optimize 4 | 5 | def f(x,a): 6 | return x - np.sin(x) - a 7 | 8 | def fprime(x,a): 9 | return 1 - np.cos(x) 10 | 11 | n = 1000 12 | xs = np.linspace(0,2*np.pi,n) 13 | 14 | pret = xs - np.sin(xs) 15 | 16 | t = [] 17 | 18 | for x in xs: 19 | startx = xs[np.argmin(np.abs(pret - x))] 20 | t.append(optimize.newton(f, startx, fprime=fprime, args=(x,))) 21 | 22 | t = np.array(t) 23 | 24 | plt.plot(t - np.sin(t), 1 - np.cos(t), linestyle="None", marker="+") 25 | plt.show() 26 | -------------------------------------------------------------------------------- /ex3/tutorial/10/qmfdm/qmfdm.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | matplotlib.use('Qt5Agg') 3 | import matplotlib.pyplot as plt 4 | import matplotlib.animation as animation 5 | import numpy as np 6 | import scipy.sparse 7 | import scipy.sparse.linalg 8 | import scipy.optimize as optimize 9 | import numpy.linalg 10 | 11 | hbar = 1 12 | m = 1 13 | 14 | def laplace1d(n,dx): 15 | diag = ([[1,-2,1]] / (dx**2)[:,None]) 16 | # diag[0,:] = [0,0,0] 17 | # diag[-1,:] = [0,0,0] 18 | ret = scipy.sparse.diags(diag.T,[-1,0,1], shape=(n,n)) 19 | return ret 20 | 21 | def hamilton1d(n,dx,v): 22 | return - hbar * hbar / (2.0 * m) * laplace1d(n,dx) + v 23 | 24 | n = 1000 25 | x = np.linspace(0,5,n + 1) 26 | dx = x[:-1] - x[1:] 27 | #v = np.zeros(n) 28 | #v[np.abs(x[:-1]) > 2] = 50 # box potential 29 | # v = x[:-1]**2 # harmonic oszillator 30 | # v = -1.0 / np.abs(x[:-1]) # 1 / r 31 | # v[v < -10000000] = -10000000 32 | # v = np.exp(x[:-1]) 33 | # print(v) 34 | 35 | # cycloid 36 | 37 | def cy(x, a): 38 | return x - np.sin(x) - a 39 | 40 | def cyprime(x, a): 41 | return 1 - np.cos(x) 42 | xss = np.linspace(0, 1 * np.pi, n) 43 | pret = cy(xss, 0) 44 | t = [] 45 | 46 | for xs in xss: 47 | startx = xss[np.argmin(np.abs(pret - xs))] 48 | t.append(optimize.newton(cy, startx, fprime=cyprime, args=(xs, ))) 49 | t = np.array(t) 50 | 51 | v = 1.0* (-1.0 + np.cos(t)) + 2.0 52 | #ahalf = v[:n/2] 53 | #bhalf = v[n/2:] 54 | #v = np.append(bhalf, ahalf) 55 | 56 | V = scipy.sparse.diags([v], [0]) 57 | H = hamilton1d(n, dx, V) 58 | #print(H.todense()) 59 | k = 3 60 | 61 | w, vs = scipy.sparse.linalg.eigsh(H, k = k, which='SM', maxiter=1000000) 62 | #w, vs = numpy.linalg.eig(H.todense()) 63 | w = w[np.argsort(w)] 64 | vs = vs[:,np.argsort(w)] 65 | #print(np.abs(vs)) 66 | #print(w) 67 | 68 | #print(w) 69 | plt.plot(x[:-1], v / np.max(np.abs(v)) * np.max(np.abs(vs[:,:k])**2)) 70 | plt.plot(x[:-1], np.abs(vs[:,:k])**2) 71 | gaussian = np.exp(-(x[:-1] - 1)**2) 72 | plt.show() 73 | #plt.plot(w) 74 | coeffs = [] 75 | for eig in vs.T: 76 | coeffs.append(np.abs(np.dot(gaussian,eig))) 77 | 78 | coeffs = np.array(coeffs) 79 | 80 | #print np.dot(vs,) 81 | 82 | gmod = np.array(x.shape) 83 | gmod[:] = 0 84 | 85 | for (i, eig) in enumerate(vs.T): 86 | gmod = gmod + coeffs[i] * eig 87 | 88 | 89 | #print(gmod) 90 | #plt.plot(x[:-1],gaussian[:,None] * vs) 91 | #plt.plot(x[:-1],gaussian) 92 | #plt.plot(coeffs) 93 | #print(coeffs) 94 | #print(coeffs) 95 | #plt.plot(x[:-1], np.real(vs[:,:k])) 96 | #plt.plot(x[:-1], np.abs(vs[:,:k])**2) 97 | #plt.plot(x[:-1], -v * np.max(vs) / np.max(v)) 98 | #for e in v: 99 | #plt.show() 100 | 101 | f, (ax1, ax2) = plt.subplots(2,1,sharex='col') 102 | 103 | ax2.plot(x[:-1], v / 4) 104 | re, = ax1.plot(x[:-1], np.real(gmod)) 105 | im, = ax1.plot(x[:-1], np.imag(gmod)) 106 | a, = ax2.plot(x[:-1], np.abs(gmod)**2) 107 | 108 | ax1.set_ylim([-1.3,1.3]) 109 | ax2.set_ylim([-.1,1.3]) 110 | 111 | def init(): 112 | gmod = np.array(x.shape) 113 | gmod[:] = 0 114 | 115 | for (i, v) in enumerate(vs.T): 116 | gmod = gmod + coeffs[i] * v 117 | 118 | re.set_data(x[:-1], np.real(gmod)) 119 | im.set_data(x[:-1], np.imag(gmod)) 120 | a.set_data(x[:-1], np.abs(gmod)**2) 121 | # (WaveFunc, PotKurve, xVals) = calc(0) 122 | # re.set_data(xVals,np.real(WaveFunc)) 123 | # im.set_data(xVals,np.imag(WaveFunc)) 124 | # a.set_data(xVals,np.abs(WaveFunc)**2) 125 | def animate(t): 126 | gmod = np.array(x.shape) 127 | gmod[:] = 0 128 | for (i, v) in enumerate(vs.T): 129 | gmod = gmod + coeffs[i] * v * np.exp(-1.j * (w[i] / hbar) * t) 130 | 131 | re.set_data(x[:-1], np.real(gmod)) 132 | im.set_data(x[:-1], np.imag(gmod)) 133 | a.set_data(x[:-1], np.abs(gmod)**2) 134 | # (WaveFunc, PotKurve, xVals) = calc(i) 135 | # re.set_data(xVals,np.real(WaveFunc)) 136 | # im.set_data(xVals,np.imag(WaveFunc)) 137 | # a.set_data(xVals,np.abs(WaveFunc)**2) 138 | 139 | #for t in range(0,1000,100): 140 | # animate(t) 141 | #plt.show() 142 | #ani = animation.FuncAnimation(f, animate, np.linspace(0,12*np.pi,500), init_func=init) 143 | #ani.show() 144 | #ani.save('test.mp4', fps=25, dpi=100) 145 | -------------------------------------------------------------------------------- /ex3/tutorial/10/ssfm/ssfm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.fftpack as fft 3 | import matplotlib.pyplot as plt 4 | 5 | hbar = 1 6 | m = 1 7 | 8 | def normalize(x): 9 | return x / np.sqrt(np.sum(np.abs(x)**2)) 10 | 11 | def split_step_single(ψ, dt, n): 12 | xn = x0 13 | # k = 2*np.pi* 14 | 15 | N = 2000 16 | 17 | x = np.linspace(-30,30,N) 18 | dx = np.diff(x).mean() 19 | 20 | k = 2 * np.pi * fft.fftshift(fft.fftfreq(N, d = dx)) 21 | dk = np.diff(k).mean() 22 | 23 | # V = (np.pi)**2 * (m / 2) * x**2 24 | V = np.full(N, 0) 25 | #V[np.abs(x) > 20] = 1e10 26 | 27 | T = hbar**2 * k**2 / (2 * m) 28 | 29 | σ = 15 30 | x0 = 0 31 | k0 = 1 32 | ψ = normalize(np.exp(-(x - x0)**2 / (2 * σ**2))) 33 | ψ = fft.ifft(fft.fftshift(np.roll(fft.fftshift(fft.fft(ψ)), np.int(np.round(k0 / dk))))) 34 | dt = .5e-3 35 | tfin = 1000 36 | 37 | M = round(tfin / dt) 38 | ts = np.full(M, np.nan) 39 | calcval = ts.copy() 40 | calcval2 = ts.copy() 41 | 42 | fig = plt.figure(1) 43 | ax1 = fig.add_subplot(2,2,1) 44 | ax2 = fig.add_subplot(2,2,2) 45 | ax3 = fig.add_subplot(2,2,3) 46 | ax4 = fig.add_subplot(2,2,4) 47 | 48 | t = 0 49 | count = 0 50 | valcount = 0 51 | 52 | for m in range(0,M): 53 | t = t + dt 54 | count = count + 1 55 | ψ = fft.ifft(fft.fftshift(fft.fftshift(fft.fft( 56 | np.exp(-1j * V / hbar * dt) * ψ)) * np.exp(-1j * T / hbar * dt))) 57 | 58 | if count > 100: 59 | ts[valcount] = t 60 | ψk = fft.fftshift(fft.fft(ψ)) 61 | meank = np.sum(np.conj(ψk) * k * ψk) 62 | meank = np.real(meank) 63 | meank2 = np.sum(np.conj(ψk) * k**2 * ψk) 64 | meank2 = np.real(meank2) 65 | meanx = np.sum(np.conj(ψ) * x * ψ) 66 | meanx = np.real(meanx) 67 | meanx2 = np.sum(np.conj(ψ) * x**2 * ψ) 68 | meanx2 = np.real(meanx2) 69 | 70 | calcval[valcount] = np.sqrt(meanx2 - meanx**2) 71 | calcval2[valcount] = np.sqrt(meank2 - meank**2) 72 | valcount += 1 73 | 74 | count = 0 75 | ax1.cla() 76 | ax2.cla() 77 | ax3.cla() 78 | ax4.cla() 79 | ax1.plot(x, np.abs(ψ)**2) 80 | ax2.plot(k, np.abs(ψk)**2) 81 | ax3.plot(x, np.angle(ψ)) 82 | ax3.set_xlim([-10,10]) 83 | # ax3.set_ylim([-.01,.0]) 84 | ax4.plot(k, np.angle(ψk)) 85 | ax4.set_xlim([-2.5,2.5]) 86 | fig.canvas.draw() 87 | plt.pause(0.00001) 88 | 89 | 90 | -------------------------------------------------------------------------------- /ex3/tutorial/6/p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex3/tutorial/6/p -------------------------------------------------------------------------------- /ex5/demos/grid_dynamics.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import matplotlib.animation as animation 4 | 5 | 6 | x = np.linspace(0,30,1000) 7 | fig, ax = plt.subplots() 8 | line, = ax.plot(np.random.rand(1000)) 9 | ax.set_ylim(-1.1, 1.1) 10 | 11 | 12 | def update(data): 13 | line.set_ydata(data) 14 | return line, 15 | 16 | 17 | def data_gen(): 18 | t = 0 19 | q1 = 1 20 | q2 = 2 21 | while True: 22 | t += 0.1 23 | yield np.sin(x - q1 * t) + np.sin(x - q2 * t) 24 | 25 | ani = animation.FuncAnimation(fig, update, data_gen, interval=1.0/60.0*1000) 26 | plt.show() 27 | 28 | -------------------------------------------------------------------------------- /ex5/tutorial/1.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/1.art -------------------------------------------------------------------------------- /ex5/tutorial/10.gnuplot: -------------------------------------------------------------------------------- 1 | set xrange [-3.1415:3.1415] 2 | plot -0.8*cos(x), 12 + 1.5*cos(x), 3.617, 0.6 * cos(x)**(-1) 3 | 4 | -------------------------------------------------------------------------------- /ex5/tutorial/11.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/11.art -------------------------------------------------------------------------------- /ex5/tutorial/12.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/12.art -------------------------------------------------------------------------------- /ex5/tutorial/12.py: -------------------------------------------------------------------------------- 1 | from constant import * 2 | from numpy import * 3 | 4 | # 25 mm 5 | # c^25 = 10 6 | # 7 | # z = log(y) / log(c) 8 | # 9 | # (log(1) - log(10)) / log(c) = 25 10 | # 11 | # 18 mm 12 | 13 | c = exp((log(1) - log(10)) / 25.0) 14 | 15 | # (log(e-5) - log(x)) / log(c) = 18 16 | ρ1 = exp(-(18 * log(c) - log(1e-5))) * unit.ohm * unit.meter 17 | ρ2 = exp(-(4 * log(c) - log(1e-1))) * unit.ohm * unit.meter 18 | 19 | T1inv = 0.001 / unit.kelvin 20 | T2inv = 0.003 / unit.kelvin 21 | 22 | Eg = 2 * unit.boltzmann_constant * log(ρ1 / ρ2) / (T1inv - T2inv) 23 | 24 | print(Eg.to(unit.electron_volt)) 25 | 26 | # ρ1 = 27 | 28 | # EF = 5 * unit.boltzmann_constant * T + EV 29 | # EA = 0.15 * Eg + EV 30 | 31 | # T = 0.08 * Eg / unit.boltzmann_constant 32 | 33 | # EF - EA = 5 * 0.05 * Eg - 0.15 * Eg 34 | 35 | gA = 1 36 | 37 | nA = 5e23 / unit.meter**3 38 | 39 | nA0 = nA * (gA * exp((5 * 0.05 - 0.15) / 0.08) + 1)**(-1) 40 | 41 | nAm = nA - nA0 42 | print(nAm) 43 | -------------------------------------------------------------------------------- /ex5/tutorial/2.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/2.art -------------------------------------------------------------------------------- /ex5/tutorial/3.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/3.art -------------------------------------------------------------------------------- /ex5/tutorial/5.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/5.art -------------------------------------------------------------------------------- /ex5/tutorial/6.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/6.art -------------------------------------------------------------------------------- /ex5/tutorial/6_ewald.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/6_ewald.png -------------------------------------------------------------------------------- /ex5/tutorial/7.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/7.art -------------------------------------------------------------------------------- /ex5/tutorial/8.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/8.art -------------------------------------------------------------------------------- /ex5/tutorial/9.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/9.art -------------------------------------------------------------------------------- /ex5/tutorial/9.py: -------------------------------------------------------------------------------- 1 | from constant import * 2 | 3 | a = 3.61 * unit.angstrom 4 | e_F = (unit.ħ**2 / (2 * unit.m_e)) * (((3.0 / 2.0) * unit.π**2 / a**3))**(2.0/3.0) 5 | e_F = 4 * e_F # 4 atom with 1 electron each per unit cell 6 | print(e_F.to(unit.electron_volt)) 7 | print((e_F / unit.boltzmann_constant).to(unit.kelvin)) 8 | 9 | γ = unit.π**2 * unit.avogadro_number * unit.boltzmann_constant**2 / (2.0 * e_F) 10 | print(γ.to(unit.joule / unit.mol / unit.kelvin**2)) 11 | 12 | β = 12 * unit.π**4 * .2 * unit.avogadro_number * unit.boltzmann_constant * (345 * unit.kelvin)**(-3) 13 | print(β.to(unit.joule / unit.mol / unit.kelvin**4)) 14 | -------------------------------------------------------------------------------- /ex5/tutorial/__pycache__/constant.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/__pycache__/constant.cpython-36.pyc -------------------------------------------------------------------------------- /ex5/tutorial/black.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/black.art -------------------------------------------------------------------------------- /ex5/tutorial/blatt_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/blatt_5.jpg -------------------------------------------------------------------------------- /ex5/tutorial/blatt_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/blatt_5.png -------------------------------------------------------------------------------- /ex5/tutorial/brillouin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ex5/tutorial/brillouin.png -------------------------------------------------------------------------------- /ex5/tutorial/constant.py: -------------------------------------------------------------------------------- 1 | ../../astro1/tutorial/constant.py -------------------------------------------------------------------------------- /header_de.org: -------------------------------------------------------------------------------- 1 | #+INCLUDE: "header_common.org" :minlevel 1 2 | #+LATEX_HEADER: \setdefaultlanguage[spelling=new, babelshorthands=true]{german} 3 | -------------------------------------------------------------------------------- /header_en.org: -------------------------------------------------------------------------------- 1 | #+INCLUDE: "header_common.org" :minlevel 1 2 | #+LATEX_HEADER: \setdefaultlanguage{english} 3 | -------------------------------------------------------------------------------- /ipi/datatypes.org: -------------------------------------------------------------------------------- 1 | * Datentypen 2 | ** Basistypen 3 | Bestandteil der Sprachsyntax und normalerweise direkt von der Hardware unterstützt (CPU) 4 | - \code{int, double, bool} ($\implies$ später mehr) 5 | ** zusammengesetzte Typen 6 | Mit Hilfe von \code{struct} oder \code{class} aus einfachen Typen zusammengesetzt. 7 | Wie das geht $\implies$ später. 8 | Standardtypen: in der C++ Standardbibliothek definiert, aktivieren durch \code{\#include }. 9 | - \code{std::string, std::complex}, etc. 10 | externe Typen: aus anderer Bibliothek, die man zuvor herunterladen und installieren muss \\ 11 | eigene Typen: vom Programmierer selbst implementiert $\implies$ später \\ 12 | Durch "objekt-orientierte Programmierung" ($\implies$ später) erreicht man, dass zusammengesetzte 13 | Typen genauso einfach und bequem und effizient sind wie Basistypen (nur c++, nicht c) 14 | - "Kapselung": die interne Struktur und Implementation ist für Benutzer unsichtbar 15 | - Benutzer manipuliert Speicher über Funktionen ("member functions") $\estimates$ Schnittstelle des Typs, "Interface", API 16 | 17 | $\implies$ Punktsyntax: \code{type\_name t = init; t.foo(a1, a2);} $\estimates$ foo(t, a1, a2); 18 | ** Zeichenketten-Strings: 19 | zwei Datentypen in c++ 20 | klassischer c-string: \code{char[]} ("Charakter Array") $\implies$ nicht gekapselt, umständlich 21 | c++ string: \code{std::string} gekapselt und bequem (nur dieser in der Vorlesung) 22 | string Literale: "Zeichenkette", einzelnes Zeichen: 'z' ("z" = Kette der Länge 1) \\ 23 | Vorsicht: die String-Literale sind c-strings (gibt keine c++ string-Literale), 24 | müssen erst in c++ strings umgewandelt werden, das passiert meist automatisch. 25 | \code{\#include } 26 | Initialisierung: 27 | #+BEGIN_SRC cpp 28 | std::string s = "abcde"; 29 | std::string s2 = s1; 30 | std::string leer = ""; 31 | std::string leer(); // Abkürzung, default Konstruktor 32 | #+END_SRC 33 | Länge 34 | #+BEGIN_SRC cpp 35 | s.size(); 36 | assert(s.size() == 5); 37 | assert(leer.size() == 0); 38 | s.empty() // Abkürzung für s.size() == 0 39 | #+END_SRC 40 | Zuweisung 41 | #+BEGIN_SRC cpp 42 | s = "xy"; 43 | s2 = leer; 44 | #+END_SRC 45 | Addition: Aneinanderreihung von String ("concatenate") 46 | #+BEGIN_SRC cpp 47 | std::string s3 = s + "ijh"; // "xyijh" 48 | s3 = "ghi" + s; // "ghixy" 49 | s3 = s + s; // "xyxy" 50 | // aber nicht!! 51 | s3 = "abc" + "def"; // Bug Literale unterstützen + mit ganz anderer Bedeutung 52 | s3 = std::string("abc") + "def"; // OK 53 | #+END_SRC 54 | Add-Assignment: Abkürzung für Addition gefolgt von Zuweisung 55 | #+BEGIN_SRC cpp 56 | s += "nmk"; // s = s + "nmk" => "xynmk" 57 | #+END_SRC 58 | die Zeichen werden intern in einem C-Array gespeichert (Array = "Feld") \\ 59 | Array: zusammenhängende Folge von Speicherzellen des gleichen Typs, hier \code{char} (für einzelne Zeichen), Die Länge wird (bei \code{std::string}) automatisch angepasst, die einzelnen Speicherzellen sind durchnummeriert 60 | in c++: von $0$ beginnend $\estimates$ Index \\ 61 | Indexoperator: 62 | #+BEGIN_SRC cpp 63 | s[index]; // gibt das Zeichen an Position "index" zurück 64 | #+END_SRC 65 | Anwendung: jedes Zeichen einzeln ausgeben 66 | #+BEGIN_SRC cpp 67 | std::string s = "abcde"; 68 | 69 | for(int i = 0; i < s.size(); i++) { 70 | std::cout << s[i] << std::endl; 71 | } 72 | #+END_SRC 73 | String umkehren 74 | #+BEGIN_SRC cpp 75 | int i = 0; // Anfang des Strings 76 | int k = s.size() - 1; // Ende des String 77 | while(i < k) { 78 | char tmp = s[i]; 79 | s[i] = s[k]; 80 | s[k] = tmp; 81 | i++; k--; 82 | } 83 | #+END_SRC 84 | Variante 2: neuen String erzeugen 85 | #+BEGIN_SRC cpp 86 | std::string s = "abcde"; 87 | std::string r = ""; 88 | for(int i = s.size() - 1; i >= 0; i--) { 89 | r += s[i]; 90 | } 91 | #+END_SRC 92 | -------------------------------------------------------------------------------- /ipi/functional_programming.org: -------------------------------------------------------------------------------- 1 | * Funktionale Programmierung 2 | Bei Maschinensprache werden Zwischenergebnisse in Speicherzellen abgelegt. 3 | Das ist auch in der funktionalen Programmierung eine gute Idee. 4 | Speicherzellen werden durch Namen (vom Programmierer vergeben) unterschieden. 5 | #+begin_ex latex 6 | Lösen einer quadratischen Gleichung: 7 | \begin{align*} 8 | ax^2 + bx + c &= 0 \\ 9 | x^2 - 2px + q &= 0, p = -\frac{b}{2a},q=\frac{c}{d} \\ 10 | x_2 &= p + \sqrt{p^2 - q},x_2 = p - \sqrt{p^2 - q} \\ 11 | \end{align*} 12 | ohne Zwischenergebnisse: \\ 13 | \code{\(x_1 \leftarrow\) add(div(div(b,a),-2),sqrt(sub(mul(div(b,a),-2),div(div(b,a),-1)),div(c,a)))} 14 | mit Zwischenergebnis und Infix Notation 15 | #+begin_center latex 16 | \code{p \(\leftarrow\) b / c / -2} oder \code{p \(\leftarrow\) -0.5 * b / a} \\ 17 | \code{a \(\leftarrow\) c / a} \\ 18 | \code{d \(\leftarrow\) sqrt(p*p - q)} \\ 19 | \code{\(x_1 \leftarrow\) p + d} \\ 20 | \code{\(x_2 \leftarrow\) p - d} \\ 21 | #+end_center 22 | #+end_ex 23 | Vorteile von Zwischenergebnissen: 24 | 1. lesbarer 25 | 2. redundante Berechnung vermieden. Beachte: In der funktionalen Programmierung können die Speicherzellen nach der Initialisierung nicht mehr verändert werden 26 | 3. Speicherzellen und Namen sind nützlich um Argumente an Funktionen zu übergeben $\implies$ Definition eigener Funktionen 27 | #+BEGIN_SRC cpp 28 | function sq(x) { 29 | return x * x 30 | } 31 | #+END_SRC 32 | $\implies$ \code{d \(\leftarrow\) sqrt(sq(p) - q)} 33 | Speicherzelle mit Namen "x" für das Argument von $sq$ 34 | ** Funktionale Programmierung in c++ 35 | In c++ hat jede Speicherzelle einen Typ (legt Größe und Bedeutung der Speicherzelle fest). Wichtige Typen: 36 | | \code{int} | ganze Zahlen | 37 | | \code{double} | reelle Zahlen | 38 | | \code{std::string} | Text | 39 | \code{int}: $12,-3$ \\ 40 | \code{double}: $-1.02,1.2e-4 = 1.2*10^{-4}$ \\ 41 | \code{std::string}: "text" \\ 42 | Initialisierung wird geschrieben als \code{typename spzname = Wert;} 43 | #+BEGIN_SRC cpp 44 | double a = ...; 45 | double b = ...; 46 | double c = ...; 47 | double p = -0.5 b / a; 48 | double q = c / a; 49 | double d = std::sqrt(p*p - q); 50 | double x1 = p + d; 51 | double x2 = p - d; 52 | std::cout << "x1: " << x1 << ", x2: " << x2 << std::endl; 53 | #+END_SRC 54 | Eigene Funktionen in C++: 55 | #+BEGIN_SRC cpp 56 | // Kommentar (auch /* */) 57 | type_ergebnis fname(type_arg1 name1, ...) { 58 | // Signatur / Funktionskopf / Deklaration 59 | return ergebnis; 60 | /* Funktionskörper / Definition / Implementation */ 61 | } 62 | #+END_SRC 63 | Ganze Zahl quadrieren: 64 | #+BEGIN_SRC cpp 65 | int sq(int x) { 66 | return x*x; 67 | } 68 | #+END_SRC 69 | reelle Zahl quadrieren: 70 | #+BEGIN_SRC cpp 71 | double sq(double x) { 72 | return x*x; 73 | } 74 | #+END_SRC 75 | beide Varianten dürfen in c++ gleichzeitig definiert sein $\implies$ "function overloading" $\implies$ c++ wählt automatisch die richtig Variable anhand des Argumenttyps ("overload resolution") 76 | #+BEGIN_SRC cpp 77 | int x = 2; 78 | double y = 1.1 79 | int x2 = sq(x) // int Variante 80 | double y2 = sq(y) // double Variante 81 | #+END_SRC 82 | jedes c++-Programm muss genau eine Funktion namens \code{main} haben. Dort beginnt die Programmausführung. 83 | #+BEGIN_SRC cpp 84 | int main() { 85 | Code; 86 | return 0; 87 | } 88 | #+END_SRC 89 | Return aus der "main" Funktion ist optional. Regel von c++ für erlaubte Name: 90 | - erstes Zeichen: Klein- oder Großbuchstaben des englischen Alphabets, oder "_" 91 | - optional: weitere Zeichen oder, "_" oder Ziffer 0-9 92 | vordefinierte Funktionen: \\ 93 | Eingebaute $\estimates$ immer vorhanden: 94 | - Infix-Operatoren $+,-,*,/,\%$ 95 | - Präfix-Operatoren $operator+,operator-,\ldots$ 96 | Funktion der Standardbibliothek $\estimates$ müssen "angefordert" werden. 97 | - Namen beginnen mit "std::", "std::sin,..." 98 | - sind in Module geordnet, zum Beispiel 99 | - cmath $\implies$ algebraische Funktion 100 | - complex $\implies$ komplexe Zahlen 101 | - string $\implies$ Zeichenkettenverarbeitung 102 | Um ein Modul zu benutzen muss man zuerst (am Anfang des Programms) sein Inhaltsverzeichnis importieren (Header inkludieren) $\rightarrow$ include 103 | #+BEGIN_SRC cpp 104 | #include 105 | #include 106 | int main() { 107 | std::cout << "Hello, world!" << std::endl; 108 | std::string out = "mein erstes Programm\n"; 109 | std::cout << out; 110 | return 0; 111 | } 112 | #+END_SRC 113 | Overloading der arithmetischen Operationen: 114 | overloading genau wie bei \code{sq} 115 | - 3 * 4 $\implies$ \code{int} Variante 116 | - 3.0 * 4.0 $\implies$ \code{double} Variante 117 | - 3 * 4.0 $\implies$ automatische Umwandlung in höheren Typ, hier \code{double} $\implies$ wird als 3.0 * 4.0 ausgeführt 118 | $\implies$ Division unterscheidet sich 119 | - Integer-Division: 12 / 5 = 2 (wird abgerundet) 120 | - Double-Division: 12.0 / 5.0 = 2.4 121 | - -12 / 5 = 2 ($\implies$ truncated Division) 122 | - 12.0 / 5.0 = 2.4 123 | - Gegensatz (zum Beispiel in Python): 124 | - floor division $\implies$ wird immer abgerundet \(\implies\)-12 / 4 = -2 125 | -------------------------------------------------------------------------------- /ipi/introduction.org: -------------------------------------------------------------------------------- 1 | * Was ist Informatik? 2 | "Kunst" Aufgaben mit Computerprogrammen zu lösen. 3 | ** Teilgebiete 4 | *** theoretische Informatik (*ITH*) 5 | - Berechenbarkeit: Welche Probleme kann man mit Informatik lösen und welche prinzipiell nicht? 6 | - Komplexität: Welche Probleme kann man effizient lösen? 7 | - Korrektheit: Wie beweist man, dass das Ergebnis richtig ist? \\ 8 | Echtzeit: Dass das richtige Ergebnis rechtzeitig vorliegt. 9 | - verteilte Systeme: Wie sichert man, dass verteilte Systeme korrekt kommunizieren? 10 | *** technische Informatik (*ITE*) 11 | - Auf welcher Hardware kann man Programme ausführen, wie baut man dies Hardware? 12 | - CPU, GPU, RAM, HD, Display, Printer, Networks 13 | *** praktische Informatik 14 | - Wie entwickelt man Software? 15 | - Programmiersprachen und Compiler: Wie kommuniziert der Programmierer mit der Hardware?\hfill *IPI, IPK* 16 | - Algorithmen und Datenstrukturen: Wie baut man komplexe Programme aus einfachen Grundbausteinen?\hfill *IAL* 17 | - Softwaretechnik: Wie organisiert man sehr große Projekte?\hfill *ISW* 18 | - Kernanwendung der Informatik: Betriebssysteme, Netzwerke, Parallelisierung\hfill *IBN* 19 | - Datenbanksysteme\hfill *IDB1* 20 | - Graphik, Graphische Benutzerschnittstellen\hfill *ICG1* 21 | - Bild- und Datenanalyse 22 | - maschinelles Lernen 23 | - künstliche Intelligenz 24 | *** angewandte Informatik 25 | - Wie löst man Probleme aus einem anderem Gebiet mit Programmen? 26 | - Informationstechnik 27 | - Buchhandlung, e-Kommerz, Logistik 28 | - Web Programmierung 29 | - scientific computing für Physik, Biologie 30 | - Medizininformatik 31 | - bildgebende Verfahren 32 | - digitale Patientenakte 33 | - Computer Linguistik 34 | - Sprachverstehen, automatische Übersetzung 35 | - Unterhaltung: Spiele, special effects im Film 36 | -------------------------------------------------------------------------------- /ipi/itertators.org: -------------------------------------------------------------------------------- 1 | * Iteratoren 2 | Für Arrays lautet die kanonische Schleife 3 | #+BEGIN_SRC cpp 4 | for(int i = 0; i != v.size(); i++) { 5 | int current = v[i]; // lesen 6 | v[i] = new_value; // schreiben 7 | } 8 | #+END_SRC 9 | Wir wollen eine so einfache Schleife für beliebige Container. 10 | Der Index-Zugriff v[] ist bei den meisten Container nicht effizient. 11 | Iteratoren sind immer effizient $\implies$ es gibt sie in allen modernen Programmiersprachen, aber Details sehr unterschiedlich. 12 | Analogie: Zeiger einer Uhr, Cursor in Textverarbeitung. 13 | $\implies$ ein Iterator zeigt immer auf ein Element des Containers, oder auf Spezialwert "ungültiges Element". 14 | In c++ unterstützt jeder Iterator 5 Grundoperationen 15 | 1. Iterator auf erstes Element erzeugen: \code{auto iter = v.begin();} 16 | 2. Iterator auf "ungültiges Element" erzeugen: \code{auto end = v.end();} 17 | 3. Vergleich \code{iter1 == iter2} (Zeigen auf gleiches Element), \code{iter != end}: iter zeigt *nicht* auf ungültiges Element 18 | 4. zum nächsten weitergehen: \code{++iter}. Ergebnis ist \code{v.end()}, wenn man vorher beim letzten Element war 19 | 5. auf Daten zugreifen: \code{*iter ("Dereferenzierung") analog \code{v[k]} 20 | kanonische Schleife: 21 | #+BEGIN_SRC cpp 22 | for(auto iter = v.begin(); iter != v.end(); ++iter) { 23 | int current = *iter; // lesen 24 | *iter = new_value; // schreiben 25 | } 26 | 27 | // Abkürzung: range-based for loop 28 | for(auto & element : v) { 29 | int current = element; // lesen 30 | element = new_value; // schreiben 31 | } 32 | #+END_SRC 33 | Iteratoren mit den 5 Grundoperationen heißen "forward iterator" (wegen \code{++iter}). 34 | - "bidirectional iterators": unterstützen auch \code{--iter}, zum vorigen Element ((fast) alle Iteratoren in \code{std}) 35 | - "random access iterators": beliebige Sprünge \code{iter += 5; iter -= 3;} 36 | Besonderheit für assoziative Arrays (\code{std::map, std::unordered\_map}): Schlüssel und Werte können beliebig gewählt werden. 37 | $\implies$ das aktuelle Element ist ein Schlüssel / Wert -Paar, das heißt Iterator gibt Schlüssel und Wert zurück 38 | #+BEGIN_SRC cpp 39 | (*iter).first; // Schlüssel 40 | (*iter).second; // Wert 41 | // Abkürzung 42 | iter->first; 43 | iter->second; 44 | #+END_SRC 45 | bei \code{std::map} liefern die Iteratoren die Elemente in aufsteigender Reihenfolge der Schlüssel. \\ 46 | Wir hatten: \code{std::copy()} 47 | #+BEGIN_SRC cpp 48 | std::vector source = {1, 2, 3, 4}; 49 | std::vector target(source.size()); 50 | std::copy(source.begin(), source.end(), target.begin()); 51 | #+END_SRC 52 | \code{std::transform}: 53 | #+BEGIN_SRC cpp 54 | // nach Kleinbuchstaben konvertieren 55 | std::string source = "aAbCdE"; 56 | std::string target = source; 57 | std::transform(source.begin(), source.end(), target.begin(), std::tolower); // Name einer Funktion, die ein einzelnes Element transformiert, t="aabcde" 58 | // die Daten quadrieren 59 | double sq(double x) { return x * x; } 60 | std::transform(source.begin(), source.end(), target.begin(), sq); // target == {1, 4, 9, 16} 61 | // das ist eine Abkürzung für eine Schleife 62 | auto src_begin = source.begin(); 63 | auto src_end = source.end(); 64 | auto tgt_begin = target.begin(); 65 | 66 | for(; src_begin != src_end; src_begin++, tgt_begin++) { 67 | *tgt_begin = sq(*src_begin); 68 | } 69 | #+END_SRC 70 | Der Argumenttyp der Funktion muss mit dem source Elementtyp kompatibel sein. Der Returntyp der Funktion muss mit dem Target-Elementtyp kompatibel sein. 71 | Das letzte Argument von \code{std::transform()} muss ein Funktor sein (verhält sich wie eine Funktion), drei Varianten: 72 | 1. normale Funktion, z.B. sq. Aber: wenn Funktion für mehrere Argumenttypen überladen ist (overloading) (zum Beispiel, wenn es sq(double) und sq(int) gibt), muss der Programmierer dem Compiler sagen, welche Version gemeint ist $\implies$ für Fortgeschrittene ("functionpointer cast") 73 | 2. Funktionsobjekt $\implies$ objekt-orientierte Programmierung 74 | 3. Definiere eine namenlose Funktion $\implies$ "Lambda-Funktion $\lambda$" 75 | - statt $\lambda$ verwenden wir den Universalnamen [] 76 | #+BEGIN_SRC cpp 77 | std::transform(source.begin(), source.end(), target.begin(), [](double x) { return x*x; }); // statt Funktionsname sq wie bei 1 steht hier die ganz Funktionsimplementation 78 | // Returntyp setzt Computer automatisch ein, wenn es nur einen return-Befehl gibt. 79 | #+END_SRC 80 | - Lambda-Funktionen können noch viel mehr $\implies$ für Fortgeschrittene 81 | - \code{std::transform()} kann in-place arbeiten (das heißt source-Container überschreiben), wenn source und target gleich 82 | #+BEGIN_SRC cpp 83 | std::transform(source.begin(), source.end(), source.begin(), sq); 84 | #+END_SRC 85 | Die Funktion \code{std::sort()} zum in-place sortieren eines Arrays: 86 | #+BEGIN_SRC cpp 87 | std::vector v = {4, 2, 3, 5 ,1}; 88 | std::sort(v.begin(), v.end()); // v == {1, 2, 3, 4, 5} 89 | #+END_SRC 90 | \code{std::sort} ruft intern den \(<\)-Operator des Elementtyps auf, um Reihenfolge zu bestimmen. 91 | Die \(<\)-Operation muss eine totale Ordnung der Elemente definieren: 92 | - $a < b$ muss für beliebige $a,b$ ausführbar sein 93 | - transitiv: $(a < b) \wedge (b < c) \implies (a < c)$ 94 | - anti-symmetrisch: $\neg(a < b) \wedge \neg(b < a) \implies a == b$ 95 | -------------------------------------------------------------------------------- /ipi/machine_code.org: -------------------------------------------------------------------------------- 1 | * Maschinensprachen 2 | - optimiert für die Hardware 3 | - Gegensatz: höhere Programmiersprachen (c++) 4 | - optimiert für Programmierer 5 | - Compiler oder Interpreter übersetzen Hoch- in Maschinensprache 6 | ** Umwandlung in Maschinensprache 7 | 1. Eingaben und (Zwischen)-Ergebnisse werden in Speicherzellen abgespeichert $\implies$ jeder Knoten im Baum bekommt eine Speicherzelle 8 | 2. Speicherzellen für Eingaben initialisieren 9 | - Notation: SpZ \leftarrow Wert 10 | 3. Rechenoperationen in Reihenfolge des Substitutionsmodell ausführen und in der jeweiligen Speicherzelle speichern 11 | - Notation: SpZ-Ergebnis \leftarrow fname SpZArg1 SpZArg2 12 | 4. alles in Zahlencode umwandeln 13 | - Funktionsnamen: 14 | | Opcode | Wert | 15 | |--------+------| 16 | | init | 1 | 17 | | add | 2 | 18 | | sub | 3 | 19 | | mul | 4 | 20 | | div | 5 | 21 | | | | 22 | -------------------------------------------------------------------------------- /ipi/references.org: -------------------------------------------------------------------------------- 1 | * Referenzen 2 | Referenzen sind neue (zusätzliche) Namen für vorhandene Speicherzellen. 3 | #+BEGIN_SRC cpp 4 | int x = 3; // neue Variable x mit neuer Speicherzelle 5 | int & y = x; // Referenz: y ist neuer Name für x, beide haben die selbe Speicherzelle 6 | y = 4; // Zuweisung an y, aber x ändert sich auch, das heißt x == 4 7 | x = 5; // jetzt y == 5 8 | int const & z = x; // read-only Referenz, das heißt z = 6 ist verboten 9 | x = 6; // jetzt auch z == 6 10 | #+END_SRC 11 | Hauptanwendung: 12 | - die Umgebung, in der eine Funktion aufgerufen wird und die Umgebung der Implementation sind unabhängig, das heißt Variablen der einen Umgebung sind in der anderen nicht sichtbar 13 | - häufig möchte man Speicherzellen in beiden Umgebungen teilen $\implies$ verwende Referenzen 14 | - häufig will man vermeiden, dass eine Variable kopiert wird (pass-by-value) 15 | - Durch pass-by-reference braucht man keine Kopie $\implies$ typisch "const &", also read-only, keine Seiteneffekte 16 | #+BEGIN_SRC cpp 17 | int foo(int x) { // pass-by-value 18 | x += 3; 19 | return x; 20 | } 21 | 22 | int bar(int & y) { // pass-by-reference 23 | y += 3; // Seiteneffekt der Funktion 24 | return y; 25 | } 26 | 27 | void baz(int & z) { // pass-by-reference 28 | z += 3; 29 | } 30 | 31 | int main() { 32 | int a = 3; 33 | std::cout << foo(a) << std::endl; // 5 34 | std::cout << a << std::endl; // 3 35 | std::cout << bar(a) << std::endl; // 5 36 | std::cout << a << std::endl; // 5 37 | baz(a); 38 | std::cout << a << std::endl; // 8 39 | } 40 | #+END_SRC 41 | In der funktionalen Programmierung sind Seiteneffekte grundsätzlich verboten, 42 | mit Ausnahmen, zum Beispiel für Ein-/Ausgabe. 43 | -------------------------------------------------------------------------------- /ipi/stack_model.org: -------------------------------------------------------------------------------- 1 | * Umgebungsmodell 2 | Gegenstück zum Substitutionsmodell (in der funktionalen Programmierung) für die prozedurale Programmierung. 3 | Regeln für Auswertung von Ausdrücken, Regeln für automatische Speicherverwaltung 4 | - Freigeben nicht mehr benötigter Speicherzellen, $\implies$ bessere Approximation von "unendlich viel Speicher" 5 | Umgebung beginnt normalerweise bei "{" und endet bei "}". Ausnahmen: 6 | - $for$: Umgebung beginnt schon bei "for" $\implies$ Laufvariable ist Teil der Umgebung 7 | - Funktionsdefinitionen: Umgebung beginnt beim Funktionskopf $\implies$ Speicherzellen für Argumente und Ergebnis gehören zur Umgebung 8 | - globale Umgebung außerhalb aller "{ }" Klammern 9 | automatische Speicherverwaltung 10 | - Speicherzellen, die in einer Umgebung angelegt werde (initialisiert, deklariert) werde, am Ende der Umgebung in umgekehrter Reihenfolge freigegeben 11 | - Computer fügt vor "}" automatisch die Notwendigen Befehle ein 12 | - Speicherzellen in der globalen Umgebung werden am Programmende freigegeben 13 | #+BEGIN_SRC cpp 14 | int global = 1; 15 | int main() { 16 | int l = 2; 17 | { 18 | int m = 3 19 | } // <- m wird freigegeben 20 | } // <- l wird freigegeben 21 | // <- global wird freigegeben 22 | #+END_SRC 23 | Umgebungen können beliebig geschachtelt werden $\implies$ alle Umgebungen bilden einen Baum, mit der globalen Umgebung als Wurzel. 24 | Funktionen sind in der globalen Umgebung definiert. 25 | Umgebung jeder Funktion sind Kindknoten der globalen Umgebung (Ausnahme: Namensräume $\implies$ siehe unten) \\ 26 | $\implies$ Funktions Umgebung ist *nicht* in der Umgebung, wo die Funktion aufgerufen wird 27 | Jede Umgebung besitzt eine *Zuordnungstabelle* für alle Speicherzellen, die in der Umgebung definiert wurden 28 | | Name | Typ | aktueller Wert | 29 | |------+-----+----------------| 30 | | l | int | 2 | 31 | Jeder Name kann pro Umgebung nur einmal vorkommen. 32 | Ausnahme: Funktionsnamen können mehrmals vorkommen bei function overloading (nur c++). 33 | Alle Befehle werden relativ zur aktuellen Umgebung ausgeführt. \\ 34 | aktuell: Zuordnungstabelle der gleichen Umgebung und aktueller Wert zum Zeitpunkt des Aufrufs \\ 35 | Beispiel: $c = a * b;$ \\ 36 | Regeln: 37 | - wird der Name (nur $a, b, c$) in der aktuellen Zuordnungstabelle gefunden 38 | 1. Typprüfung $\implies$ Fehlermeldung, wenn Typ und Operation nicht zusammenpassen 39 | 2. andernfalls, setze aktuellen Wert aus Tabelle in Ausdruck ein (ähnlich Substitutionsmodell) 40 | - wird Name nicht gefunden: suche in der Elternumgebung weiter 41 | - wird der Name bis zur Wurzel (globale Umgebung) nicht gefunden $\implies$ Fehlermeldung 42 | - $\implies$ ist der Name in mehreren Umgebungen vorhanden gilt der zuerst gefundene (Typ, Wert) 43 | - $\implies$ Programmierer muss selbst darauf achten, dass 44 | 1. bei der Suche die gewünschte Speicherzelle gefunden wird $\implies$ benutze "sprechende Namen" 45 | 2. der aktuelle Wert der richtig ist $\implies$ beachte Reihenfolge der Befehle! 46 | - Namensraum: spezielle Umgebungen in der globalen Umgebung (auch geschachtelt) mit einem Namen \\ 47 | Ziele: 48 | - Gruppieren von Funktionalität in Module (zusätzlich zu Headern) 49 | - Verhinderung von Namenskollisionen 50 | Beispiel: c++ Standardbibliothek: 51 | #+BEGIN_SRC cpp 52 | namespace std { 53 | double sqrt(double x); 54 | namespace chrono { 55 | class system_clock; 56 | } 57 | } 58 | 59 | // Benutzung mit Namespace-Präfix: 60 | std::sqrt(80); 61 | std::chrono::system_clock clock; 62 | #+END_SRC 63 | Besonderheit: mehrere Blöcke mit selbem Namensraum werden verschmolzen. 64 | #+BEGIN_SRC cpp 65 | int p = 2; 66 | int q = 3; 67 | 68 | int foo(int p) { 69 | return p * q; 70 | } 71 | 72 | int main() { 73 | int k = p * q; // beides global => 6 = 2 * 3 74 | int p = 4; // lokales p verdeckt globales p 75 | int r = p * q; // p lokal, q global => 12 = 4 * 3 76 | int s = foo(p); // lokale p von main() wird zum lokalen p von foo() 12 = 4 * 3 77 | int t = foo(q); // globales q wird zum lokalen p von foo() 9 = 3 * 3 78 | int q = 5; 79 | int n = foo(g); // lokales q wird zum lokalen p von foo() 15 = 5 * 3 80 | } 81 | #+END_SRC 82 | -------------------------------------------------------------------------------- /ipi/substitution_model.org: -------------------------------------------------------------------------------- 1 | * Substitutionsmodell (funktionale Programmierung) 2 | Einfaches Modell für arithmetische Berechnung "Taschenrechner". Eingaben und Ausgaben sind Zahlen (ganze oder reelle Zahlen). Zahlenkonstanten heißen "Literale" 3 | Elementare Funktionen: haben eine oder mehrere Zahlen als Argumente (Parameter) und liefern eine Zahl als Ergebnis (wie Mathematik): 4 | \code{add(1,2) \(\to\) 3, mul(2,3) \(\to\) 6}, analog \code{sub(), div(), mod()} 5 | Funktionsaufrufe können verschachtelt werden, das heißt Argumente kann Ergebnis einer anderen Funktion sein. \\ 6 | \code{mul(add(1,2),sub(5,3)) \(\to\) 6} 7 | ** Substitutionsmodell 8 | Man kann einen Funktionsaufruf, dessen Argument bekannt ist (das heißt Zahlen sind) durch den Wert des Ergebnisses ersetzen ("substituieren"). Geschachtelte Ausdrücke lassen sich so von innen nach außen auswerten. 9 | #+begin_center latex 10 | \code{mul(add(1,2),sub(5,3))} \\ 11 | \code{mul(3,sub(5,3))} \\ 12 | \code{mul(3,2)} \\ 13 | \code{6} 14 | #+end_center 15 | Die arithmetischen Operationen add(), sub(), mul(), div(), mod() werden normalerweise von der Hardware implementiert. 16 | Die meisten Programmiersprachen bieten außerdem algebraische Funktionen wie: \code{sqrt(), sin(), cos(), log()}. 17 | Diese sind meist nicht in Hardware, aber vorgefertigte Algorithmen, werden mit Programmiersprachen geliefert, "Standardbibliothek". 18 | In C++: mathematisches Modul des Standardbibliothek: "cmath". 19 | Für Arithmetik gebräuchlicher ist "Infix-Notation" mit Operator-Symbolen "+", "-", "*", "/", "%" \\ 20 | \code{mul(add(1,2),sub(5,3)) $\iff$ ((1+2)*(5-3))} \\ 21 | Oft besser, unter anderem weil man Klammer weglassen darf. 22 | 1. "Punkt vor Strichrechnung" 3+4*5 $\iff$ 3+(4*5), \code{mul, div, mod} binden stärker als \code{add, sub} 23 | 2. Operatoren gleicher Präzedenz werden von links nach rechts ausgeführt (links-assoziativ) \\ 24 | 1+2+3-4+5 $\iff$ ((((1+2)+3)-4)+5) 25 | 3. äußere Klammer kann man weglassen (1+2)$\iff$ 1+2 26 | Computer wandeln Infix zuerst in Präfix Notation um 27 | 1. weggelassene Klammer wieder einfügen 28 | 2. Operatorensymbol durch Funktionsnamen ersetzen und an Präfix-Position verschieben \\ 29 | #+begin_center latex 30 | \code{1 + 2 + 3 * 4 / (1 + 5) - 2} \\ 31 | \code{(((1 + 2) + ((3 * 4) / (1 + 5))) - 2)} \\ 32 | \code{sub(add(add(1,2),div(mul(3,4),add(1,5))), 2)} \\ 33 | \code{sub(add(3,div(12,6)), 2)} \\ 34 | \code{sub(add(3,2), 2)} \\ 35 | \code{sub(5, 2)} \\ 36 | \code{2} 37 | #+end_center 38 | ** Bäume 39 | Bestehen aus Knoten und Kanten (Kreise und Pfeile). 40 | Kanten verbinden Knoten mit ihren Kind-knoten. 41 | Jeder Konten (außer der Wurzel) hat genau ein Elternteil ("parent node"). 42 | Knoten ohne Kinder heißen Blätter ("leaves / leaf node"). 43 | Teilbaum: 44 | - wähle beliebigen Knoten 45 | - entferne temporär dessen Elternkante, dadurch wird der Knoten temporär zu einer Wurzel, dieser Knoten mit allen Nachkommen bildet wieder einen Baum (Teilbaum des Originalbaumes) 46 | - trivialer Teilbaum hat nur einen Knoten 47 | Tiefe: Abstand eines Knotens von der Wurzel (Anzahl der Kanten zwischen Knoten und Wurzel) 48 | - Tiefe des Baums: maximale Tiefe eines Knoten 49 | #+begin_ex latex 50 | \mbox{} 51 | \begin{center} 52 | \code{1 + 2 + 3 * 4 / (1 + 5) - 2} \\ 53 | \code{sub(add(add(1,2),div(mul(3,4),add(1,5))), 2)} \\ 54 | \Tree [ .sub [ .add [ .add 1 2 ] [ .div [ .mul 3 4 ] [ .add 1 5 ] ] ] 2 ] 55 | \end{center} 56 | #+end_ex 57 | ** Rekursion 58 | Rekursiv $\estimates$ Algorithmus für Teilproblem von vorn. 59 | ** Präfixnotation aus dem Baum rekonstruieren 60 | 1. <> Wenn die Wurzel ein Blatt ist: Drucke die Zahl 61 | 2. sonst: 62 | - Drucke Funktionsnamen 63 | - Drucke "(" 64 | - Wiederhole den Algorithmus ab [[algstart1]] für das linke Kind (Teilbaum mit Wurzel = linkes Kind) 65 | - Drucke "," 66 | - Wiederhole den Algorithmus ab [[algstart1]] für das rechte Kind (Teilbaum mit Wurzel = rechtes Kind) 67 | - Drucke ")" 68 | $\implies$ \code{sub(add(add(1,2),div(mul(3,4),add(1,5))), 2)} 69 | ** Infixnotation aus dem Baum rekonstruieren 70 | 1. <> Wenn die Wurzel ein Blatt ist: Drucke die Zahl 71 | 2. sonst: 72 | - Drucke Funktionsnamen 73 | - Drucke "(" 74 | - Wiederhole den Algorithmus ab [[algstart2]] für das linke Kind (Teilbaum mit Wurzel = linkes Kind) 75 | - Drucke Operatorsymbol 76 | - Wiederhole den Algorithmus ab [[algstart2]] für das rechte Kind (Teilbaum mit Wurzel = rechtes Kind) 77 | - Drucke ")" 78 | $\implies$ \code{sub(add(add(1,2),div(mul(3,4),add(1,5))), 2)} 79 | $\implies$ *inorder* 80 | ** Berechnen des Wertes mit Substitutionsmodell 81 | 1. <> Wenn Wurzel dein Blatt gib Zahl zurück 82 | 2. sonst: 83 | - Wiederhole den Algorithmus ab [[algstart3]] für das linkes Kind (Teilbaum mit Wurzel = rechtes Kind), speichere Ergebnis als "lhs" 84 | - Wiederhole den Algorithmus ab [[algstart3]] für das rechte Kind (Teilbaum mit Wurzel = rechtes Kind), speichere Ergebnis als "rhs" 85 | - berechne funktionsname(lhs,rhs) und gebe das Ergebnis zurück 86 | $\implies$ *post-order* 87 | -------------------------------------------------------------------------------- /ipi/tutorial/01/1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[auto,node distance=8cm, semithick, text width=2.5cm, align=center, sloped] 2 | \node[initial,state] (idle) {idle}; 3 | \node[state] (1€) [above right of=idle] {1€ bezahlt}; 4 | \node[state] (2€) [below right of=1€] {2€ bezahlt}; 5 | \node[state] (mk) [below left of=2€]{Münzkassette überprüfen}; 6 | \node[state] (ab) [below of=idle]{Außer Betrieb}; 7 | \path 8 | (idle) edge [loop above] node [above] {Münze $\neq 1€ \vee 2€$} node [below] {Münze wieder auswerfen} (idle) 9 | edge [loop below] node {Abbrechen gedrückt} (idle) 10 | edge node [above] {1€ eingeworfen} (1€) 11 | edge [bend left] node {2€ eingeworfen} (2€) 12 | (1€) edge node [above] {1€ eingeworfen} (2€) 13 | edge [loop above] node [above] {Münze $\neq 1€ \vee 2€$} node [below] {Münze wieder auswerfen} (1€) 14 | edge node [above] {2€ eingeworfen} node [below] {Fahrkarte drucken} (mk) 15 | edge [bend right] node [above] {Abbrechen gedrückt} node [below] {1€ auswerfen} (idle) 16 | (2€) edge node [above] {1€ eingeworfen} node [below] {Fahrkarte drucken}(mk) 17 | edge [loop above] node [above] {Münze $\neq 1€ \vee 2€$} node [below] {Münze wieder auswerfen} (2€) 18 | edge [loop left=120] node [above] {2€ eingeworfen} node [below] {2€ auswerfen} (2€) 19 | edge [bend left] node [above] {Abbrechen gedrückt} node [below] {2€ auswerfen} (idle) 20 | (mk) edge node [above] {Münzkassette voll} (ab) 21 | edge node [above] {Münzkassette nicht voll} (idle) 22 | (ab) edge [loop below] node [above] {Münze eingeworfen} node [below] {Münze wieder auswerfen, Meldung "Außer Betrieb" anzeigen} (ab); 23 | \end{tikzpicture} 24 | -------------------------------------------------------------------------------- /ipi/tutorial/01/Heinemann.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ipi/tutorial/01/Heinemann.zip -------------------------------------------------------------------------------- /ipi/tutorial/03/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using i32 = std::int32_t; 16 | using f64 = double; 17 | 18 | using str = std::string; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ipi/tutorial/03/ostern.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | ostern.cpp -- Berechnung des Datum von Ostern nach Gauß Algirithmus 4 | */ 5 | 6 | #include "common.h" 7 | 8 | str easter(i32 year) { 9 | i32 a = year % 19; 10 | i32 b = year % 4; 11 | i32 c = year % 7; 12 | i32 k = year / 100; 13 | i32 p = (8 * k + 13) / 25; 14 | i32 q = k / 4; 15 | i32 m = (15 + k - p - q) % 30; 16 | i32 d = (19 * a + m) % 30; 17 | i32 n = (4 + k - q) % 7; 18 | i32 e = (2 * b + 4 * c + 6 * d + n) % 7; 19 | i32 x = 22 + d + e; 20 | i32 z = (x == 57) ? 50 : (((x == 56) && (d == 28) && (a > 10)) ? 49 : x); 21 | return std::to_string((z < 32) ? z : z - 31) + 22 | ((z < 32) ? ". März" : ". April"); 23 | } 24 | 25 | int main() { 26 | assert(easter(2000) == "23. April"); 27 | assert(easter(2001) == "15. April"); 28 | assert(easter(2002) == "31. März"); 29 | assert(easter(2003) == "20. April"); 30 | assert(easter(2004) == "11. April"); 31 | assert(easter(2005) == "27. März"); 32 | assert(easter(2006) == "16. April"); 33 | assert(easter(2007) == "8. April"); 34 | assert(easter(2008) == "23. März"); 35 | assert(easter(2009) == "12. April"); 36 | } 37 | -------------------------------------------------------------------------------- /ipi/tutorial/03/potenz.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | potenz.cpp -- Schneller Algorithmus zur für Integer Exponenten 4 | */ 5 | 6 | #include "common.h" 7 | 8 | constexpr inline auto sq(f64 x) noexcept -> f64 { return x * x; } 9 | 10 | /* 11 | Es wäre unsinnvoll nicht sq zu verwenden, wenn man nicht das 12 | Zwischenergebnis von power(x, i / 2) abspeichert, denn dann würde 13 | man einen bereits berechneten Wert nocheinmal ausrechen, und da dies 14 | auf allen Ebenen von power passieren würde man anstatt \mathcal{O}(n) 15 | Berechnungen \mathcal{O}(2^n) Berechnungen benötigen 16 | */ 17 | constexpr inline auto power(f64 x, i32 i) noexcept -> f64 { 18 | return (i == 1) ? x 19 | : (i % 2 == 0) ? sq(power(x, i / 2)) : x * power(x, i - 1); 20 | } 21 | 22 | int main() { 23 | std::cout << power(1.1, 8) << ", " << std::pow(1.1, 8) << std::endl; 24 | std::cout << power(2.1, 7) << ", " << std::pow(2.1, 7) << std::endl; 25 | std::cout << power(3.1, 6) << ", " << std::pow(3.1, 6) << std::endl; 26 | std::cout << power(4.1, 5) << ", " << std::pow(4.1, 5) << std::endl; 27 | std::cout << power(5.1, 4) << ", " << std::pow(5.1, 4) << std::endl; 28 | std::cout << power(6.1, 3) << ", " << std::pow(6.1, 3) << std::endl; 29 | std::cout << power(7.1, 2) << ", " << std::pow(7.1, 2) << std::endl; 30 | std::cout << power(8.1, 1) << ", " << std::pow(8.1, 1) << std::endl; 31 | } 32 | -------------------------------------------------------------------------------- /ipi/tutorial/03/sinus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | sinus.cpp -- Sinusberechung über Talyorentwicklung 4 | */ 5 | 6 | #include "common.h" 7 | 8 | constexpr f64 pi = 3.14159265358979323; 9 | 10 | namespace ipi { 11 | // Extrem schlechte implementation von tquot, aber für die Aufgabe 12 | // ausreichend 13 | const inline auto tquot(const f64 x) noexcept -> f64 { return (i32)x; } 14 | 15 | const inline auto fmod(const f64 a, const f64 b) -> f64 { 16 | return a - b * tquot(a / b); 17 | } 18 | 19 | const inline auto taylor_sin(const f64 x) noexcept -> f64 { 20 | return x - 0.16666666666666666666 * (x * x * x); 21 | } 22 | 23 | const inline auto degrees_to_rad(const f64 x) noexcept -> f64 { 24 | return (x / 180) * pi; 25 | } 26 | 27 | const inline auto pump_sin(const f64 s_) noexcept -> f64 { 28 | f64 s = ipi::fmod(pi + s_, 2.0 * pi) - pi; 29 | return 3 * s - 4 * s * s * s; 30 | } 31 | 32 | const inline auto my_sin(const f64 x) noexcept -> f64 { 33 | return (std::abs(x) <= degrees_to_rad(9)) ? taylor_sin(x) 34 | : pump_sin(my_sin(x / 3)); 35 | } 36 | } 37 | 38 | using namespace ipi; 39 | 40 | /* 41 | Tabelle zur Abweichung von taylor_sin 42 | | Winkel in Grad | std::sin(i) | taylor_sin(i) | Betrag der Abweichung | 43 | |----------------+-------------+---------------+-----------------------| 44 | | 5 | 0.0871557 | 0.0871557 | 4.21674e-08 | 45 | | 10 | 0.173648 | 0.173647 | 1.34862e-06 | 46 | | 20 | 0.34202 | 0.341977 | 4.30622e-05 | 47 | | 45 | 0.707107 | 0.704653 | 0.00245413 | 48 | | 90 | 1 | 0.924832 | 0.0751678 | 49 | | 135 | 0.707107 | 0.176066 | 0.531041 | 50 | | 180 | 1.22465e-16 | -2.02612 | 2.02612 | 51 | | 225 | -0.707107 | -6.1662 | 5.45909 | 52 | | 270 | -1 | -12.7286 | 11.7286 | 53 | | 315 | -0.707107 | -22.1979 | 21.4908 | 54 | 55 | Die Näherung hat einen Fehler von kleiner als 1e-6 bis zu x0 = 9°: 56 | 9°: |taylor_sin - std::sin| = 7.65e-7 (gerundet) 57 | 10°: |taylor_sin - std::sin| = 1.35e-6 > 1e-6 (gerundet) 58 | 59 | Tabelle zur Abweichung von my_sin 60 | | Winkel in Grad | std::sin(i) | taylor_sin(i) | Betrag der Abweichung | 61 | |----------------+-------------+---------------+-----------------------| 62 | | 5 | 0.0871557 | 0.0871557 | 4.21674e-08 | 63 | | 10 | 0.173648 | 0.173648 | 1.64351e-08 | 64 | | 20 | 0.34202 | 0.34202 | 5.0427e-07 | 65 | | 45 | 0.707107 | 0.707107 | 2.69377e-07 | 66 | | 90 | 1 | 1 | 1.13243e-14 | 67 | | 135 | 0.707107 | 0.707108 | 8.0813e-07 | 68 | | 180 | 1.22465e-16 | 4.82969e-06 | 4.82969e-06 | 69 | | 225 | -0.707107 | -0.707096 | 1.04603e-05 | 70 | | 270 | -1 | -1 | 1.02141e-13 | 71 | | 315 | -0.707107 | -0.707107 | 6.89059e-07 | 72 | 73 | Tabelle zur Abweichung vom verbesserten my_sin 74 | | Winkel in Grad | std::sin(i) | taylor_sin(i) | Betrag der Abweichung | 75 | |----------------+--------------+---------------+-----------------------| 76 | | 5 | 0.0871557 | 0.0871557 | 4.21674e-08 | 77 | | -5 | -0.0871557 | -0.0871557 | 4.21674e-08 | 78 | | 10 | 0.173648 | 0.173648 | 1.64351e-08 | 79 | | -10 | -0.173648 | -0.173648 | 1.64351e-08 | 80 | | 20 | 0.34202 | 0.34202 | 5.0427e-07 | 81 | | -20 | -0.34202 | -0.34202 | 5.0427e-07 | 82 | | 45 | 0.707107 | 0.707107 | 2.69377e-07 | 83 | | -45 | -0.707107 | -0.707107 | 2.69377e-07 | 84 | | 90 | 1 | 1 | 1.13243e-14 | 85 | | -90 | -1 | -1 | 1.13243e-14 | 86 | | 135 | 0.707107 | 0.707108 | 8.0813e-07 | 87 | | -135 | -0.707107 | -0.707108 | 8.0813e-07 | 88 | | 180 | 1.22465e-16 | 4.82969e-06 | 4.82969e-06 | 89 | | -180 | -1.22465e-16 | -4.82969e-06 | 4.82969e-06 | 90 | | 225 | -0.707107 | -0.707096 | 1.04603e-05 | 91 | | -225 | 0.707107 | 0.707096 | 1.04603e-05 | 92 | | 270 | -1 | -1 | 1.02141e-13 | 93 | | -270 | 1 | 1 | 1.02141e-13 | 94 | | 315 | -0.707107 | -0.707107 | 6.89059e-07 | 95 | | -315 | 0.707107 | 0.707107 | 6.89059e-07 | 96 | */ 97 | 98 | int main(){ 99 | /* 100 | for(auto j : {5, 10, 20, 45, 90, 135, 180, 225, 270, 315}) { 101 | auto i = degrees_to_rad(j); 102 | std::cout << "| " << j << " | " << std::sin(i) << " | " << my_sin(i) 103 | << " | " << std::abs(std::sin(i) - my_sin(i)) << " 104 | |" 105 | << std::endl; 106 | i = degrees_to_rad(-j); 107 | std::cout << "| " << -j << " | " << std::sin(i) << " | " << 108 | my_sin(i) 109 | << " | " << std::abs(std::sin(i) - my_sin(i)) << " 110 | |" 111 | << std::endl; 112 | } 113 | */ 114 | } * 115 | -------------------------------------------------------------------------------- /ipi/tutorial/03/weekday.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | weekday.cpp -- Wochentagberechnung 4 | */ 5 | 6 | #include "common.h" 7 | 8 | i32 sgn(i32 x) { return (0 < x) - (x < 0); } 9 | 10 | /* 11 | Der Unterschied trifft auf, wenn das Ergebnis der Division negativ 12 | ist und sich dadurch das Ergebnis von floorDiv und normaler Integer 13 | Division unterscheidet. Zum Beispiel: -3 / 2 = -1, -3 % 2 = -1, 14 | aber floorDiv(-3,2) = -2, floorMod(-3,2) muss dann 1 sein, damit a 15 | == floorDiv(a, b) * b + floorMod(a, b) 16 | */ 17 | i32 floorMod(i32 a, i32 b) { 18 | return ((sgn(a) + sgn(b)) || ((a % b) == 0)) != 0 ? a % b : a % b + b; 19 | } 20 | 21 | i32 floorDiv(i32 a, i32 b) { 22 | i32 c = (a % b) != 0 ? std::abs(b) : 0; 23 | return (sgn(a) + sgn(b)) != 0 ? a / b : -(std::abs(a) + c) / std::abs(b); 24 | } 25 | 26 | bool gap_year(i32 y) { 27 | return ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0); 28 | } 29 | 30 | i32 weekday_helper(i32 d, i32 m, i32 y, i32 z) { 31 | i32 j1 = (365 * z + (z / 4) - (z / 100) + (z / 400)) % 7; 32 | i32 p = 33 | (m == 1) ? d : ((m == 2) ? d + 31 34 | : (((m > 2) && !gap_year(y)) 35 | ? (d + 59 + ((153 * m - 457) / 5)) 36 | : (d + 60 + ((153 * m - 457) / 5)))); 37 | return (j1 + p - 1) % 7; 38 | } 39 | 40 | i32 weekday2001(i32 d, i32 m, i32 y) { 41 | i32 z = y - 2001; 42 | return weekday_helper(d, m, y, z); 43 | } 44 | 45 | /* 46 | Der Ablauf der Wochentage wiederholt sich, durch die Regeln zu 47 | Schaltjahren alle 400 Jahre, also kann jedes beliebige Vielefache 48 | von 400 + 1 gewählt werden, insbesondere 0 * 400 + 1 = 1 49 | */ 50 | i32 weekday1(i32 d, i32 m, i32 y) { 51 | i32 z = y - 1; 52 | return weekday_helper(d, m, y, z); 53 | } 54 | 55 | i32 weekday(i32 d, i32 m, i32 y) { 56 | i32 z = y - 2001; 57 | i32 j1 = floorMod( 58 | 365 * z + floorDiv(z, 4) - floorDiv(z, 100) + floorDiv(z, 400), 7); 59 | i32 p = (m == 1) 60 | ? d 61 | : ((m == 2) ? d + 31 62 | : (((m > 2) && !gap_year(y)) 63 | ? (d + 59 + floorDiv((153 * m - 457), 5)) 64 | : (d + 60 + floorDiv((153 * m - 457), 5)))); 65 | return (j1 + p - 1) % 7; 66 | } 67 | 68 | int main() { 69 | assert(weekday2001(1, 1, 2002) == 1); 70 | assert(weekday2001(7, 2, 2001) == 2); 71 | assert(weekday2001(12, 7, 2008) == 5); 72 | assert(weekday2001(28, 2, 2016) == 6); 73 | assert(weekday2001(10, 11, 2016) == 3); 74 | assert(weekday2001(10, 11, 2004) == 2); 75 | 76 | assert(weekday(1, 1, 2002) == 1); 77 | assert(weekday(7, 2, 2001) == 2); 78 | assert(weekday(12, 7, 2008) == 5); 79 | assert(weekday(28, 2, 2016) == 6); 80 | assert(weekday(10, 11, 2016) == 3); 81 | assert(weekday(10, 11, 2004) == 2); 82 | 83 | assert(weekday(28, 2, 2000) == 0); 84 | assert(weekday(29, 2, 2000) == 1); 85 | assert(weekday(1, 3, 2000) == 2); 86 | 87 | assert(weekday(27, 2, 1900) == 1); 88 | assert(weekday(28, 2, 1900) == 2); 89 | assert(weekday(1, 3, 1900) == 3); 90 | 91 | assert(weekday(28, 2, 1600) == 0); 92 | assert(weekday(29, 2, 1600) == 1); 93 | assert(weekday(1, 3, 1600) == 2); 94 | assert(weekday(3, 1, 1578) == 1); 95 | 96 | assert(weekday1(1, 1, 2002) == 1); 97 | assert(weekday1(7, 2, 2001) == 2); 98 | assert(weekday1(12, 7, 2008) == 5); 99 | assert(weekday1(28, 2, 2016) == 6); 100 | assert(weekday1(10, 11, 2016) == 3); 101 | assert(weekday1(10, 11, 2004) == 2); 102 | 103 | assert(weekday1(28, 2, 2000) == 0); 104 | assert(weekday1(29, 2, 2000) == 1); 105 | assert(weekday1(1, 3, 2000) == 2); 106 | 107 | assert(weekday1(27, 2, 1900) == 1); 108 | assert(weekday1(28, 2, 1900) == 2); 109 | assert(weekday1(1, 3, 1900) == 3); 110 | 111 | assert(weekday1(28, 2, 1600) == 0); 112 | assert(weekday1(29, 2, 1600) == 1); 113 | assert(weekday1(1, 3, 1600) == 2); 114 | assert(weekday1(3, 1, 1578) == 1); 115 | } 116 | -------------------------------------------------------------------------------- /ipi/tutorial/04/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using i32 = std::int32_t; 16 | using f64 = double; 17 | 18 | using str = std::string; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ipi/tutorial/04/email.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | email.cpp -- check if a string is a email 4 | */ 5 | 6 | #include "common.h" 7 | #include 8 | 9 | 10 | // Benutzung von regex ist mit Dr. Köthe abgesprochen 11 | bool is_email(str s) { 12 | std::regex email_regex("[\\w.-]+@[\\w.-]+\\.[\\w-]+"); 13 | return std::regex_match(s, email_regex); 14 | } 15 | 16 | i32 main() { 17 | assert(is_email("a@a.a")); 18 | assert(is_email("a.a@a.a.a")); 19 | assert(is_email("a.aa.a@a.a.a.a.de")); 20 | assert(is_email("aaaa@a.aaade")); 21 | assert(is_email("ab.ac_a-aa@a.aa.ade-")); 22 | assert(is_email("ab.ac_a-aa@a.aa.ade_")); 23 | 24 | assert(!is_email("a@a.a.")); 25 | assert(!is_email("a.aa.a.a")); 26 | assert(!is_email("a.aa.a@aaaade")); 27 | assert(!is_email("a@aaa@a.aaade")); 28 | assert(!is_email("ab.ac*a-aa@a.aa.ade-")); 29 | assert(!is_email("ab.ac_a-aa@a.aa.ade_.")); 30 | } 31 | -------------------------------------------------------------------------------- /ipi/tutorial/04/kubikwurzel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | kubikwurzel.cpp -- calculation of cubic root 4 | */ 5 | 6 | #include "common.h" 7 | 8 | f64 cbrt(f64 y) { 9 | if(y == 0.0) return 0.0; 10 | 11 | f64 x = y; // inital guess 12 | f64 x2; 13 | f64 epsilon = 1e-15 * y; 14 | 15 | while(std::abs(x * x * x - y) > std::abs(epsilon)) { 16 | x2 = x * x; 17 | x = (2 * x2 * x + y) / (3 * x2); 18 | } 19 | 20 | return x; 21 | } 22 | 23 | i32 main() { 24 | for(const auto & x : {1, 8, 1000, 12983}) { 25 | // kleiner Fehler erlaubt 26 | assert(std::abs(cbrt(x) - pow(x, 1.0 / 3.0)) < 1e-15 * x); 27 | assert(cbrt(-x) == -cbrt(x)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ipi/tutorial/04/kubikwurzel.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Übungszettel 4 3 | #+OPTIONS: toc:nil 4 | #+OPTIONS: H:6 5 | #+LATEX_CLASS: koma-article 6 | #+LATEX_CLASS_OPTIONS: [a4paper] 7 | #+LATEX_HEADER: \usepackage{siunitx}% 8 | #+LATEX_HEADER: \usepackage{fontspec}% 9 | #+LATEX_HEADER: \sisetup{load-configurations = abbrevations}% 10 | #+LATEX_HEADER: \newcommand{\estimates}{\overset{\scriptscriptstyle\wedge}{=}}% 11 | #+LATEX_HEADER: \usepackage{mathtools}% 12 | #+LATEX_HEADER: \DeclarePairedDelimiter\abs{\lvert}{\rvert}% 13 | #+LATEX_HEADER: \DeclarePairedDelimiter\norm{\lVert}{\rVert}% 14 | #+LATEX_HEADER: \DeclareMathOperator{\Exists}{\exists}% 15 | #+LATEX_HEADER: \DeclareMathOperator{\Forall}{\forall}% 16 | #+LATEX_HEADER: \def\colvec#1{\left(\vcenter{\halign{\hfil$##$\hfil\cr \colvecA#1;;}}\right)} 17 | #+LATEX_HEADER: \def\colvecA#1;{\if;#1;\else #1\cr \expandafter \colvecA \fi} 18 | #+LATEX_HEADER: \usepackage{minted} 19 | #+LATEX_HEADER: \usepackage{makecell} 20 | # #+LATEX_HEADER: \usemintedstyle{tango} 21 | #+LATEX_HEADER: \usemintedstyle{perldoc} 22 | #+LATEX_HEADER: \usepackage{tikz} 23 | #+LATEX_HEADER: \usetikzlibrary{arrows,automata} 24 | #+LATEX_HEADER: \usepackage{tikz-qtree} 25 | #+LATEX_HEADER: \usepackage{enumitem} 26 | #+LATEX_HEADER: \setlistdepth{20} 27 | #+LATEX_HEADER: \renewlist{itemize}{itemize}{20} 28 | #+LATEX_HEADER: \setlist[itemize]{label=$\cdot$} 29 | 30 | \section*{Aufgabe 4.1} 31 | Herleitung des Newtonverfahren für Kubikwurzeln 32 | \begin{align*} 33 | \intertext{Es ist gegeben} 34 | x^{(t + 1)} = x^{(t)} - \frac{f(x^{(t)})}{f'(x^{(t)})} \\ 35 | \intertext{im Fall der Kubikwurzeln gilt:} 36 | f(x) = x^3 - y \\ 37 | f(x^\ast) = 0 \\ 38 | x^\ast = \sqrt[3]{y} \\ 39 | \intertext{Damit erhält man für $x^{(t + 1)}$:} 40 | x^{(t + 1)} = x^{(t)} - \frac{x^{(t)^3} - y}{3x^{(t)^2}} = \frac{2x^{(t)^3} + y}{3x^{(t)^2}} 41 | \intertext{Als Abbruchbedingung könnte man wählen:} 42 | \abs{x^{(t)^3} - y} \leq \varepsilon 43 | \intertext{Für ein kleines $\varepsilon$ zum Beispiel ist $\varepsilon = 10^{-15} y$ für double sinnvoll, denn diese sind nur auf genau 16 Nachkommastellen genau, also könnte eine höhere Genauigkeit mit trivialen Methoden gar nicht erreicht werden} 44 | \end{align*} 45 | 46 | \section*{Aufgabe 4.2b} 47 | Herleitung von $n$ ist Quadratzahl $\implies (n \mod 4) \in \{0, 1\}$ 48 | $n$ Quadratzahl $\implies \Exists a\in \mathbb{N}: a^2 = n$ 49 | \[n \mod 4 = (a\cdot a) \mod 4 = ((a \mod 4)(a\mod 4)) \mod 4\] 50 | Für $a \mod 4$ gibt es 4 verschiedene Fälle: 51 | 1. $a\mod 4 = 0 \implies (\underbrace{(a\mod 4)(a\mod 4)}_{= 0}) \mod 4 = 0$ 52 | 2. $a\mod 4 = 1 \implies (\underbrace{(a\mod 4)(a\mod 4)}_{= 1}) \mod 4 = 1$ 53 | 3. $a\mod 4 = 2 \implies (\underbrace{(a\mod 4)(a\mod 4)}_{= 4}) \mod 4 = 0$ 54 | 4. $a\mod 4 = 3 \implies (\underbrace{(a\mod 4)(a\mod 4)}_{= 9}) \mod 4 = 1$ 55 | $\implies n$ Quadratzahl $\implies (n\mod 4) \in \{0, 1\}$ 56 | -------------------------------------------------------------------------------- /ipi/tutorial/04/palindrom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | palindrom.cpp -- test if a string is a palindrome 4 | */ 5 | 6 | #include "common.h" 7 | 8 | str to_lower(str s) { 9 | str ret; 10 | 11 | for(const auto & c : s) ret += std::tolower(c); 12 | 13 | return ret; 14 | } 15 | 16 | str letters_only(str s) { 17 | str ret; 18 | 19 | for(const auto & c : s) { 20 | if(std::isalpha(c)) ret += c; 21 | } 22 | 23 | return ret; 24 | } 25 | 26 | bool is_palindrom(str s) { 27 | s = letters_only(to_lower(s)); 28 | 29 | i32 j = s.size() - 1; 30 | for(i32 i = 0; i < j; i++) { 31 | if(s[i] != s[j]) return false; 32 | 33 | j--; 34 | } 35 | 36 | return true; 37 | } 38 | 39 | int main() { 40 | assert(is_palindrom("Otto")); 41 | assert(is_palindrom("Anna")); 42 | assert(is_palindrom("Rentner")); 43 | assert(is_palindrom("Lagerregal")); 44 | assert(is_palindrom("Ein Neger mit Gazelle zagt im Regen nie")); 45 | assert(!is_palindrom("Ein Neger mit Gazelle zagt im Regen immer")); 46 | assert(!is_palindrom("Neger mit Gazelle zagt im Regen immer")); 47 | 48 | str s; 49 | 50 | while(1) { 51 | std::cout << "to check: " << std::endl; 52 | std::getline(std::cin, s); 53 | std::cout << (is_palindrom(s) ? "ist ein Palindrom" 54 | : "ist kein Palindrom") 55 | << std::endl; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ipi/tutorial/04/pythagoras.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | pythagoras.cpp -- algorithm to find pythagorean triples 4 | */ 5 | 6 | #include "common.h" 7 | 8 | bool is_square_slow(i32 n) { 9 | auto x = std::sqrt(n); 10 | return x == std::floor(x); 11 | } 12 | 13 | bool is_square(i32 n) { 14 | auto x = n % 4; 15 | 16 | if(x == 1 || x == 0) return is_square_slow(n); 17 | 18 | return false; 19 | } 20 | 21 | void pythagorean_triple(i32 max) { 22 | for(i32 b = 1; b < max; b++) { 23 | for(i32 a = 1; a < b; a++) { 24 | if(is_square(a * a + b * b)) { 25 | std::cout << a << ", " << b << std::endl; 26 | } 27 | } 28 | } 29 | } 30 | 31 | i32 main() { pythagorean_triple(400); } 32 | -------------------------------------------------------------------------------- /ipi/tutorial/05/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using i32 = std::int32_t; 22 | using u32 = std::uint32_t; 23 | using f64 = double; 24 | 25 | using str = std::string; 26 | 27 | template 28 | using vec = std::vector; 29 | 30 | template 31 | std::ostream & operator<<(std::ostream & out, const std::vector & v) { 32 | if(!v.empty()) { 33 | out << '['; 34 | std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); 35 | out << "\b\b]"; 36 | } 37 | return out; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /ipi/tutorial/05/mix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | mix.cpp -- mixing up the letters in words 4 | Uses c++14 5 | */ 6 | 7 | #include "common.h" 8 | #include "text.hpp" 9 | 10 | vec const inline split_words(str s) noexcept { 11 | std::istringstream iss(s); 12 | return {std::istream_iterator{iss}, std::istream_iterator{}}; 13 | } 14 | 15 | auto mix(str s) noexcept { 16 | auto begin = std::find_if(s.begin(), s.end(), 17 | [](char s) { return std::isalpha(s); }) + 18 | 1; 19 | 20 | auto end = std::find_if(std::reverse_iterator(s.end()), 21 | std::reverse_iterator(s.begin()), 22 | [](char s) { return std::isalpha(s); }) 23 | .base() - 24 | 1; 25 | 26 | std::random_shuffle(begin, end); 27 | 28 | return s; 29 | } 30 | 31 | auto concat(vec strs, const char * delim = " ") { 32 | switch(strs.size()) { 33 | case 0: 34 | return str(""); 35 | case 1: 36 | return strs[0]; 37 | default: 38 | std::ostringstream os; 39 | std::copy(strs.begin(), strs.end() - 1, 40 | std::ostream_iterator(os, delim)); 41 | os << *strs.rbegin(); 42 | return os.str(); 43 | } 44 | } 45 | 46 | auto split_and_mix(str s) noexcept { 47 | auto words = split_words(s); 48 | 49 | std::transform(words.begin(), words.end(), words.begin(), mix); 50 | 51 | return concat(words); 52 | } 53 | 54 | int main() { 55 | for(const auto & str : {str1, str2, str3, str4, str5}) { 56 | std::cout << str << std::endl; 57 | std::cout << split_and_mix(str) << std::endl; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ipi/tutorial/05/ordered_insert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | ordered_insert.cpp -- Insert ints read from cmdline ordered into a vector 4 | Uses c++14 5 | */ 6 | 7 | #include "common.h" 8 | 9 | template 10 | auto const inline ordered_insert(vec & v, const T & n) noexcept { 11 | v.insert(std::find_if(v.begin(), v.end(), 12 | [=](const T & other) { return other > n; }), 13 | n); 14 | } 15 | 16 | i32 main() { 17 | i32 user_input; 18 | vec numbers; 19 | 20 | while(true) { 21 | user_input = -1; 22 | std::cin >> user_input; 23 | 24 | // check for valid number 25 | if(!std::cin) { 26 | std::cin.clear(); 27 | std::cin.ignore(std::numeric_limits::max(), 28 | '\n'); // skip bad input 29 | continue; 30 | } 31 | 32 | if(user_input < 0) { 33 | break; 34 | } else { 35 | ordered_insert(numbers, user_input); 36 | } 37 | 38 | std::cout << numbers << std::endl; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ipi/tutorial/05/perfect_shuffle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | perfect_shuffle.cpp -- Implementation of perfect suffle 4 | Uses c++14 5 | */ 6 | 7 | #include "common.h" 8 | 9 | auto const inline init_deck() noexcept { 10 | vec cards(52); 11 | std::iota(cards.begin(), cards.end(), 0); 12 | 13 | return cards; 14 | } 15 | 16 | auto const inline check_deck(vec cards) noexcept { 17 | auto correct_deck = init_deck(); 18 | 19 | return correct_deck == cards; 20 | } 21 | 22 | auto const inline shuffle(vec cards, bool out) noexcept { 23 | vec halves[2]; 24 | vec shuffeled; 25 | 26 | halves[0].reserve(26); 27 | halves[1].reserve(26); 28 | shuffeled.reserve(52); 29 | 30 | std::copy(cards.begin(), cards.begin() + 26, halves[1].begin()); 31 | std::copy(cards.begin() + 26, cards.end(), halves[0].begin()); 32 | 33 | out %= 2; 34 | 35 | for(i32 i = 0; i < 52; i++) { 36 | shuffeled.push_back(halves[(i + out) % 2][i / 2]); 37 | } 38 | 39 | return shuffeled; 40 | } 41 | 42 | i32 main() { 43 | auto cards = init_deck(); 44 | assert(check_deck(cards)); 45 | 46 | i32 iterations = 0; 47 | 48 | do { 49 | cards = shuffle(cards, false); 50 | iterations++; 51 | } while(!check_deck(cards)); 52 | 53 | std::cout << "Perfect-In-Shuffle: " << iterations << " iterations" 54 | << std::endl; 55 | 56 | iterations = 0; 57 | 58 | do { 59 | cards = shuffle(cards, true); 60 | iterations++; 61 | } while(!check_deck(cards)); 62 | 63 | std::cout << "Perfect-Out-Shuffle: " << iterations << " iterations" 64 | << std::endl; 65 | } 66 | -------------------------------------------------------------------------------- /ipi/tutorial/05/text.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_HPP 2 | #define TEXT_HPP 3 | 4 | #include 5 | 6 | std::string str1 = "Nach einer Studie einer englischen Universitaet ist es egal, in welcher Reihenfolge die Buchstaben in einem Wort stehen. Das einzig Wichtige dabei ist, dass der erste und letzte Buchstabe am richtigen Platz sind. Der Rest kann totaler Bloedsinn sein, und man kann es trotzdem ohne Probleme lesen. Das geht deshalb, weil wir nicht Buchstabe fuer Buchstabe lesen, sondern Woerter als Ganzes."; 7 | std::string str2 = "Blaukraut bleibt Blaukraut und Brautkleid bleibt Brautkleid."; 8 | std::string str3 = "Am Anfang wurde das Universum erschaffen. Das machte viele Leute sehr wuetend und wurde allenthalben als Schritt in die falsche Richtung angesehen."; 9 | std::string str4 = "Habe nun, ach! Philosophie, Juristerei und Medizin, Und leider auch Theologie Durchaus studiert, mit heissem Bemuehn. Da steh ich nun, ich armer Tor! Und bin so klug als wie zuvor."; 10 | std::string str5 = "Im Atomstreit mit Iran zeichnen sich weitere UN-Sanktionen gegen das Land ab. Da eine klare Antwort aus Teheran auf ein Anreizpaket ausgeblieben sei, gebe es zu neuen Strafmassnahmen keine Alternative, teilte das US-Aussenministerium mit. Wie ein Ministeriumssprecher erklaerte, wollen die politischen Direktoren aus den Aussenministerien der fuenf UN-Vetomaechte und Deutschlands am Mittwoch in einer Telefonkonferenz ueber moegliche Reaktionen beraten."; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /ipi/tutorial/06/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using i32 = std::int32_t; 25 | using i64 = std::int64_t; 26 | using u32 = std::uint32_t; 27 | using f64 = double; 28 | 29 | using str = std::string; 30 | using namespace std; 31 | using namespace std::placeholders; 32 | 33 | template 34 | using vec = std::vector; 35 | 36 | template 37 | std::ostream & operator<<(std::ostream & out, const std::vector & v) { 38 | if(!v.empty()) { 39 | out << '['; 40 | std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); 41 | out << "\b\b]"; 42 | } 43 | return out; 44 | } 45 | 46 | template 47 | auto to_vec(T (&data)[size]) { 48 | vec vector; 49 | vector.assign(data, data + size); 50 | return vector; 51 | } 52 | 53 | template 54 | std::ostream & operator<<(std::ostream & out, const std::map & m) { 55 | T key; 56 | G value; 57 | 58 | out << '['; 59 | for(const auto & key_value : m) { 60 | tie(key, value) = key_value; 61 | 62 | out << "{" << key << " : " << value << "}, "; 63 | } 64 | 65 | if(!m.empty()) { out << "\b\b"; } 66 | out << ']'; 67 | 68 | return out; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /ipi/tutorial/06/decrypt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | decrypt.cpp -- decrypt text using character probabilities 4 | requires c++14 5 | */ 6 | 7 | #include "common.h" 8 | 9 | auto read_whole_file(str filename) { 10 | ifstream file(filename); 11 | str contents; 12 | 13 | // reserve enough space in the buffer string 14 | file.seekg(0, ios::end); 15 | contents.reserve(file.tellg()); 16 | file.seekg(0, ios::beg); 17 | 18 | // read the whole file to memory 19 | contents.assign(istreambuf_iterator(file), 20 | istreambuf_iterator()); 21 | 22 | file.close(); 23 | 24 | return contents; 25 | } 26 | 27 | template 28 | const pair flip_pair(const pair & p) noexcept { 29 | return pair(p.second, p.first); 30 | } 31 | 32 | template 33 | const map flip_map(const map & src) noexcept { 34 | map dst; 35 | transform(src.begin(), src.end(), inserter(dst, dst.begin()), 36 | flip_pair); 37 | return dst; 38 | } 39 | 40 | i32 main() { 41 | auto text = read_whole_file("encrypted_text.txt"); 42 | 43 | // std::map c; 44 | 45 | // for (auto iter = text.begin(); iter != text.end(); ++iter) { 46 | // if(std::isalpha(*iter)) { 47 | // *iter = std::tolower(*iter); 48 | // c[*iter] += 1; 49 | // } 50 | // } 51 | 52 | // cout << c << endl; 53 | 54 | vec cnts(128); 55 | for_each(text.begin(), text.end(), [&](char c) { 56 | if(isalpha(c)) cnts[(unsigned char)tolower(c)]++; 57 | }); 58 | 59 | map counts; 60 | for(u32 i = 0; i < cnts.size(); i++) { 61 | if(cnts[i] > 0) { counts[i] = cnts[i]; } 62 | } 63 | 64 | // cout << counts << endl; 65 | 66 | auto sorted = flip_map(counts); 67 | 68 | vec letters = { 69 | 'z', 'j', 'q', 'x', 'k', 'v', 'b', 'y', 'g', 'p', 'w', 'f', 'm', 70 | 'c', 'u', 'l', 'd', 'r', 'h', 's', 'n', 'i', 'o', 'a', 't', 'e', 71 | }; 72 | 73 | map decrypt; 74 | 75 | i32 key, counter = 0; 76 | char value; 77 | for(const auto & key_value : sorted) { 78 | tie(key, value) = key_value; 79 | 80 | decrypt[value] = letters[counter]; 81 | decrypt[toupper(value)] = toupper(letters[counter]); 82 | 83 | counter++; 84 | } 85 | 86 | transform(text.begin(), text.end(), text.begin(), [&](char c) { 87 | if(isalpha(c)) { 88 | return decrypt[c]; 89 | } else { 90 | return c; 91 | } 92 | }); 93 | 94 | ofstream out("decrypted_text.txt"); 95 | out << text; 96 | out.close(); 97 | } 98 | -------------------------------------------------------------------------------- /ipi/tutorial/06/format_numbers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | format_numbers.cpp -- formatting of tables and doubles 4 | requires c++14 5 | */ 6 | 7 | #include "format_numbers.hpp" 8 | #include "common.h" 9 | 10 | namespace ipi { 11 | const inline auto round(f64 d, i32 digits) noexcept { 12 | auto offset = pow(10, digits); 13 | d *= offset; 14 | d = (f64)((i64)(d + 0.5)); 15 | return d / offset; 16 | } 17 | 18 | const inline auto vec_to_int(const vec v) noexcept { 19 | vec ret(v.size()); 20 | 21 | ret.resize(v.size()); 22 | transform(v.begin(), v.end(), ret.begin(), 23 | [](f64 d) { return (i32)round(d, 0); }); 24 | return ret; 25 | } 26 | 27 | const inline auto vec_rounded(vec v) noexcept { 28 | transform(v.begin(), v.end(), v.begin(), bind(round, _1, 2)); 29 | return v; 30 | } 31 | 32 | const inline auto double_to_string(f64 x) noexcept { 33 | x = round(x, 2); 34 | auto tmp = to_string(x); 35 | auto dot = tmp.rfind('.'); 36 | str lhs = tmp.substr(0, dot); 37 | str rhs = tmp.substr(dot, tmp.size() - dot); 38 | rhs.resize(16); 39 | 40 | while(rhs.size() < 3) rhs += "0"; 41 | rhs = rhs.substr(0, 3); 42 | 43 | for(u32 i = 3; i < lhs.size(); i += 4) { 44 | if(isdigit(lhs[lhs.size() - i - 1])) { 45 | lhs.insert(lhs.end() - i, '\''); 46 | } 47 | } 48 | 49 | return str(16 - lhs.size() - rhs.size(), ' ') + lhs + rhs; 50 | } 51 | 52 | const inline auto format_numbers(vec v) noexcept { 53 | vec formatted_numbers; 54 | formatted_numbers.resize(v.size()); 55 | transform(v.begin(), v.end(), formatted_numbers.begin(), 56 | double_to_string); 57 | return formatted_numbers; 58 | } 59 | } 60 | 61 | using namespace ipi; 62 | 63 | i32 main() { 64 | const auto nums = format_numbers(numbers); 65 | copy(nums.begin(), nums.end(), ostream_iterator(cout, "\n")); 66 | } 67 | -------------------------------------------------------------------------------- /ipi/tutorial/06/format_numbers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FORMAT_NUMBERS_HPP 2 | #define FORMAT_NUMBERS_HPP 3 | 4 | #include 5 | 6 | std::vector numbers = { 7 | 1234567.678, 8 | -3.0, 9 | -98765.4321, 10 | -300.4567, 11 | 19.5, 12 | 2.218, 13 | -7.324, 14 | 7246.0, 15 | 199.999, 16 | 0.00001, 17 | -0.0002 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ipi/tutorial/06/sort_versions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | sort_versions.cpp -- sort version numbers 4 | requires c++14 5 | */ 6 | 7 | #include "common.h" 8 | #include "sort_versions.hpp" 9 | 10 | const auto inline split(str s, char delim) noexcept { 11 | stringstream ss; 12 | vector elems; 13 | str item; 14 | ss.str(s); 15 | 16 | while(getline(ss, item, delim)) { elems.push_back(item); } 17 | 18 | return elems; 19 | } 20 | 21 | const auto inline split_version(str version) noexcept { 22 | auto split_version = split(version, '.'); 23 | vec versions(split_version.size()); 24 | 25 | transform(split_version.begin(), split_version.end(), versions.begin(), 26 | [](const str & s) { return stoi(s); }); 27 | 28 | return versions; 29 | } 30 | 31 | const auto inline version_less(str v1, str v2) noexcept { 32 | auto s1 = split_version(v1); 33 | auto s2 = split_version(v2); 34 | 35 | return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end()); 36 | } 37 | 38 | i32 main() { 39 | sort(versions.begin(), versions.end(), version_less); 40 | copy(versions.begin(), versions.end(), ostream_iterator(cout, "\n")); 41 | } 42 | -------------------------------------------------------------------------------- /ipi/tutorial/06/sort_versions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SORT_VERSIONS_HPP 2 | #define SORT_VERSIONS_HPP 3 | 4 | std::vector versions = { 5 | "4.2.95", "3.1.1.6", "4.0", "1.2", "4.7.95", "1996.07.12", "1.0.4", 6 | "0.9.6", "1.1.16", "0.4", "2", "1.1", "2.2.0.1", "1.0.5", 7 | "2.3.0", "0.5", "1.1", "1.0", "0.4.1", "4.7.1", "2.3.4", 8 | "14.3.1", "0.960923", "4.7", "1.1.1"}; 9 | 10 | #endif // SORT_VERSIONS_HPP 11 | -------------------------------------------------------------------------------- /ipi/tutorial/07/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using i32 = std::int32_t; 26 | using i64 = std::int64_t; 27 | using u32 = std::uint32_t; 28 | using f64 = double; 29 | 30 | using str = std::string; 31 | using namespace std; 32 | using namespace std::placeholders; 33 | 34 | template 35 | using vec = std::vector; 36 | 37 | template 38 | std::ostream & operator<<(std::ostream & out, const std::vector & v) { 39 | if(!v.empty()) { 40 | out << '['; 41 | std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); 42 | out << "\b\b]"; 43 | } 44 | return out; 45 | } 46 | 47 | template 48 | auto to_vec(T (&data)[size]) { 49 | vec vector; 50 | vector.assign(data, data + size); 51 | return vector; 52 | } 53 | 54 | template 55 | std::ostream & operator<<(std::ostream & out, const std::map & m) { 56 | T key; 57 | G value; 58 | 59 | out << '['; 60 | for(const auto & key_value : m) { 61 | tie(key, value) = key_value; 62 | 63 | out << "{" << key << " : " << value << "}, "; 64 | } 65 | 66 | if(!m.empty()) { out << "\b\b"; } 67 | out << ']'; 68 | 69 | return out; 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /ipi/tutorial/08/UB8.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Übungszettel 8 3 | #+OPTIONS: toc:nil 4 | #+OPTIONS: H:6 5 | #+LATEX_CLASS: koma-article 6 | #+LATEX_CLASS_OPTIONS: [a4paper] 7 | #+LATEX_HEADER: \usepackage{siunitx}% 8 | #+LATEX_HEADER: \usepackage{fontspec}% 9 | #+LATEX_HEADER: \sisetup{load-configurations = abbrevations}% 10 | #+LATEX_HEADER: \newcommand{\estimates}{\overset{\scriptscriptstyle\wedge}{=}}% 11 | #+LATEX_HEADER: \usepackage{mathtools}% 12 | #+LATEX_HEADER: \DeclarePairedDelimiter\abs{\lvert}{\rvert}% 13 | #+LATEX_HEADER: \DeclarePairedDelimiter\norm{\lVert}{\rVert}% 14 | #+LATEX_HEADER: \DeclareMathOperator{\Exists}{\exists}% 15 | #+LATEX_HEADER: \DeclareMathOperator{\Forall}{\forall}% 16 | #+LATEX_HEADER: \def\colvec#1{\left(\vcenter{\halign{\hfil$##$\hfil\cr \colvecA#1;;}}\right)} 17 | #+LATEX_HEADER: \def\colvecA#1;{\if;#1;\else #1\cr \expandafter \colvecA \fi} 18 | #+LATEX_HEADER: \usepackage{minted} 19 | #+LATEX_HEADER: \usepackage{makecell} 20 | # #+LATEX_HEADER: \usemintedstyle{tango} 21 | #+LATEX_HEADER: \usemintedstyle{perldoc} 22 | #+LATEX_HEADER: \usepackage{tikz} 23 | #+LATEX_HEADER: \usetikzlibrary{arrows,automata} 24 | #+LATEX_HEADER: \usepackage{tikz-qtree} 25 | #+LATEX_HEADER: \usepackage{enumitem} 26 | #+LATEX_HEADER: \setlistdepth{20} 27 | #+LATEX_HEADER: \renewlist{itemize}{itemize}{20} 28 | #+LATEX_HEADER: \setlist[itemize]{label=$\cdot$} 29 | 30 | \section*{Aufgabe 8.1} 31 | \subsection*{(a)} 32 | Bis zu einer gewissen Anzahl von Iterationen wird die Approximation von von $\pi$ immer besser. 33 | Danach wird sie allerdings wieder schlechter, denn $s$ und $t$ werden (zwangsweise) immer kleiner. 34 | \subsection*{(b)} 35 | Auch mit double tritt dieses Problem auch auf, allerdings erst bei ungefähr der doppelten Anzahl von 36 | Iterationen. 37 | \subsection*{(c)} 38 | y 39 | \section*{Aufgabe 8.3} 40 | 41 | \section*{Aufgabe 8.4} 42 | -------------------------------------------------------------------------------- /ipi/tutorial/08/archimedes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | archimedes.cpp -- archimedian pi calculation 4 | */ 5 | 6 | #include "common.h" 7 | 8 | template 9 | void archimedes_pi(i32 doubles) noexcept { 10 | Float s = sqrt(2); 11 | Float t = 2; 12 | i32 n = 4; 13 | 14 | for(i32 i = 0; i < doubles; i++) { 15 | n *= 2; 16 | s = sqrt(Float(2) - sqrt(Float(4) - s * s)); 17 | t = (Float(2) / t) * (sqrt(Float(4) + t * t) - Float(2)); 18 | cout << setprecision(16) << s * n / 2 << " <= " << M_PI 19 | << " <= " << t * n / 2 20 | << ", Abweichung s: " << Float(1) - (M_PI / (s * (n / 2))) 21 | << ", Abweichung t: " << Float(1) - (M_PI / (t * (n / 2))) << endl; 22 | 23 | } 24 | } 25 | 26 | template 27 | void archimedes_piv2(i32 doubles) noexcept { 28 | Float s = sqrt(2); 29 | Float t = 2; 30 | i32 n = 4; 31 | 32 | for(i32 i = 0; i < doubles; i++) { 33 | n *= 2; 34 | s = sqrt(Float(2) - sqrt(Float(4) - s * s)); 35 | t = (Float(2) / t) * (sqrt(Float(4) + t * t) - Float(2)); 36 | cout << setprecision(16) << s * n / 2 << " <= " << M_PI 37 | << " <= " << t * n / 2 38 | << ", Abweichung s: " << Float(1) - (M_PI / (s * (n / 2))) 39 | << ", Abweichung t: " << Float(1) - (M_PI / (t * (n / 2))) << endl; 40 | 41 | } 42 | } 43 | 44 | i32 main() { 45 | archimedes_pi(13); 46 | archimedes_pi(28); 47 | } 48 | -------------------------------------------------------------------------------- /ipi/tutorial/08/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | common.h -- Common defines and includes 4 | */ 5 | 6 | #ifndef _COMMON_H 7 | #define _COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using i32 = std::int32_t; 27 | using i64 = std::int64_t; 28 | using u32 = std::uint32_t; 29 | using f64 = double; 30 | 31 | using str = std::string; 32 | using namespace std; 33 | using namespace std::placeholders; 34 | 35 | template 36 | using vec = std::vector; 37 | 38 | template 39 | std::ostream & operator<<(std::ostream & out, const std::vector & v) { 40 | if(!v.empty()) { 41 | out << '['; 42 | std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); 43 | out << "\b\b]"; 44 | } 45 | return out; 46 | } 47 | 48 | template 49 | auto to_vec(T (&data)[size]) { 50 | vec vector; 51 | vector.assign(data, data + size); 52 | return vector; 53 | } 54 | 55 | inline int log2(int x) noexcept { return __builtin_ctz(x); } 56 | 57 | template 58 | std::ostream & operator<<(std::ostream & out, const std::map & m) { 59 | T key; 60 | G value; 61 | 62 | out << '['; 63 | for(const auto & key_value : m) { 64 | tie(key, value) = key_value; 65 | 66 | out << "{" << key << " : " << value << "}, "; 67 | } 68 | 69 | if(!m.empty()) { out << "\b\b"; } 70 | out << ']'; 71 | 72 | return out; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /ipi/tutorial/08/perfect_shuffle_to_k.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by Robin Heinemann. All Rights Reserved. 3 | perfect_shuffle_to_k.cpp -- perfect shuffle to position k 4 | */ 5 | 6 | #include "common.h" 7 | 8 | auto const inline init_deck() noexcept { 9 | vec cards(52); 10 | std::iota(cards.begin(), cards.end(), 0); 11 | 12 | return cards; 13 | } 14 | 15 | auto const inline check_deck(vec cards) noexcept { 16 | auto correct_deck = init_deck(); 17 | 18 | return correct_deck == cards; 19 | } 20 | 21 | auto const inline shuffle(vec cards, bool out) noexcept { 22 | vec halves[2]; 23 | vec shuffeled; 24 | 25 | halves[0].reserve(26); 26 | halves[1].reserve(26); 27 | shuffeled.reserve(52); 28 | 29 | std::copy(cards.begin(), cards.begin() + 26, halves[1].begin()); 30 | std::copy(cards.begin() + 26, cards.end(), halves[0].begin()); 31 | 32 | if(out) 33 | out = 1; 34 | else 35 | out = 0; 36 | 37 | for(i32 i = 0; i < 52; i++) { 38 | shuffeled.push_back(halves[(i + out) % 2][i / 2]); 39 | } 40 | 41 | return shuffeled; 42 | } 43 | 44 | auto shuffle_top_to(vec deck, uint8_t k) noexcept { 45 | if(k != 0) { 46 | for(i32 i = log2(k); i >= 0; i--) { 47 | deck = shuffle(deck, ~(k >> i) & 1); 48 | } 49 | } 50 | return deck; 51 | } 52 | 53 | i32 main() { 54 | for(i32 i = 0; i < 52; i++) { 55 | auto cards = init_deck(); 56 | cards = shuffle_top_to(cards, i); 57 | assert(cards[i] == 0); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ipi/tutorial/09/draw.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | import fileinput 3 | import re 4 | import hashlib 5 | import random 6 | from PIL import Image, ImageFont, ImageDraw 7 | 8 | def random_color(s): 9 | return "#%06x" % (int(hashlib.sha1(s.encode()).hexdigest(), 16) % (0xffffff)) 10 | 11 | input = fileinput.input().readline() 12 | input = input.strip()[1:-1] 13 | input = re.findall(r'\s*(\d+\:\d+,\s\d+\:\d+)\s*', input) 14 | 15 | im = Image.new('RGB', (100,80), (0,0,0)) 16 | dr = ImageDraw.Draw(im) 17 | 18 | for rect in input: 19 | color = random_color(rect) 20 | 21 | print(rect) 22 | dr.rectangle(((int(rect.split(',')[0].split(':')[0]),int(rect.split(',')[1].split(':')[0])), 23 | (int(rect.split(',')[0].split(':')[1]),int(rect.split(',')[1].split(':')[1]))), 24 | fill="#00000000", outline = color) 25 | 26 | im.save("rectangle.png") 27 | -------------------------------------------------------------------------------- /ipi/tutorial/09/gifts.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | gifts.cpp -- optimal gift placing 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // clang-format off 12 | #include "rec.cpp" 13 | #include "gifts.txt" 14 | // clang-format on 15 | 16 | using namespace std; 17 | template 18 | using vec = vector; 19 | using str = string; 20 | constexpr auto infty = std::numeric_limits::infinity(); 21 | 22 | template 23 | std::ostream & operator<<(std::ostream & out, const std::vector & v) { 24 | if(!v.empty()) { 25 | out << '['; 26 | std::copy(v.begin(), v.end(), std::ostream_iterator(out, ", ")); 27 | out << "\b\b]"; 28 | } 29 | return out; 30 | } 31 | 32 | std::ostream & operator<<(std::ostream & out, const Rectangle & r) { 33 | return out << to_string(r); 34 | } 35 | 36 | template 37 | auto to_vec(T (&data)[size]) { 38 | vec vector; 39 | vector.assign(data, data + size); 40 | return vector; 41 | } 42 | double bssf_score(Rectangle const & free, Rectangle const & obj) { 43 | auto dw = free.width() - obj.width(); 44 | auto dh = free.height() - obj.height(); 45 | auto m = std::min(dw, dh); 46 | 47 | return m > 0 ? m : infty; 48 | } 49 | 50 | struct placeable { 51 | const Rectangle & free; 52 | const Rectangle & to_place; 53 | double score; 54 | bool transposed; 55 | }; 56 | 57 | int main() { 58 | vec to_be_placed(gifts), already_placed, 59 | free_rectangles = {table}; 60 | to_be_placed.push_back(tree_stand); 61 | 62 | bool did_place_stand = false; 63 | 64 | while(true) { 65 | vec can_place; 66 | for(const auto & free : free_rectangles) { 67 | for(const auto & to_place : to_be_placed) { 68 | auto score = bssf_score(free, to_place); 69 | if(score != infty) { 70 | can_place.push_back( 71 | placeable{free, to_place, score, false}); 72 | } 73 | } 74 | } 75 | 76 | for(const auto & free : free_rectangles) { 77 | for(const auto & to_place : to_be_placed) { 78 | auto score = bssf_score(free, to_place.transpose()); 79 | if(to_place == tree_stand) { 80 | can_place.push_back(placeable{free, to_place, 0, true}); 81 | } else if(score != infty) { 82 | can_place.push_back(placeable{free, to_place, score, true}); 83 | } 84 | } 85 | } 86 | 87 | if(can_place.size() == 0) break; 88 | 89 | placeable best = 90 | *min_element(can_place.begin(), can_place.end(), 91 | [](auto r1, auto r2) { return r1.score < r2.score; }); 92 | 93 | if(best.to_place == tree_stand) did_place_stand = true; 94 | 95 | auto new_rect = 96 | best.transposed ? best.to_place.transpose() : best.to_place; 97 | new_rect = new_rect.translate(best.free.p0()); 98 | 99 | auto split = !(new_rect == best.free); 100 | auto old_free = best.free; 101 | 102 | already_placed.push_back(new_rect); 103 | to_be_placed.erase( 104 | remove(to_be_placed.begin(), to_be_placed.end(), best.to_place), 105 | to_be_placed.end()); 106 | free_rectangles.erase( 107 | remove(free_rectangles.begin(), free_rectangles.end(), best.free), 108 | free_rectangles.end()); 109 | 110 | if(split) { 111 | if(old_free.width() < old_free.height()) { 112 | Rectangle h1({new_rect.x0(), new_rect.y1()}, 113 | {old_free.x1(), old_free.y1()}); 114 | Rectangle h2({new_rect.x1(), new_rect.y0()}, 115 | {old_free.x1(), new_rect.y1()}); 116 | free_rectangles.push_back(h1); 117 | free_rectangles.push_back(h2); 118 | } else { 119 | Rectangle v1({new_rect.x0(), new_rect.y1()}, 120 | {new_rect.x1(), old_free.y1()}); 121 | Rectangle v2({new_rect.x1(), new_rect.y0()}, 122 | {old_free.x1(), old_free.y1()}); 123 | free_rectangles.push_back(v1); 124 | free_rectangles.push_back(v2); 125 | } 126 | } 127 | 128 | bool merged; 129 | 130 | do { 131 | merged = false; 132 | 133 | restart: 134 | for(int i = 0; i < free_rectangles.size(); i++) { 135 | for(int j = i + 1; j < free_rectangles.size(); j++) { 136 | auto a = free_rectangles[i]; 137 | auto b = free_rectangles[j]; 138 | auto un = rectangle_union(a, b); 139 | 140 | if(un.area() == a.area() + b.area()) { 141 | free_rectangles.erase(free_rectangles.begin() + i); 142 | free_rectangles.erase(free_rectangles.begin() + j); 143 | free_rectangles.push_back(un); 144 | 145 | merged = true; 146 | goto restart; 147 | } 148 | } 149 | } 150 | } while(merged); 151 | } 152 | 153 | assert(("did not place tree stand", did_place_stand)); 154 | for(const auto & rect : already_placed) { assert(table.contains(rect)); } 155 | for(int i = 0; i < already_placed.size(); i++) { 156 | for(int j = i + 1; j < already_placed.size(); j++) { 157 | assert(rectangle_intersection(already_placed[i], already_placed[j]) 158 | .area() <= 0.0); 159 | } 160 | } 161 | cout << already_placed << endl; 162 | } 163 | -------------------------------------------------------------------------------- /ipi/tutorial/09/gifts.txt: -------------------------------------------------------------------------------- 1 | Rectangle table(Point(100.0, 80.0)); 2 | Rectangle tree_stand(Point(30.0, 30.0)); 3 | 4 | std::vector gifts = { Rectangle(Point(20.0, 10.0)), 5 | Rectangle(Point(10.0, 11.0)), 6 | Rectangle(Point(3.0, 46.0)), 7 | Rectangle(Point(3.0, 4.0)), 8 | Rectangle(Point(6.0, 16.0)), 9 | Rectangle(Point(10.0, 20.0)), 10 | Rectangle(Point(20.0, 8.0)), 11 | Rectangle(Point(12.0, 37.0)), 12 | Rectangle(Point(11.0, 15.0)), 13 | Rectangle(Point(40.0, 63.0)), 14 | Rectangle(Point(23.0, 6.0)), 15 | Rectangle(Point(16.0, 12.0)), 16 | Rectangle(Point(25.0, 20.0)), 17 | Rectangle(Point(67.0, 3.0)), 18 | Rectangle(Point(31.0, 29.0)), 19 | Rectangle(Point(12.0, 11.0)), 20 | Rectangle(Point(8.0, 9.0)), 21 | Rectangle(Point(3.0, 8.0)), 22 | Rectangle(Point(21.0, 13.0)), 23 | Rectangle(Point(46.0, 13.0)), 24 | Rectangle(Point(11.0, 75.0)), 25 | Rectangle(Point(4.0, 3.0)), 26 | Rectangle(Point(19.0, 7.0)), 27 | Rectangle(Point(33.0, 7.0)), 28 | Rectangle(Point(6.0, 16.0)), 29 | Rectangle(Point(21.0, 4.0)), 30 | Rectangle(Point(8.0, 8.0)), 31 | Rectangle(Point(3.0, 86.0)), 32 | Rectangle(Point(20.0, 6.0)), 33 | Rectangle(Point(21.0, 3.0)), 34 | Rectangle(Point(13.0, 59.0)), 35 | Rectangle(Point(4.0, 20.0)) 36 | }; 37 | -------------------------------------------------------------------------------- /ipi/tutorial/09/rectangle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | rectangle.cpp -- rectangle class, requires c++14 4 | */ 5 | 6 | #include "rec.cpp" 7 | 8 | int main() { testRectangle(); } 9 | -------------------------------------------------------------------------------- /ipi/tutorial/09/rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ipi/tutorial/09/rectangle.png -------------------------------------------------------------------------------- /ipi/tutorial/10/image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | image.cpp -- pnm image manipulation 4 | */ 5 | 6 | #include "image.hpp" 7 | #include 8 | #include 9 | 10 | Image chessboard(unsigned int width, unsigned int height, 11 | unsigned int square_size) { 12 | Image i(width, height); 13 | for(unsigned int y = 0; y < height; y++) { 14 | for(unsigned int x = 0; x < width; x++) { 15 | if(y % (square_size * 2) < square_size) { 16 | if(x % (square_size * 2) < square_size) { i(x, y) = 255; } 17 | } else { 18 | if(x % (square_size * 2) >= square_size) { i(x, y) = 255; } 19 | } 20 | } 21 | } 22 | 23 | return i; 24 | } 25 | 26 | Image invert_image(Image const & image) { 27 | Image ret(image.width(), image.height()); 28 | for(int y = 0; y < image.height(); y++) { 29 | for(int x = 0; x < image.width(); x++) { 30 | ret(x, y) = 255 - image(x, y); 31 | } 32 | } 33 | 34 | return ret; 35 | } 36 | 37 | int main() { 38 | Image i(4, 3); 39 | assert(i.width() == 4); 40 | assert(i.height() == 3); 41 | 42 | for(int x = 0; x < i.width(); x++) { 43 | for(int y = 0; y < i.height(); y++) { assert(i(x, y) == 0); } 44 | } 45 | 46 | assert(to_string(i) == std::string("0 0 0 0\n0 0 0 0\n0 0 0 0\n")); 47 | 48 | for(int x = 0; x < i.width(); x++) { 49 | for(int y = 0; y < i.height(); y++) { 50 | i(x, y) = 255 * ((x + 1 + y % 2) % 2); 51 | } 52 | } 53 | for(int x = 0; x < i.width(); x++) { 54 | for(int y = 0; y < i.height(); y++) { 55 | assert(i(x, y) == 255 * ((x + 1 + y % 2) % 2)); 56 | } 57 | } 58 | assert(to_string(i) == 59 | std::string("255 0 255 0\n0 255 0 255\n255 0 255 0\n")); 60 | writePGM(i, "board4x3.pgm"); 61 | auto i2 = readPGM("board4x3.pgm"); 62 | assert(i == i2); 63 | 64 | auto c1 = chessboard(400, 300, 20); 65 | writePGM(c1, "board400x300.pgm"); 66 | auto c2 = readPGM("board400x300.pgm"); 67 | assert(c1 == c2); 68 | writePGM(invert_image(c2), "board400x300-inverse.pgm"); 69 | 70 | writePGM(invert_image(readPGM("lena.pgm")), "lena-invert.pgm"); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ipi/tutorial/10/kaleidoscope.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | kaleidoscope.cpp -- Image mirroring 4 | */ 5 | 6 | #include 7 | #include "image.hpp" 8 | 9 | Image mirror_x(Image const & image) { 10 | Image r(image.width() * 2, image.height()); 11 | 12 | for(int y = 0; y < image.height(); y++) { 13 | for(int x = 0; x < image.width(); x++) { 14 | r(x, y) = image(x, y); 15 | r(r.width() - x - 1, y) = image(x, y); 16 | } 17 | } 18 | 19 | return r; 20 | } 21 | 22 | Image mirror_y(Image const & image) { 23 | Image r(image.width(), image.height() * 2); 24 | 25 | for(int y = 0; y < image.height(); y++) { 26 | for(int x = 0; x < image.width(); x++) { 27 | r(x, y) = image(x, y); 28 | r(x, r.height() - y - 1) = image(x, y); 29 | } 30 | } 31 | 32 | return r; 33 | } 34 | 35 | Image mirror_d(Image const & image) { 36 | Image r(image.height(), image.width()); 37 | 38 | for(int y = 0; y < image.height(); y++) { 39 | for(int x = 0; x < image.width(); x++) { 40 | if(x > y) { 41 | r(x, y) = image(y, x); 42 | } else { 43 | r(x, y) = image(x, y); 44 | } 45 | } 46 | } 47 | 48 | return r; 49 | } 50 | 51 | void assert_equal(Image const & i, std::string filename) { 52 | assert(i == readPGM(filename)); 53 | } 54 | 55 | Image kaleidoscope4(Image const & image) { 56 | return mirror_y(mirror_x(image)); 57 | } 58 | 59 | Image kaleidoscope8(Image const & image) { 60 | return mirror_y(mirror_x(mirror_d(image))); 61 | } 62 | 63 | int main() { 64 | assert_equal(mirror_x(readPGM("lena.pgm")), "mirror_x_test.pgm"); 65 | assert_equal(mirror_y(readPGM("lena.pgm")), "mirror_y_test.pgm"); 66 | assert_equal(kaleidoscope4(readPGM("lena.pgm")), "kaleidoskop4_test.pgm"); 67 | assert_equal(kaleidoscope8(readPGM("lena.pgm")), "kaleidoskop8_test.pgm"); 68 | writePGM(kaleidoscope8(readPGM("my_image.pgm")), "my_kaleidoscope.pgm"); 69 | } 70 | -------------------------------------------------------------------------------- /ipi/tutorial/10/point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class Point { 6 | private: 7 | // die Koordinaten des Punktes 8 | double x_; 9 | double y_; 10 | 11 | public: 12 | // Standardkonstruktor: initialisiere Punkt (0,0) 13 | Point() : x_(0), y_(0) {} 14 | 15 | // Konstruktor mit zwei Koordinaten: initialisiere Punkt (x,y) 16 | Point(double x, double y) : x_(x), y_(y) {} 17 | 18 | // Getter-Funktionen fuer die Koordinaten 19 | double x() const { return (*this).x_; } 20 | 21 | double y() const { return (*this).y_; } 22 | 23 | // teste ob zwei Punkte gleich sind 24 | bool operator==(Point const & other) const { 25 | return (*this).x() == other.x() && (*this).y() == other.y(); 26 | } 27 | 28 | // teste ob zwei Punkte ungleich sind 29 | bool operator!=(Point const & other) const { 30 | return (*this).x() != other.x() || (*this).y() != other.y(); 31 | } 32 | 33 | // erzeuge neuen Punkt, desssen x- und y-Koordinate 34 | // vertauscht sind 35 | Point transpose() const { 36 | Point res((*this).y(), (*this).x()); 37 | return res; 38 | } 39 | 40 | // erzeuge neuen Punkt, der um den Vektor v verschoben ist 41 | Point translate(Point const & v) const { 42 | Point res((*this).x() + v.x(), (*this).y() + v.y()); 43 | return res; 44 | } 45 | }; 46 | 47 | // wandle den Punkt in einen String der Form "[x, y]" 48 | std::string to_string(Point const & p) { 49 | return "[" + std::to_string(p.x()) + ", " + std::to_string(p.y()) + "]"; 50 | } 51 | 52 | Point operator+(Point p1, Point p2) { 53 | return {p1.x() + p2.x(), p1.y() + p2.y()}; 54 | } 55 | 56 | Point operator-(Point p1, Point p2) { 57 | return {p1.x() - p2.x(), p1.y() - p2.y()}; 58 | } 59 | 60 | Point operator*(Point p1, Point p2) { 61 | return {p1.x() * p2.x(), p1.y() * p2.y()}; 62 | } 63 | 64 | Point operator/(Point p1, Point p2) { 65 | return {p1.x() / p2.x(), p1.y() / p2.y()}; 66 | } 67 | 68 | Point operator*(double s, Point p) { 69 | return {s * p.x(), s * p.y()}; 70 | } 71 | 72 | Point operator*(Point p, double s) { 73 | return {p.x() * s, p.y() * s}; 74 | } 75 | 76 | Point operator/(Point p, double s) { 77 | return {p.x() / s, p.y() / s}; 78 | } 79 | 80 | Point operator-(Point p) { 81 | return {-p.x(), -p.y()}; 82 | } 83 | 84 | void test_Point() { 85 | using P = Point; 86 | 87 | Point p(2, 3), q(4, 5); 88 | assert(p + q == Point(6, 8)); 89 | assert(p - q == Point(-2, -2)); 90 | assert(p * q == Point(8, 15)); 91 | assert(p / q == Point(0.5, 3.0 / 5.0)); 92 | assert(p * 0 == Point(0, 0)); 93 | assert(p * 1 == p); 94 | assert(p * -1 == Point(0, 0) - p); 95 | assert(0 * p == p * 0); 96 | assert(1 * p == p * 1); 97 | assert(-1 * p == p * -1); 98 | assert(p / 1 == p); 99 | assert(q / 2 == Point(2, 2.5)); 100 | assert(2 * q / 2 == q); 101 | assert(-p == Point(0, 0) - p); 102 | assert(-q == Point(0, 0) - q); 103 | assert(-p + p == Point(0, 0)); 104 | 105 | p = {1, 4}; 106 | q = {2, 3}; 107 | assert((p + q) == Point(3, 7)); 108 | assert((p - q) == Point(-1, 1)); 109 | assert((p * q) == Point(2, 12)); 110 | assert((p / q) == Point(0.5, 4.0 / 3.0)); 111 | 112 | p = {199, 123}; 113 | q = {121, 144}; 114 | assert((p + q) == Point(320, 267)); 115 | assert((p - q) == Point(78, -21)); 116 | assert((p * q) == Point(24079, 17712)); 117 | assert((p / q) == Point(199.0 / 121.0, 123.0 / 144.0)); 118 | 119 | std::cout << "Alle Tests erfolgreich.\n"; 120 | } 121 | 122 | int main() { test_Point(); } 123 | -------------------------------------------------------------------------------- /ipi/tutorial/11/conway.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | conway.cpp -- conway game of life 4 | */ 5 | 6 | #include "image.hpp" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int get_periodic(int x, int width) { return ((x % width) + width) % width; } 13 | 14 | int count_alive_neighbors(Image const & image, int x, int y) { 15 | int count = 0; 16 | count += image.get_periodic(x + 1, y + 1) ? 0 : 1; 17 | count += image.get_periodic(x + 0, y + 1) ? 0 : 1; 18 | count += image.get_periodic(x - 1, y + 1) ? 0 : 1; 19 | 20 | count += image.get_periodic(x + 1, y - 0) ? 0 : 1; 21 | count += image.get_periodic(x - 1, y - 0) ? 0 : 1; 22 | 23 | count += image.get_periodic(x + 1, y - 1) ? 0 : 1; 24 | count += image.get_periodic(x + 0, y - 1) ? 0 : 1; 25 | count += image.get_periodic(x - 1, y - 1) ? 0 : 1; 26 | 27 | return count; 28 | } 29 | 30 | Image conway_step(Image const & image) { 31 | Image n(image.width(), image.height()); 32 | int ns = 0; 33 | 34 | for(int y = 0; y < image.height(); y++) { 35 | for(int x = 0; x < image.width(); x++) { 36 | ns = count_alive_neighbors(image, x, y); 37 | 38 | if(image(x, y)) { 39 | if(ns != 3) { n(x, y) = 255; } 40 | } else { 41 | if((ns < 2) || (ns > 3)) { n(x, y) = 255; } 42 | } 43 | } 44 | } 45 | 46 | return n; 47 | } 48 | 49 | Image scale_image(Image const & image, int scale) { 50 | Image n(image.width() * scale, image.height() * scale); 51 | 52 | for(int y = 0; y < n.height(); y++) { 53 | for(int x = 0; x < n.height(); x++) { 54 | n(x, y) = image(x / scale, y / scale); 55 | } 56 | } 57 | 58 | return n; 59 | } 60 | 61 | int main() { 62 | { 63 | auto init = readPGM("conway_init.pgm"); 64 | char buffer[19]; 65 | 66 | for(int i = 0; i < 100; i++) { 67 | init = conway_step(init); 68 | std::snprintf(buffer, 19, "conway_sim_%03d.pgm", i); 69 | writePGM(scale_image(init, 5), buffer); 70 | } 71 | init = scale_image(init, 5); 72 | assert(init == readPGM("conway_test.pgm")); 73 | } 74 | 75 | auto init = readPGM("my_conway.pgm"); 76 | char buffer[23]; 77 | 78 | for(int i = 0; i < 1103; i++) { 79 | init = conway_step(init); 80 | std::snprintf(buffer, 23, "my_conway_sim_%04d.pgm", i); 81 | writePGM(scale_image(init, 5), buffer); 82 | std::cout << buffer << std::endl; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /ipi/tutorial/11/my_simulation.mpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ipi/tutorial/11/my_simulation.mpg -------------------------------------------------------------------------------- /ipi/tutorial/11/point_template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template 6 | class Point { 7 | private: 8 | // die Koordinaten des Punktes 9 | T x_; 10 | T y_; 11 | 12 | public: 13 | // Standardkonstruktor: initialisiere Punkt (0,0) 14 | Point() : x_(0.0), y_(0.0) {} 15 | 16 | // Konstruktor mit zwei Koordinaten: initialisiere Punkt (x,y) 17 | Point(T x, T y) : x_(x), y_(y) {} 18 | 19 | // Getter-Funktionen fuer die Koordinaten 20 | T x() const { return (*this).x_; } 21 | 22 | T y() const { return (*this).y_; } 23 | 24 | // teste ob zwei Punkte gleich sind 25 | bool operator==(Point const & other) const { 26 | return (*this).x() == other.x() && (*this).y() == other.y(); 27 | } 28 | 29 | // teste ob zwei Punkte ungleich sind 30 | bool operator!=(Point const & other) const { 31 | return (*this).x() != other.x() || (*this).y() != other.y(); 32 | } 33 | 34 | // erzeuge neuen Punkt, desssen x- und y-Koordinate 35 | // vertauscht sind 36 | Point transpose() const { 37 | Point res((*this).y(), (*this).x()); 38 | return res; 39 | } 40 | 41 | // erzeuge neuen Punkt, der um den Vektor v verschoben ist 42 | Point translate(Point const & v) const { 43 | Point res((*this).x() + v.x(), (*this).y() + v.y()); 44 | return res; 45 | } 46 | }; 47 | 48 | template 49 | std::string to_string(Point const & p) { 50 | return "[" + std::to_string(p.x()) + ", " + std::to_string(p.y()) + "]"; 51 | } 52 | 53 | template 54 | Point operator+(Point p1, Point p2) { 55 | Point res(p1.x() + p2.x(), p1.y() + p2.y()); 56 | return res; 57 | } 58 | 59 | template 60 | Point operator-(Point p1, Point p2) { 61 | Point res(p1.x() - p2.x(), p1.y() - p2.y()); 62 | return res; 63 | } 64 | 65 | template 66 | Point operator-(Point p) { 67 | Point res(-p.x(), -p.y()); 68 | return res; 69 | } 70 | 71 | template 72 | Point operator*(Point p1, Point p2) { 73 | Point res(p1.x() * p2.x(), p1.y() * p2.y()); 74 | return res; 75 | } 76 | 77 | template 78 | Point operator*(T s, Point p) { 79 | Point res(s * p.x(), s * p.y()); 80 | return res; 81 | } 82 | 83 | template 84 | Point operator*(Point p, T s) { 85 | Point res(p.x() * s, p.y() * s); 86 | return res; 87 | } 88 | 89 | template 90 | Point operator/(Point p1, Point p2) { 91 | Point res(p1.x() / p2.x(), p1.y() / p2.y()); 92 | return res; 93 | } 94 | 95 | template 96 | Point operator/(Point p, T d) { 97 | Point res(p.x() / d, p.y() / d); 98 | return res; 99 | } 100 | 101 | void test_Point_double() { 102 | using P = Point; 103 | 104 | P p(2.0, 3.0), q(4.0, 5.0); 105 | assert(p + q == P(6.0, 8.0)); 106 | assert(p - q == P(-2.0, -2.0)); 107 | assert(p * q == P(8.0, 15.0)); 108 | assert(p / q == P(0.5, 3.0 / 5.0)); 109 | assert(p * 0.0 == P(0.0, 0.0)); 110 | assert(p * 1.0 == p); 111 | assert(p * -1.0 == P(0.0, 0.0) - p); 112 | assert(0.0 * p == p * 0.0); 113 | assert(1.0 * p == p * 1.0); 114 | assert(-1.0 * p == p * -1.0); 115 | assert(p / 1.0 == p); 116 | assert(q / 2.0 == P(2.0, 2.5)); 117 | assert(2.0 * q / 2.0 == q); 118 | assert(-p == P(0.0, 0.0) - p); 119 | assert(-q == P(0.0, 0.0) - q); 120 | assert(-p + p == P(0.0, 0.0)); 121 | 122 | p = {1.0, 4.0}; 123 | q = {2.0, 3.0}; 124 | assert((p + q) == P(3.0, 7.0)); 125 | assert((p - q) == P(-1.0, 1.0)); 126 | assert((p * q) == P(2.0, 12.0)); 127 | assert((p / q) == P(0.5, 4.0 / 3.0)); 128 | 129 | p = {199.0, 123.0}; 130 | q = {121.0, 144.0}; 131 | assert((p + q) == P(320.0, 267.0)); 132 | assert((p - q) == P(78.0, -21.0)); 133 | assert((p * q) == P(24079.0, 17712.0)); 134 | assert((p / q) == P(199.0 / 121.0, 123.0 / 144.0)); 135 | 136 | std::cout << "Alle Tests erfolgreich.\n"; 137 | } 138 | 139 | void test_Point_int() { 140 | using P = Point; 141 | 142 | P p(2, 3), q(4, 5); 143 | assert(p + q == P(6, 8)); 144 | assert(p - q == P(-2, -2)); 145 | assert(p * q == P(8, 15)); 146 | assert(p / q == P(0.5, 3.0 / 5.0)); 147 | assert(p * 0 == P(0, 0)); 148 | assert(p * 1 == p); 149 | assert(p * -1 == P(0, 0) - p); 150 | assert(0 * p == p * 0); 151 | assert(1 * p == p * 1); 152 | assert(-1 * p == p * -1); 153 | assert(p / 1 == p); 154 | assert(q / 2 == P(2, 2.5)); 155 | assert(2 * q / 2 == q); 156 | assert(-p == P(0, 0) - p); 157 | assert(-q == P(0, 0) - q); 158 | assert(-p + p == P(0, 0)); 159 | 160 | p = {1, 4}; 161 | q = {2, 3}; 162 | assert((p + q) == P(3, 7)); 163 | assert((p - q) == P(-1, 1)); 164 | assert((p * q) == P(2, 12)); 165 | assert((p / q) == P(0.5, 4.0 / 3.0)); 166 | 167 | p = {199, 123}; 168 | q = {121, 144}; 169 | assert((p + q) == P(320, 267)); 170 | assert((p - q) == P(78, -21)); 171 | assert((p * q) == P(24079, 17712)); 172 | assert((p / q) == P(199.0 / 121.0, 123.0 / 144.0)); 173 | 174 | std::cout << "Alle Tests erfolgreich.\n"; 175 | } 176 | 177 | int main() { 178 | test_Point_double(); 179 | test_Point_int(); 180 | } 181 | -------------------------------------------------------------------------------- /ipi/tutorial/11/polynomial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | class Polynomial { 7 | std::vector a_; 8 | 9 | public: 10 | // Konstruktor, dem die Koeffizienten als C-Array 11 | // uebergeben werden koennen, z.B.: 12 | // 13 | // Polynomial p{1, 2, 3}; 14 | Polynomial(std::initializer_list coeffs) noexcept : a_{coeffs} {} 15 | 16 | // Konstruktor fuer ein Polynom vom Grad 0 (nur der konstante 17 | // Koeffizient ist definiert und hat den Wert 0). 18 | Polynomial() noexcept : Polynomial(0) {} 19 | 20 | // Konstruktor fuer ein Polynom vom Grad n, bei dem alle 21 | // Koeffizienten 0 sind. Der Fall n < 0 soll wie n == 0 behandelt 22 | // werden. 23 | Polynomial(int n) noexcept : a_(std::max(n, 0) + 1) {} 24 | 25 | // Grad des Polynoms (Exponent der hoechsten vorkommenden Potenz) 26 | int degree() const noexcept { return a_.size() > 0 ? a_.size() - 1 : 0; } 27 | 28 | // lesender Zugriff auf den Koeffizienten zur Potenz i 29 | int operator[](int i) const noexcept { return a_[i]; } 30 | 31 | // Lese-/Schreib-Zugriff auf den Koeffizienten zur Potenz i 32 | int & operator[](int i) noexcept { return a_[i]; } 33 | 34 | // Ausrechnen des Polynoms fuer das Argument x 35 | int operator()(int x) const noexcept { 36 | int y = 0; 37 | 38 | for(int i = a_.size(); i >= 0; i--) { 39 | y *= x; 40 | y += a_[i]; 41 | } 42 | 43 | return y; 44 | } 45 | 46 | bool operator==(const Polynomial & other) const noexcept { 47 | return a_ == other.a_; 48 | } 49 | 50 | Polynomial operator+(const Polynomial & other) const noexcept { 51 | int max_degree = std::max(other.degree(), degree()); 52 | Polynomial p(max_degree); 53 | 54 | for(int i = 0; i <= max_degree; i++) { p[i] = a_[i] + other[i]; } 55 | 56 | return p; 57 | } 58 | 59 | Polynomial operator*(const Polynomial & other) const noexcept { 60 | int new_degree = degree() + other.degree(); 61 | Polynomial bigger = degree() > other.degree() ? *this : other; 62 | Polynomial smaller = degree() > other.degree() ? other : *this; 63 | Polynomial p(new_degree); 64 | 65 | for(int i = 0; i <= new_degree; i++) { 66 | int sum = 0; 67 | 68 | for(int x = std::max(i - smaller.degree(), 0); x <= bigger.degree(); 69 | x++) { 70 | auto y = i - x; 71 | if(y < 0) continue; 72 | 73 | sum += bigger[x] * smaller[y]; 74 | } 75 | p[i] = sum; 76 | } 77 | 78 | return p; 79 | } 80 | 81 | Polynomial derivative(int i = 1) const noexcept { 82 | Polynomial d(degree() - 1); 83 | 84 | for(int i = 0; i <= d.degree(); i++) { d[i] = (i + 1) * a_[i + 1]; } 85 | 86 | if(i == 1) { 87 | return d; 88 | } else { 89 | return d.derivative(i - 1); 90 | } 91 | } 92 | }; 93 | 94 | int main() { 95 | // testen des Standard-Konstruktors 96 | Polynomial p0; 97 | assert(p0.degree() == 0); 98 | assert(p0[0] == 0); 99 | 100 | // testen des Konstruktors mit Gradangabe 101 | Polynomial pm(-1); 102 | assert(pm == p0); 103 | 104 | Polynomial p2(2); 105 | assert(p2.degree() == 2); 106 | 107 | // testen des Konstruktors mit Koeffizientenarray 108 | Polynomial p{1, 2, 3}; 109 | assert(p.degree() == 2); 110 | 111 | // testen der Werte der Koeffizienten 112 | assert(p2[0] == 0); 113 | assert(p2[1] == 0); 114 | assert(p2[2] == 0); 115 | 116 | assert(p[0] == 1); 117 | assert(p[1] == 2); 118 | assert(p[2] == 3); 119 | 120 | // testen, dass die Polynom fuer verschiedene Argumente x 121 | // korrekt ausgerechnet werden 122 | assert(p0(1) == 0); 123 | assert(p0(2) == 0); 124 | assert(p0(3) == 0); 125 | 126 | assert(p2(1) == 0); 127 | assert(p2(2) == 0); 128 | assert(p2(3) == 0); 129 | 130 | assert(p(1) == 6); 131 | assert(p(2) == 17); 132 | assert(p(3) == 34); 133 | 134 | // testen der Polynom-Addition 135 | Polynomial pa1 = p + p; 136 | Polynomial pa1_expected{2, 4, 6}; 137 | assert(pa1 == pa1_expected); 138 | 139 | Polynomial pa2 = p + Polynomial{3, 6}; 140 | Polynomial pa2_expected{4, 8, 3}; 141 | assert(pa2 == pa2_expected); 142 | 143 | // testen der Polynom-Multiplikation 144 | Polynomial pm1 = p * p; 145 | assert(pm1.degree() == 4); 146 | assert(pm1(2) == p(2) * p(2)); 147 | Polynomial pm1_expected{1, 4, 10, 12, 9}; 148 | assert(pm1 == pm1_expected); 149 | 150 | Polynomial pm2 = p * Polynomial{2, 6}; 151 | assert(pm2.degree() == 3); 152 | Polynomial pm2_expected{2, 10, 18, 18}; 153 | assert(pm2 == pm2_expected); 154 | 155 | // testen der ersten Ableitung 156 | Polynomial derivative1_expected{2, 6}; 157 | assert(p.derivative() == derivative1_expected); 158 | assert(p.derivative(1) == derivative1_expected); 159 | 160 | // testen der zweiten bis vierten Ableitung 161 | Polynomial derivative2_expected{6}; 162 | assert(p.derivative(2) == derivative2_expected); 163 | Polynomial derivative3_expected{0}; 164 | assert(p.derivative(3) == derivative3_expected); 165 | assert(p.derivative(4) == derivative3_expected); 166 | 167 | std::cout << "Alle Tests erfolgreich!\n"; 168 | } 169 | -------------------------------------------------------------------------------- /ipi/tutorial/11/simulation.mpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/ipi/tutorial/11/simulation.mpg -------------------------------------------------------------------------------- /ipi/tutorial/12/koordinaten.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | koordinaten.cpp -- coodinate transformations 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "image.hpp" 11 | 12 | template 13 | struct v2 { 14 | T x; 15 | T y; 16 | }; 17 | 18 | /* 19 | Die Formel ist 20 | x = (ix - cx)d + x_{center} 21 | y = (iy - cy)d + y_{center} 22 | */ 23 | 24 | v2 pixel_to_real(v2 p, v2 cp, v2 cr, double d) { 25 | return {(p.x - cp.x) * d + cr.x, (p.y - cp.y) * d + cr.y}; 26 | } 27 | 28 | template 29 | inline auto sq(T && t) noexcept { 30 | return t * t; 31 | } 32 | 33 | int main() { 34 | Image i1(640, 480), i2 = i1; 35 | 36 | for(int y = 0; y < i1.height(); y++) { 37 | for(int x = 0; x < i1.width(); x++) { 38 | auto real = pixel_to_real({x, y}, {i1.width() / 2, i2.height() / 2}, 39 | {0, 0}, 1.0 / 64.0); 40 | i1(x, y) = 255.0 * sq(std::sin(sq(real.x) + sq(real.y))); 41 | real = pixel_to_real({x, y}, {i1.width() / 2, i2.height() / 2}, 42 | {0, 0}, 1); 43 | i2(x, y) = 255.0 * sq(std::sin((sq(real.x) + sq(real.y)) / 4096.0)); 44 | } 45 | } 46 | 47 | assert(i1 == i2); 48 | 49 | writePGM(i1, "koordinaten.pgm"); 50 | } 51 | -------------------------------------------------------------------------------- /ipi/tutorial/12/mandelbrot.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Robin Heinemann. All Rights Reserved. 3 | mandelbrot.cpp -- mandelbrot fractal 4 | */ 5 | 6 | #include "image.hpp" 7 | 8 | #include 9 | #include 10 | 11 | using cmplx = std::complex; 12 | using namespace std; 13 | 14 | constexpr int max_norm = 1000; 15 | constexpr int max_iter = 512; 16 | 17 | class FractalView { 18 | double x_center_, y_center_, pixel_side_; 19 | 20 | int iterations_until_limit(cmplx const & c) const { 21 | cmplx z(0, 0); 22 | int iters = 0; 23 | 24 | while((iters++ < max_iter) && (norm(z) < max_norm)) { z = z * z + c; } 25 | 26 | return iters; 27 | } 28 | 29 | cmplx pixel_to_real(cmplx p, cmplx cp, cmplx cr, double d) const { 30 | return (p - cp) * d + cr; 31 | /* return {(p.real() - cp.real()) * d + cr.x, (p.y - cp.y) * d + cr.y}; 32 | */ 33 | } 34 | 35 | cmplx pixel_to_complex(Image const & img, double ix, double iy) const { 36 | return pixel_to_real(cmplx(ix, iy), 37 | cmplx(img.width() / 2, img.height() / 2), 38 | cmplx(x_center_, y_center_), pixel_side_); 39 | } 40 | 41 | uint16_t color_scheme(double num_iterations) const { 42 | return 255.0 - 43 | std::sin((std::cbrt(num_iterations) / std::cbrt(max_iter)) * 44 | 4.0 * M_PI + 45 | M_PI) * 46 | 255.0; 47 | }; 48 | 49 | public: 50 | double & x_center() { return x_center_; } 51 | 52 | double & y_center() { return y_center_; } 53 | 54 | double & pixel_side() { return pixel_side_; } 55 | 56 | void render_mandelbrot(Image & img) const { 57 | for(int y = 0; y < img.height(); y++) { 58 | for(int x = 0; x < img.width(); x++) { 59 | double its = 0; 60 | its += iterations_until_limit( 61 | pixel_to_complex(img, (double)x + 0.25, (double)y + 0.25)); 62 | its += iterations_until_limit( 63 | pixel_to_complex(img, (double)x + 0.25, (double)y - 0.25)); 64 | its += iterations_until_limit( 65 | pixel_to_complex(img, (double)x - 0.25, (double)y + 0.25)); 66 | its += iterations_until_limit( 67 | pixel_to_complex(img, (double)x - 0.25, (double)y - 0.25)); 68 | its /= 4; 69 | img(x, y) = color_scheme(its); 70 | } 71 | } 72 | } 73 | 74 | public: 75 | FractalView(double x, double y, double d) 76 | : x_center_(x), y_center_(y), pixel_side_(d) {} 77 | }; 78 | 79 | int main() { 80 | { 81 | FractalView v(0, 0, 4.0 / (640.0 / 2.0)); 82 | Image i(640, 480); 83 | v.render_mandelbrot(i); 84 | writePGM(i, "mandelbrot_overview.pgm"); 85 | } 86 | 87 | { 88 | FractalView v(0.375011, -0.1875, 2.38419e-08); 89 | Image i(640, 480); 90 | v.render_mandelbrot(i); 91 | writePGM(i, "mandelbrot_zoom.pgm"); 92 | } 93 | 94 | bool open = true; 95 | double x = 0; 96 | double y = 0; 97 | double zoom = 4; 98 | double width = 640; 99 | double height = 480; 100 | FractalView v(x, y, zoom / (width / 2.0)); 101 | Image i(width, height); 102 | 103 | while(open) { 104 | v.render_mandelbrot(i); 105 | writePGM(i, "mandelbrot.pgm"); 106 | zoom = v.pixel_side(); 107 | x = v.x_center(); 108 | y = v.y_center(); 109 | 110 | char in; 111 | std::cin >> in; 112 | 113 | switch(in) { 114 | case 'a': { 115 | v.x_center() -= (width / 4.0) * zoom; 116 | break; 117 | } 118 | case 'd': { 119 | v.x_center() += (width / 4.0) * zoom; 120 | break; 121 | } 122 | case 'w': { 123 | v.y_center() -= (height / 4.0) * zoom; 124 | break; 125 | } 126 | case 's': { 127 | v.y_center() += (height / 4.0) * zoom; 128 | break; 129 | } 130 | case '+': { 131 | v.pixel_side() /= 2; 132 | break; 133 | } 134 | case '-': { 135 | v.pixel_side() *= 2; 136 | break; 137 | } 138 | case 'b': { 139 | open = false; 140 | break; 141 | } 142 | default: 143 | break; 144 | } 145 | 146 | std::cout << v.x_center() << std::endl; 147 | std::cout << v.y_center() << std::endl; 148 | std::cout << v.pixel_side() << std::endl; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /ipi/tutorial/link: -------------------------------------------------------------------------------- 1 | https://elearning2.uni-heidelberg.de/course/view.php?id=13385 2 | -------------------------------------------------------------------------------- /ipi/tutorial/tutorial: -------------------------------------------------------------------------------- 1 | Abgabe als zip: <1.Nachname>_<2.Nachname>[_<3.Nachname>].zip, kein Unterordner -------------------------------------------------------------------------------- /keys.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/keys.enc -------------------------------------------------------------------------------- /la1/introduction.org: -------------------------------------------------------------------------------- 1 | * Einleitung 2 | # Passwort für Downloads (Website Prof. Gade): GRUNDVORLESUNG 3 | Übungsblätter/Lösungen: 4 | jew. Donnerstag / folgender Donnerstag 5 | Abgabe Donnerstag 9:30 6 | 50% der Übungsblätter 7 | ** Plenarübung 8 | Aufgeteilt 9 | ** Moodle 10 | Passwort: vektorraumhomomorphismus 11 | ** Klausur 12 | 24.02.2017 13 | -------------------------------------------------------------------------------- /la1/la1.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Lineare Algebra I (Vogel) 3 | 4 | #+INCLUDE: "../header_de.org" :minlevel 1 5 | 6 | # Kapitel 1: Grundlagen 7 | #+INCLUDE: "introduction.org" :minlevel 1 8 | #+INCLUDE: "basics.org" :minlevel 1 9 | #+INCLUDE: "algebra.org" :minlevel 1 10 | #+INCLUDE: "polynomial.org" :minlevel 1 11 | # Kapitel 2: ????? 12 | #+INCLUDE: "vector_space.org" :minlevel 1 13 | #+INCLUDE: "basis_dimension.org" :minlevel 1 14 | #+INCLUDE: "matrix.org" :minlevel 1 15 | #+INCLUDE: "sub_vector_space.org" :minlevel 1 16 | # Kapitel 3: Lineare Abbildungen 17 | #+INCLUDE: "linear_map.org" :minlevel 1 18 | #+INCLUDE: "quotient_space.org" :minlevel 1 19 | #+INCLUDE: "linear_systems.org" :minlevel 1 20 | #+INCLUDE: "linear_systems_matrices.org" :minlevel 1 21 | #+INCLUDE: "basis_change.org" :minlevel 1 22 | #+INCLUDE: "determinants.org" :minlevel 1 23 | -------------------------------------------------------------------------------- /la1/tutorial/12/solution.dvi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/la1/tutorial/12/solution.dvi -------------------------------------------------------------------------------- /la1/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/moodle) --delete-after https://elearning2.uni-heidelberg.de/login/index.php 4 | match=' Blatt .*? Datei' 5 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://elearning2.uni-heidelberg.de/course/view.php?id=12813' | grep -Po '(?<=(href="))https://elearning2.uni-heidelberg.de/mod/resource/view.php.*?(?=")(?=.*?>Blatt .*?<)') 6 | 7 | rm *.pdf 8 | 9 | for pdf in $pdfs 10 | do 11 | wget --content-disposition --load-cookies cookies.txt $pdf 12 | done 13 | 14 | rm HinweiseZurUebungV4.pdf 15 | rm MusterloesungBlatt01.pdf 16 | -------------------------------------------------------------------------------- /la1/tutorial/link: -------------------------------------------------------------------------------- 1 | https://elearning2.uni-heidelberg.de/course/view.php?id=12813 2 | -------------------------------------------------------------------------------- /la2/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IFS=$'\n' 4 | 5 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/moodle) --delete-after https://elearning2.uni-heidelberg.de/login/index.php 6 | 7 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://elearning2.uni-heidelberg.de/course/view.php?id=14484' | pcregrep --buffer-size 10M -o1 '(https:\/\/elearning2\.uni-heidelberg\.de\/mod\/resource\/view\.php\?id=\d*?)"> Übungsblatt .\d*') 8 | 9 | echo $pdfs 10 | 11 | rm *.pdf 12 | 13 | for pdf in $pdfs 14 | do 15 | wget --content-disposition --load-cookies cookies.txt $pdf 16 | done 17 | -------------------------------------------------------------------------------- /numerik/introduction.org: -------------------------------------------------------------------------------- 1 | * Einführung 2 | #+begin_ex latex 3 | Simulation einer Pendelbewegung \\ 4 | Modellannahmen: 5 | - Masse $m$ an Stange 6 | - keine Reibung 7 | - Stange: Gewicht $0$, starr, Länge $l$ 8 | - Auslenkung $ϕ$ 9 | *Erste Fehlerquelle:* Modellierungsfehler \\ 10 | Modellgleichungen: 11 | \[F_T(ϕ) = - m·g \sin ϕ\] 12 | Konsistenzcheck: 13 | \begin{align*} 14 | F_T(0) = 0 \tag{Ruhelage} \\ 15 | F_T(\frac{\pi}{2}) = F_G = - m g \\ 16 | \end{align*} 17 | Bewegungsgleichungen: 18 | - Weg $s(t)$ 19 | - $\dd{s}{t} =: v(t)$ Geschwindigkeit 20 | - $\dd{v}{t} =: a(t)$ Beschleunigung 21 | Beziehungen: 22 | - Bogenlänge $s(t) = l ϕ(t)$ 23 | - 2. Newton'sches Gesetz ($F = m a$) 24 | \[-m g \sin ϕ(t) = m \dd{}{t} v(t) = m \frac{\d^2}{\d t^2} s(t) = m l \frac{\d^2}{\d t^2} ϕ(t)\] 25 | $⇒$ DGL 2. Ordnung 26 | \[\frac{\d^2}{\d t^2} ϕ(t) = - \frac{g}{l} \sin ϕ(t) \quad t \geq 0\] 27 | Für eindeutige Lösung braucht man zwei Anfangsbedingungen: 28 | \[ϕ(0) = ϕ_0\quad \dd{}{t}ϕ(0) = u_0\] 29 | Lösung bei kleiner Auslenkung: Linearisiere um $ϕ = 0$ 30 | \begin{gather*} 31 | \sin ϕ = ϕ - \frac{1}{3!} ϕ^3 + \dots \approx ϕ \\ 32 | ⇒ \frac{\d^2}{\d t^2} ϕ(t) = -\frac{g}{l}ϕ(t) 33 | \end{gather*} 34 | Für $u_0 = 0$ findet man mit dem Ansatz $ϕ(t) = A \cos(ω t)$: 35 | \[-ω^2 A \cos (ω t) = -\frac{g}{l} A \cos (ω t)\] 36 | die Lösung: 37 | \[ϕ(t) = ϕ_0\cos(\sqrt{\frac{g}{l}}t)\] 38 | Fehlerquelle: Abschneidefehler. \\ 39 | Numerische Lösung: \\ 40 | Setze $u(t) := \dd{}{t} ϕ(t)$ 41 | \[\dd{}{t} \cvec{ϕ; u} = \cvec{u; - \frac{g}{l}\sin(ϕ)}\] 42 | Approximation mit Differenzenquotienten 43 | \[\cvec{u(t); -\frac{g}{l}\sin{ϕ(t)}} = \dd{}{t} \cvec{ϕ; u} = \lim_{Δt \to 0} \frac{1}{Δt}\cvec{ϕ(t + Δt) - ϕ(t); u(t + Δt) - u(t)} \approx \underarrow[\frac{1}{Δt}]{> 0, klein} \cvec{ϕ(t + Δt) - ϕ(t); u(t + Δt) - u(t)}\] 44 | Fehlerquelle: Diskretisierungsfehler \\ 45 | Auf Gitter $t_n = n Δt$ mit Werten $ϕ_n = ϕ(n Δt), u_n = u(n Δt)$: 46 | \[ϕ_{n + 1} = ϕ_n + Δt u_n, u_{n + 1} = u_n - Δt \frac{g}{l}ϕ_n\] 47 | Kleinerer Diskretisierungsfehler mit zentralen Differenzen: 48 | \[-\frac{g}{l} \sinϕ(t) = \frac{\d^2}{\d t^2} ϕ(t) \approx \frac{ϕ(t + Δt) - 2ϕ(t) + ϕ(t - Δt)}{Δt^2}\] 49 | Rekursionsformel: 50 | \[ϕ_{n + 1} = 2ϕ_n - ϕ_{n - 1} - Δt^2 \frac{g}{l}\sin ϕ_n, n\geq 1\] 51 | mit $ϕ_1 = ϕ_0 + Δt n_0$ (Expliziter Euler) \\ 52 | Letzte Fehlerquelle: Rundungsfehler 53 | #+end_ex 54 | -------------------------------------------------------------------------------- /numerik/tutorial/blatt01.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# PA Ermittlung der Maschienengenauigkeit" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "def get_eps(basis):\n", 19 | " eps = 1\n", 20 | " while 1 + eps != 1:\n", 21 | " eps /= basis\n", 22 | " return eps" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": { 29 | "collapsed": false 30 | }, 31 | "outputs": [ 32 | { 33 | "data": { 34 | "text/plain": [ 35 | "1.1102230246251565e-16" 36 | ] 37 | }, 38 | "execution_count": 2, 39 | "metadata": {}, 40 | "output_type": "execute_result" 41 | } 42 | ], 43 | "source": [ 44 | "get_eps(2.0)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 3, 50 | "metadata": { 51 | "collapsed": false 52 | }, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "Decimal('1E-28')" 58 | ] 59 | }, 60 | "execution_count": 3, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "import decimal as dec\n", 67 | "# reset to default precision\n", 68 | "dec.getcontext().prec = 28\n", 69 | "get_eps(dec.Decimal(10))" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "Decimal hat als Basis 10.\n", 77 | "Die Mantissenlänge ist also 28." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "Decimal('1E-200')" 91 | ] 92 | }, 93 | "execution_count": 4, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "dec.getcontext().prec = 200\n", 100 | "get_eps(dec.Decimal(10))" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "Der Wert für prec ist offensichtlich die Mantissenlänge. Dadurch, das die Basis gleich 10 erhält man außerdem für die Genauigkeit eine ganze Anzahl von Nachkommastellen, anders als bei dem IEEE Format mit einer Basis von 2." 108 | ] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.5.3" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 2 132 | } 133 | -------------------------------------------------------------------------------- /numerik/tutorial/blatt01.org: -------------------------------------------------------------------------------- 1 | #+LANGUAGE: de 2 | #+OPTIONS: toc:nil 3 | #+AUTHOR: Robin Heinemann 4 | #+TITLE: Aufsatz: Motivation 5 | #+LATEX_HEADER: \usepackage[ngerman]{babel} 6 | #+LATEX_HEADER: \usepackage[no-math]{fontspec} 7 | #+LATEX_HEADER: \renewcommand{\baselinestretch}{1.5} 8 | Meine Motivation Numerik zu lernen ist stark mit meinem Studienfach, der Physik, verbunden. 9 | In der Physik sind nur die einfachsten Probleme überhaupt analytische lösbar. Wie in der ersten Vorlesung 10 | gezeigt wurde ist schon eines der simpelsten physikalischen Systeme, das Pendel nicht vollständig analytisch lösbar. 11 | Deswegen ist es für die Physik zwingend notwendig auf numerische Methoden / Simulationen zurückzugreifen. 12 | Selbst die Ursprünge der Numerik liegen in der Physik, genauer in Astronomischen Betrachtungen. 13 | Ich habe mich damit sogar schon selber beschäftigt, im Rahmen eines Jugend Forscht Projektes habe 14 | ich eine N-Körper-Simulation entwickelt um den Einfluss verschiedener Parameter, wie Geschwindigkeit- und Massenverteilung einzelner Partikel 15 | auf die Entwicklung von Protoplanetaren Scheiben zu untersuchen. Hierbei reichte es aufgrund der Problemgröße nicht aus 16 | einen naiven Ansatz zu wählen und alle $n^2$ Kräfte zu berechnen, sondern ein intelligenterer Ansatz, 17 | der die Gruppierung der einzelnen Partikel berücksichtigt war notwendig. Außerdem habe ich 18 | verschiedene numerische Integrationsverfahren, insbesondere auch symplektische Integrationsverfahren 19 | und deren besondere Eigenschaften, wie auch in der ersten Vorlesung demonstriert wurde. 20 | Dieses Projekt hat mein Interesse an der Numerik geweckt, da mir bewusst geworden ist, 21 | wie viel von der richtigen Wahl und Umsetzung der Numerischen Methode abhängt und wie wichtig 22 | die Numerik überhaupt für die Physik ist. \\ 23 | Später habe ich mich noch mit einem anderem Projekt beschäftigt, der Entwicklung einer 24 | passiven Schallbasierten Ortung. Auch dabei habe ich einiges aus der Numerik kennen gelernt. 25 | Als erster Schritt der Ortung muss das Signal mehrerer Mikrophone in seine einzelnen Frequenzen 26 | aufgespalten werden, dazu ist eine Fourier-Transformation notwendig. Den Kern der Ortung 27 | bildet ein Gleichungssystem, ähnlich dem einer GPS-Ortung, das gelöst werden muss. Anfangs habe ich probiert dieses Gleichungssystem analytisch zu lösen. Dies 28 | ist mir nur mit Hilfe eines CAS gelungen und die resultierende Formel war ausgedruckt 3 Seiten lang, für den 2D Fall. 29 | Auch den 3D Fall wollte ich analytisch lösen, allerdings war die analytische Lösung davon schon in Form einer Textdatei 140Mb groß. 30 | Deswegen bin in dazu übergegangen das Gleichungssystem numerisch mit der Newton-Methode zu lösen. 31 | Ein Vorteil davon war, das ich sehr leicht dazu übergehen konnte anstatt der minimal benötigten 4 32 | Mikrofone noch mehr zu verwenden, um das Ergebnis mit der Least-Squares-Methode noch weiter zu verbessern. 33 | Außerdem habe ich Methoden der Rückkopplung von Simulation und Experiment benutzt um für die Ortung 34 | lokal die Schallgeschwindigkeit zu bestimmen. \\ 35 | Durch diese beiden Projekte wurde mein Interesse an Numerik sehr verstärkt, denn Numerik ist 36 | nicht nur wichtig für die Physik, auch ein großer Teil unseres Alltags sähe ganz Anders aus 37 | ohne die Numerik. \\ 38 | Bei einem Praktikum beim Fraunhofer-Institut in Kassel, habe ich noch einen ganz anderen 39 | Teil die Numerik kennen gelernt, der Entwicklung von Reglern für Stromnetze. \\ 40 | Ich hoffe durch das Besuchen dieser Vorlesung noch mehr zu generellen numerischen Methoden zu erfahren. 41 | Insbesondere interessiert mich die Fehlerabschätzung, denn damit habe ich mich bis jetzt wenig befasst. 42 | Außerdem hoffe ich einige Methoden, die ich bereits kenne, wie die numerische Lösung eines 43 | Least-Squares-Problems noch tiefer und besser zu verstehen. Ein weiter interessantes Thema ist für mich 44 | die Stabilität von numerischen Verfahren, da ich damit selber einige Probleme hatte. Auch ist die Vorlesung 45 | Voraussetzung für einige weiterführende Vorlesungen, wie das numerische Lösen von Differentialgleichungen, 46 | die interessant in Bezug auf die Physik sind. Die Numerik spielt in großen Teilen der aktuellen 47 | Forschung der Physik eine so große Rolle, das jeder Physiker in den Grundzügen mit der Numerik vertraut 48 | sein sollte. 49 | -------------------------------------------------------------------------------- /numerik/tutorial/blatt03.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Robin Heinemann" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from math import sqrt\n", 17 | "from numpy import finfo\n", 18 | "\n", 19 | "def find_ns(a, b, c):\n", 20 | " # check for a == 0 to avoid division by zero\n", 21 | " if a == 0:\n", 22 | " if b == 0:\n", 23 | " if c == 0:\n", 24 | " return([-1.0, 0.0, 1.0])\n", 25 | " else:\n", 26 | " return([])\n", 27 | " # degenerates to a line\n", 28 | " else:\n", 29 | " return([-c / b])\n", 30 | " # less calculation needed if b == 0\n", 31 | " elif b == 0:\n", 32 | " if c == 0:\n", 33 | " return([0])\n", 34 | " q = c / a \n", 35 | " if q < 0:\n", 36 | " ns = sqrt(-q)\n", 37 | " return([-ns, ns])\n", 38 | " else:\n", 39 | " return([])\n", 40 | " else:\n", 41 | " q = c / a\n", 42 | " p = -b / a\n", 43 | " u = (p * p / 4) - q\n", 44 | " # has only complex solutions\n", 45 | " if u < 0:\n", 46 | " return([])\n", 47 | " w = sqrt(u)\n", 48 | " if p < 0:\n", 49 | " ns1 = p / 2 - w\n", 50 | " else:\n", 51 | " ns1 = p / 2 + w\n", 52 | " \n", 53 | " ns2 = q / ns1\n", 54 | " return([ns1, ns2])\n", 55 | "\n", 56 | "def polyval(a, b, c, x):\n", 57 | " return(c + x * (b + x * a))\n", 58 | "\n", 59 | "def polyval_dx(a, b, c, x):\n", 60 | " return(2 * a * x + b)\n", 61 | " \n", 62 | "def valid_ns(a, b, c, ns):\n", 63 | " if len(ns) == 3:\n", 64 | " return(a == 0 and b == 0 and c == 0)\n", 65 | " elif len(ns) == 2:\n", 66 | " return(abs(polyval(a, b, c, ns[0])) <= finfo(float).eps * \n", 67 | " abs(polyval_dx(a, b, c, ns[0]) * ns[0]) and\n", 68 | " abs(polyval(a, b, c, ns[1])) <= finfo(float).eps * \n", 69 | " abs(polyval_dx(a, b, c, ns[1]) * ns[1]))\n", 70 | " elif len(ns) == 1:\n", 71 | " return(abs(polyval(a, b, c, ns[0])) <= finfo(float).eps)\n", 72 | " else:\n", 73 | " return(True)" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 2, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "True: [0, 0, 0] [-1.0, 0.0, 1.0]\n", 86 | "True: [0, 0, 1] []\n", 87 | "True: [0, 1, 0] [0.0]\n", 88 | "True: [0, 2, 1] [-0.5]\n", 89 | "True: [2, 0, 0] [0]\n", 90 | "True: [2, 0, 1] []\n", 91 | "True: [2, 0, -4] [-1.4142135623730951, 1.4142135623730951]\n", 92 | "True: [4, 2, 0] [-0.5, -0.0]\n", 93 | "True: [1, 2, -3] [-3.0, 1.0]\n", 94 | "True: [1, 2, 1] [-1.0, -1.0]\n", 95 | "True: [1, 2, 2] []\n", 96 | "True: [-1, 0, 0] [0]\n", 97 | "True: [-1, 0, -1] []\n", 98 | "True: [-4, 0, 2] [-0.7071067811865476, 0.7071067811865476]\n", 99 | "True: [-1, 2, 0] [2.0, -0.0]\n", 100 | "True: [-4, 8, 12] [3.0, -1.0]\n", 101 | "True: [-1, 2, -1] [1.0, 1.0]\n", 102 | "True: [-1, 2, -5] []\n", 103 | "False: [2500000000.0, -100000.0, 1] [2.0000000227373677e-05, 1.9999999772626326e-05]\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "a = [0, 0, 0, 0, 2, 2, 2, 4, 1, 1, 1, -1, -1, -4, -1, -4, -1, -1, 2.5e9]\n", 109 | "b = [0, 0, 1, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 8, 2, 2, -1e5]\n", 110 | "c = [0, 1, 0, 1, 0, 1, -4, 0, -3, 1, 2, 0, -1 , 2, 0, 12, -1, -5, 1]\n", 111 | "\n", 112 | "for a, b, c in zip(a, b, c):\n", 113 | " ns = find_ns(a, b, c)\n", 114 | " print(\"%s: %s %s\" % (valid_ns(a, b, c, ns), [a, b, c], ns))\n" 115 | ] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.6.5" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 2 139 | } 140 | -------------------------------------------------------------------------------- /numerik/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pdfs=$(wget -qO- https://typo.iwr.uni-heidelberg.de/groups/mobocon/teaching/numerik-0-ss17/ | grep -o 'href=".*blatt.*pdf"') 3 | rm *.pdf 4 | 5 | for pdf in $pdfs 6 | do 7 | wget --content-disposition "https://typo.iwr.uni-heidelberg.de/$(sed 's/href="//g; s/"//g' <<< $pdf)" 8 | done 9 | find . -size 0 -delete 10 | -------------------------------------------------------------------------------- /theo1/overview.org: -------------------------------------------------------------------------------- 1 | * Semesterüberblick 2 | 1. Newtonsche Mechanik 3 | 2. Lagrange / Hamilton Mechanik / Statistik / Kontinua 4 | 3. Elektrodynamik / Spezielle Relativitätstheorie 5 | 4. Quantenmechanik 6 | 5. Thermodynamik / Quantenstatistik 7 | 6. Allgemeine Relativitätstheorie / Kosmologie 8 | 7. Quantenfeldtheorie I (ggf. 5.) 9 | 8. Quantenfeldtheorie II (ggf. 6. $\impliedby$ Stringtheorie / Teilchenphysik / Supersymmetrie) 10 | 9. Masterarbeit 11 | 10. Masterarbeit 12 | ** Mathe 13 | *wichtig:* 14 | - Gruppentheorie 15 | - Differientialgeometrie 16 | -------------------------------------------------------------------------------- /theo1/theo.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/theo1/theo.ora -------------------------------------------------------------------------------- /theo1/theo1.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/theo1/theo1.ora -------------------------------------------------------------------------------- /theo1/theo1.org: -------------------------------------------------------------------------------- 1 | #+AUTHOR: Robin Heinemann 2 | #+TITLE: Theoretische Physik I (Hebecker) 3 | 4 | # Einleitung: \\ 5 | # - Website: www.thphys.uni-heidelberg.de/hebecker/TP1/tp1.html 6 | # - Bartelman Skripte 7 | 8 | #+INCLUDE: "../header_de.org" :minlevel 1 9 | 10 | #+INCLUDE: "overview.org" :minlevel 1 11 | #+INCLUDE: "mass_points.org" :minlevel 1 12 | #+INCLUDE: "newton_mechanics.org" :minlevel 1 13 | #+INCLUDE: "conservation_laws.org" :minlevel 1 14 | #+INCLUDE: "harmonic_oscillator.org" :minlevel 1 15 | #+INCLUDE: "symmetries.org" :minlevel 1 16 | #+INCLUDE: "pseudo_forces.org" :minlevel 1 17 | #+INCLUDE: "central_forces.org" :minlevel 1 18 | #+INCLUDE: "collision.org" :minlevel 1 19 | #+INCLUDE: "expanded_gravitation.org" :minlevel 1 20 | -------------------------------------------------------------------------------- /theo1/tutorial/UB0.pdf_ignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/theo1/tutorial/UB0.pdf_ignore -------------------------------------------------------------------------------- /theo1/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/theo) --delete-after https://uebungen.physik.uni-heidelberg.de/uebungen/login.php 4 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://uebungen.physik.uni-heidelberg.de/uebungen/liste.php?vorl=683' | grep -o 'uebungen/download/.*pdf') 5 | 6 | for pdf in $pdfs 7 | do 8 | grep UB0.pdf <<< $pdf > /dev/null && continue; 9 | num=$(grep -o UB.*pdf <<< $pdf | sed 's/UB//g' | sed 's/\.pdf//g') 10 | wget --load-cookies cookies.txt -O UB$num.pdf "https://uebungen.physik.uni-heidelberg.de/$pdf" 11 | done 12 | -------------------------------------------------------------------------------- /theo2/hamilton.org: -------------------------------------------------------------------------------- 1 | * Hamilton-Formalismus 2 | Motivation: 3 | - nur 1. Ordnung Differentialgleichungen 4 | - $∃$ Umkehrung von Noether 5 | - Grundlegend für Quantenmachanik (für kanonische Quantisierung) 6 | ** Legendre-Transformation 7 | Gegeben: $f: ℝ \to ℝ, x ↦ f(x)$. Wollen "Information" in $f$ anders darstellen, zum Beispiel durch Funktion von $u \equiv f'(x)$. Man könnte zum Beispiel $x = x(u)$ definieren durch Auflösen von $u = f'(x)$. 8 | Dann könnte man $f = f(x(u))$ als transformierte Funktion auffassen. Das ist nur "fast" richtig. Mathematisch natürlicher ist 9 | \[g(u) = x(u) · u - f(x(u))\] 10 | #+ATTR_LATEX: :options [Legendre-Transformation] 11 | #+begin_defn latex 12 | Die Legendre-Transformation zu einer Funktion $x ↦ f(x)$ ist die Funktion $u ↦ g(u)$ mit 13 | \[g(u) = x u - f(x)\] wobei $x$ durch $u = f'(x)$ definiert ist. Wir wollen fordern, dass $f''(x) \neq 0$ damit $u = f'(x)$ auflösbar in $x$. 14 | #+end_defn 15 | Fakten: 16 | - $g'(u) = x(u)$, denn: 17 | \[g'(u) = \dd{}{u} x(u) u - f(x(u)) = \dots = x(u) + u \dd{x(u)}{u} - f'(x(u)) \dd{x(u)}{u} = x(u)\] 18 | - Wenn $g$ die Legendre-Transformation zu $f$ ist, dann sind $f', g'$ zueinander inverse Funktionen, denn: 19 | \[f'(g'(u)) = f'(x(u)) = u\] 20 | - $\Leg(\Leg(f)) = f$ (Legendre-Transformation ist eine Involution), denn: $f \xrightarrow{Leg.} g \xrightarrow{Leg.} h, h(z) = u z - g(u), z = g'(u)$. Wegen $g'(u) = x$ gilt $z = x$. Weiterhin: 21 | \[h(z) = u x - (x u - f(x)) = f(x) = f(z)\] 22 | Verallgemeinerung auf mehrere Variablen: $f: ℝ^n \to ℝ, \v x ↦ f(\v x)$ Legendre-Transformation: $g: ℝ^n \to ℝ, \v u ↦ g(\v u)$ 23 | #+ATTR_LATEX: :options [Legendre-Transformation mehrerer Variablen] 24 | #+begin_defn latex 25 | \[g(\v u) = \v x(\v u) \v u - f(\v x), \v u = \v ∇ f(\v x)\] 26 | Nebenbedingung: 27 | \[f'' \neq 0 ⇒ \det (\frac{\partial^2 f}{\partial x^i \partial x^j}) \neq 0\] 28 | #+end_defn 29 | #+begin_ex latex 30 | \begin{align*} 31 | f(x) &= x^2 \\ 32 | f'(x) &= 2x = u \\ 33 | x &= \frac{u}{2} \\ 34 | g(u) &= x u - f = \frac{u^2}{2} - (\frac{u}{2})^2 = \frac{u^2}{4} 35 | \end{align*} 36 | #+end_ex 37 | #+begin_ex latex 38 | \begin{align*} 39 | f(x) &= e^x \\ 40 | f'(x) &= e^x = x \\ 41 | x &= \ln u \\ 42 | g(u) &= x u - f = u \ln u - e^{\ln u} = u(\ln u - 1) 43 | \end{align*} 44 | #+end_ex 45 | ** Hamilton - Funkion 46 | Gegeben $L = L(q, \dot q, t)$. Die Hamilton - Funktion $H(q, p, t)$ ist die Legendre-Transformation zu $L$ in der Variablen $\dot q$. Also: 47 | \[H(q, p, t) \equiv p \dot q - L(q, \dot q, t)\] 48 | mit $\dot q = \dot q(q, p, t)$ gegeben durch: 49 | \[p \equiv \pp{L(q, \dot q, t)}{\dot q}\] 50 | "Der zu $q$ kanonische Impuls" 51 | #+ATTR_LATEX: :options [Eindimensional] 52 | #+begin_ex latex 53 | \begin{align*} 54 | L &= \frac{1}{2} f(q) \dot q^2 - V(q), p = f(q) \dot q \\ 55 | H &= p \dot q = p \frac{p}{f(q)} - \frac{1}{2} f(q) (\frac{p}{f(q)})^2 + V(q) = \frac{1}{2} \frac{p^2}{f(q)} + V(q) = T + V 56 | \end{align*} 57 | #+end_ex 58 | #+ATTR_LATEX: :options [Mehrdimensional] 59 | #+begin_ex latex 60 | \begin{align*} 61 | L &= L(q_1, \dots, q_n, \dot q_1, \dots, \dot q_n, t) \\ 62 | \intertext{Völlig analog folgt} 63 | H &= H(q_1, \dots, q_n, p_1, \dots, p_n) = \sum_{i = 1}^{n} p_i \dot q_i - L \\ 64 | \dot q_i &= \dot q_i (q_1, \dots, q_n, p_1, \dots, p_n, t) \\ 65 | p_i &= \pp{L(q_1, \dots, q_n, \dot q_1, \dots, \dot q_n, t)}{\dot q_i} \\ 66 | L &= T - V \\ 67 | H &= T + V 68 | \end{align*} 69 | #+end_ex 70 | ** Hamilton-Gleichungen und Phasenraum 71 | Eigenschaften der Legendre-Transformation: $\partial H / \partial p = \dot q$. Außerdem: 72 | \begin{align*} 73 | \pp{H}{q} &= \pp{}{q}\{p \dot q(q, p, t) - L(q, \dot q(q, p, t), t)\} \\ 74 | &= p \pp{\dot q}{q} - \pp{L}{q} - \pp{L}{\dot q} \pp{\dot q}{q} = - \pp{L}{q} = - \dd{}{t} \pp{L}{\dot q} = - \dot p 75 | \end{align*} 76 | Völlig analoge Rechnung: \\ 77 | $⇒$ Hamilton-Gleichung 78 | \begin{align*} 79 | \dot q_i &= \pp{H}{p_i} \\ 80 | \dot p_i &= -\pp{H}{q_i} 81 | \end{align*} 82 | Vergleich: 83 | 1. Lagrange - \(\{q_i\}\)- Lage im Konfigurationsraum, \(\{\dot q_i\}\)- momentane Geschwindigkeiten $⇒$ Zustand des Systems 84 | Bewegung: Differentialgleichungen 2. Ordnung 85 | 2. Hamilton - \(\{ξ_a\} \equiv \{q_i, p_i\}\)- Lage im Phasenraum $⇒$ Zustand des Systems 86 | Bewegung: Differentialgleichungen 1. Ordnung (2n Stück): $\dot ξ_a = f_a(ξ_1, \dots, ξ_{2n})$ 87 | Zur Intuition: 88 | \[H = \frac{p^2}{2 m} + V(q)\] 89 | Hamilton-Gleichungen: 90 | \[\dot q = \pp{H}{p} = \frac{p}{m}, \dot p = -\pp{H}{q} = -\pp{V}{q}\] 91 | Check: Leite 1. Gleichung ab: 92 | \[\ddot q = \frac{\dot p}{m}\] 93 | Setze in 2. Gleichung ein: 94 | \[m \ddot q = - \pp{V}{q}\] 95 | Veranschaulichung im Phasenraum: Betrachte Energieerhaltung: 96 | \[\frac{p^2}{2m} + V(q) = E = \const\] 97 | \[⇒ p = \pm \sqrt{2m(E - V(q))} \equiv p(q)\] 98 | $⇒$ Trajektiorie im Phasenraum. 99 | Allgemein: $-\pp{H}{q}$ und $\pp{H}{p}$ definieren an jedem Punkt des Phasenraumes einen Vektor ($\to$ TP1, 2.2/2.3) 100 | -------------------------------------------------------------------------------- /theo2/tutorial/fetch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget --save-cookies cookies.txt --keep-session-cookies --post-data $(cat /home/robin/study/lectures/secrets/theo) --delete-after https://uebungen.physik.uni-heidelberg.de/uebungen/login.php 4 | pdfs=$(wget --load-cookies cookies.txt -qO- 'https://uebungen.physik.uni-heidelberg.de/uebungen/liste.php?vorl=734' | grep -o 'uebungen/download/.*/.*pdf'"'") 5 | 6 | echo $pdfs 7 | 8 | for pdf in $pdfs 9 | do 10 | grep blatt0.pdf <<< $pdf > /dev/null && continue; 11 | num=$(grep -o blatt.*pdf <<< $pdf | sed 's/UB//g' | sed 's/\.pdf//g') 12 | echo $pdf 13 | wget --load-cookies cookies.txt -O $num.pdf "https://uebungen.physik.uni-heidelberg.de/$pdf" 14 | done 15 | -------------------------------------------------------------------------------- /theo3/tutorial/03.ora: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/theo3/tutorial/03.ora -------------------------------------------------------------------------------- /theo3/tutorial/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/theo3/tutorial/03.png -------------------------------------------------------------------------------- /tsp/tutorial/1.kra: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/1.kra -------------------------------------------------------------------------------- /tsp/tutorial/10.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/10.art -------------------------------------------------------------------------------- /tsp/tutorial/11.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/11.art -------------------------------------------------------------------------------- /tsp/tutorial/2.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/2.art -------------------------------------------------------------------------------- /tsp/tutorial/3.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/3.art -------------------------------------------------------------------------------- /tsp/tutorial/5.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/5.art -------------------------------------------------------------------------------- /tsp/tutorial/7.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/7.art -------------------------------------------------------------------------------- /tsp/tutorial/8.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/8.art -------------------------------------------------------------------------------- /tsp/tutorial/9.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/9.art -------------------------------------------------------------------------------- /tsp/tutorial/black.art: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hd-notes/notes/5343b75c9910f46257abac30e5b70e38bfb4f107/tsp/tutorial/black.art --------------------------------------------------------------------------------