\chapter{Critical Evaluation}
This final chapter presents my evaluation of the project as a whole, outlines directions for future work in this area and provides a personal reflection on how I have handled and executed this project.

\section{Evaluation of the Project}
Overall this project has managed to answer some of the original questions laid out during the problem analysis and I feel that while the results of this project are not necessarily  as good as I was hoping for this has still been a fun project and excellent learning experience. I started this project with very minimal knowledge of image processing and analysis techniques (other than what had been taught in other university modules) and no knowledge of dimensionality reduction algorithms. I also started this project with very little prior knowledge of linear algebra, something which I would call a prerequisite for properly understanding many dimensionality reduction algorithms.

There were several goals that I set out to achieve as part of this project. This section will discuss them one by one and provide a review of what was achieved, what went well, and what went wrong.

The first goal was to generate image features from both real and synthetic mammogram images based on a variety of common techniques used with mammographic images. This required an extensive review of existing literature on the subject and the selection of a few techniques from each case to be used as part of the final system pipeline.

I feel that the features chosen for use in this project were entirely appropriate. I feel that starting with shape based features was a good idea and that the two techniques chosen produced reasonable results in practice. Blob features proved more complicated to implement than line features overall, but blob features end up producing better results and so I felt the extra effort involved was justified.

After extracting shape features I wanted to also try and focus on extracting other types of feature from the images. A difficult issue with this the time complexity required to extract more complicated features (i.e. texture features) from an image. For this reason I chose to use the patch of image defined by shape features as way narrow down the amount of processing required on each image. The reasoning behind this was that because a ROI has already been defined, extracting texture and intensity features from that region might be a good point to focus on.

In hindsight to this project I feel that I should have only focussed on an single type of image features (such as shape based). There were a lot of different pieces to this project outside of pure implementation and I think that I would of had a much more well-polished project had I narrowed the project scope.

My biggest regret with feature extraction is that I didn't realise until after the extracting texture and intensity features that the intensity distribution between real and synthetic images is very different, leading to the clear separation between the two datasets that can be viewed in all of the visualisations of these spaces. While this proved to be a disappointing result it does match with the some of the limitations proposed by the authors of the synthetic dataset in refs. \cite{bakic2002mammogram1, bakic2002mammogram2, bakic2003mammogram3}. In terms of the shape features, the synthetic mammograms at least appeared to be in the same space as their real counterparts but the extracted features were still unable to properly align the synthetics under projection according to their associated level of risk.

The second goal was to perform dimensionality reduction on the feature space generated by each of these techniques to produce two and three dimensional visual representations. A variety of different techniques were investigated as part of the initial stage of this project and a few fundamentally different approaches were selected to be used in the results of this project.

As I have briefly mentioning in the first paragraph of this section, one of the major challenges that I felt I faced with this project was trying fully understand the core principles and mathematics behind how dimensionality reduction algorithms worked. This was an area in which I had zero knowledge of before I began this project and subsequently I spent a significant proportion of the early part of the project researching how some of the more common techniques work along with the strengths and weaknesses of each.

There was very little technical effort involved with this component of the project. All of the techniques used in the project were already implemented as part of the scikit-learn python library. I felt that there was no need to reimplement complicated dimensionality reduction algorithms when they were already readily available in a well known and well tested package. I feel that the choice of dimensionality reduction techniques used was justified and that a small yet diverse mix of approaches were presented along with the results.

The third goal was to produce a way of evaluating the quality of the visualisations produced by dimensionality reduction. Once again this was investigated as part of the initial stage of the project and quality metrics derived from co-ranking matrices were eventually selected as the best choice due to the large number of measures that can be derived from them.

Again, like dimensionality reduction, this was an area that required more background reading than actual implementation. The implementation of the co-ranking matrix and the measures derived from it are actually only a few hundred lines of code, but understanding how the co-ranking matrix is derived and what the metrics subsequently derived from it measure took the majority of the effort. I felt that this was a justified approach to assess the quality of the mappings produced but that there was much more that could have been done in this area, for example in visualising the quality of the mapping in a similar way as suggested by Mokbel et al \cite{mokbel2013visualizing}.

The third aim was to integrate these separate components into an image analysis pipeline. This goal was achieved as part of a Python package produced during this project. While the implementation offered in this package is far from perfect I feel that it provides a good basic implementation of a image analysis pipeline. I feel that the most well developed part of the system is the feature extraction component. This provides reusable way to implement new feature detection routines through an interface that provides support for multiprocessing on a per image basis.

There are, however, some parts of the system I am not entirely happy with. The most notable of these is the section analysis module. This has mostly been developed on an ad-hoc basis depending on the functions I required to perform analysis. This module has ended up being a collection of the more common operations used when processing the features using IPython notebooks. It was particularly difficult deciding which functions to include in this module. The problem is that the operations you need to perform on the data largely depends on the patterns you see in the data itself. On one hand obviously not every single thing should be included, but on the other the aim of good software is to produce reusable components. Based on this I chose to work on the code in an IPython notebook and if I required the function in more than one place, move it into the analysis module.

The final aim of this project was to try and examine the difference between projections of the feature space of real and synthetic mammogram datasets. In this goal I feel that I have only been partially successful. While I feel that the results of the experiments performed allow us to draw some valid conclusions about the the differences between the two datasets I also feel that I could have spent more time constructing a better system to evaluate the results.

I feel that by far my most major weakness in the project was failing to full develop how to formally compare the feature spaces generated by the two datasets. Throughout the project my analysis of the dimensionality reduction was mostly based on visual examination of the mapping and trying to relate back to the original data. Looking at how images change across the lower dimensional embedding and trying to relate this to why the synthetics images show up as different works fine, but does not provide quantitive evaluation of how the feature spaces overlap.

I believe that this weakness was mostly caused by my own failure to plan this section of the project correctly ahead of time. This was the first research style project I have undertaken and in reflection I should have spent more time planning how to formally compare the two datasets. In reflection I feel that I perhaps jumped into development and implementation too soon without giving enough thought as to how to formally evaluate my results.

If I were to do this project again I would also be more rigorous in the approach to the generation of a visualisations produced in the results section. The parameters used by the dimensionality reduction algorithms were chosen ``by hand". If I were to continue with this project I would investigate a more rigorous approach for estimating the parameters used. Also, for the t-SNE projections I would create a framework where I could run the algorithm multiple times and then take the mapping which reports the lowest error rate (this wasn't trivial with the scikit-learn implementation as it doesn't expose the error to the API).

Another issue I feel hindered my method was having only a very small number of synthetics to work with. Even though I had a total of 60 different mammograms to play with, each group of ten images was effectively the same. This meant I had to use a random sample from each group and couldn't use the whole dataset. I think that it would have been easier to draw more valid statistical conclusions about the relationship between the two datasets had I had larger samples to work with.

In reflection on the choice of language used I feel that Python was an excellent choice for this project. The fact that Python is a very high level language but with the capability of producing decent performance when needed. The Scipy and Numpy libraries in particular saved me from having to reinvent the wheel on a lot of things. The general design of the language allowed me to work at a higher level compared to other languages. I found that I was easily able to focus on actually implementing what was required for the project than spending my time writing boilerplate code. Python's C API also came in handy as predicted. My implementation of the deformable convolution would have been much, much slower if it had been implemented in pure Python code.

My approach to the management of the project seemed to work reasonably well. The agile/XP based process I used in this project allowed me all of the flexibility I needed to work on what needed to be done rather than focussing on rigid requirements. As predicted I found that it really helped to be as flexible as possible about the project as new issues and challenges arose.

One thing that I found worked particularly well was the having a weekly iteration which was timed to start and finish with my weekly dissertation meeting. The discussion in these meetings allowed me to decide what ``stories" should be worked on throughout the week. During the first few iterations I tended to find that I would be overly ambitious about the number of tasks I could complete in a week. In the later iterations I found that this started to balance out more as I became more aware of how much I could feasibly achieve in a week.

I found the use of test driven development to be difficult to adhere to at times. I also often found it challenging to write decent tests for the software I was producing. Many of the functions in the package either return output that is difficult to evaluate for correctness. Another issue with testing was the fact that a number routines take a quite a long time to execute (i.e. greater than a minute per image). As this execution time makes it infeasible for unit testing I found that regression testing of the larger components of the system often proved to be more useful than the smaller unit tests. I did, however, find that both types of testing used in the project were extremely useful debugging the program, especially in the later stages of development as the system grew larger.

I also had a positive experience with using continuous integration throughout my project. My primary workflow involved doing most of my work on separate git branches and merging the finished work into the main branch upon completion. I found that it provided a useful safety net for checking if I broke something while working on code in two different branches in parallel.

Overall my time management on the project to be good, but demanding. I have often felt like I had too many choices and too many thing to do on the project. As suggested above I believe that I should have narrowed the scope of the project earlier one and then really focussed on the specifics of how to achieve this. By the nature of the project I wanted to be flexible and to investigate potentially interesting avenues as they occurred, but due to the time constraints of the project I found this lead to having too much choice on what to work on.

In conclusion I found this project to be a mostly enjoyable and rewarding experience. I found the most challenging and rewarding aspect to be trying to understand the concepts that I have been trying to make use. I strongly feel that while many of aspects of this project weren't a success I have learned a great deal how to better structure a research based project like this. I have also been left with a much stronger knowledge and personal interest in the image analysis and dimensionality reduction domains. If I were to replay this project I would first narrow the scope, then focus on fleshing out the specifics on the experiment much earlier on.

\section{Future Work}
\label{sec:future-work}
There are a multitude of ways in which this project could be extended. This section lists a few of the ways in which I believe the project could be expanded along with a discussion as to why I feel each point would be worth investigating.

One piece of additional work I would have liked to of investigated is to run the projections produced through a couple of common classifiers (such as, for example, a non-linear SVM). Alongside the quality metrics for visualisation, this would give me some raw numbers quantifying how well a classifier performs on the feature spaces produced by my implementations. While this would have little benefit to the projects main goals of examining the differences between synthetic and real feature spaces, it would have given me a better indication of how well features and projections separate mammograms based on class. This would have the additional advantage of providing a quantitive way of adjusting the parameters for the feature extraction and dimensionality reduction components of the system.

Another improvement I would have liked to have made to the system is to speed up the performance of the deformable convolution module. Currently this module provides a very slow implementation of the convolution operator. While this is necessarily slow around the edge of mask being convolved with the image because of the nature of modifying the kernel with every convolution, this does not need to be the case across the main portion of the image. For most of the breast two 1D second derivative Gaussian kernel in vertical and horizontal directions could be used and simply summed together to produce the same response but reducing the overall complexity. Another improvement that could be made here would be to wrap this module with better Numpy C API integration, something which I didn't have time to work on during this project.

I believe that the best feature used in this project was the multi-scale blob feature. I think that if I were to continue developing this project I would have experimented with making the linear structure feature multi-scale. I think that this feature misses some of the very small and very large scale linear structures because the algorithm has trouble detecting features across all scales with the same parameters (bins size, threshold etc.). For smaller lines the kernel proves to be too large and the line response does not show through strongly enough to avoid getting removed by thresholding. Likewise for larger lines the opposite is true; the response from the kernel in all directions appears uniform. Using this, duplicated lines detected across scales could be removed using a merging method like blob features, but it would obviously have to be more complicated because of the inconsistent size and shape of line features.

With regards to the visualisation aspect of this project I feel that there are several areas for further expansion. One method that captures my attention was a point wise measure of quality for lower dimensional mappings derived from the co-ranking matrix \cite{mokbel2013visualizing}. This can be used to colour the data points in a scatterplot of the lower dimensional mapping of a feature space. I feel that an approach based on a technique such as this would provide a much easier visual interpretation of the quality of the visualisation in comparison of the measures of trustworthiness, continuity, and LCMC.

During this project I have not focussed too much on the use of higher dimensional representations of the feature space. While these are often not as easy to interpret as a 2D or 3D scatterplot, they can provide useful additional insight. One thing which I would have liked to have tried in my project is to implement a method of ordering features according to their importance such as proposed by many methods listed in ref. \cite{bertini2011quality}. In particular my imagination was captured by the discussion of ordering parallel coordinates axes using the Hough transform \cite{tatu2009combining} and interactive feature selection by information loss \cite{johansson2009interactive}.

One aspect that I did not focus on much during the course of this project was ``topological" aspect in the project title. Mid way through the course of this project I began to read into the field of topological data analysis \cite{carlsson2009topology}. I think while this area is not necessarily directly related to examining the goals of this specific project it would be an area I feel would be worth examining. I think that exploring the topology of the mammographic feature space might yield some interesting relationships and I would be excited to explore this area further.


\documentclass[11pt,a4paper]{article}

% These are extra packages that you might need for writing the equations:
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{outlines}
\usepackage{mathtools}

\lstset {language=C++,
		 basicstyle=\ttfamily,
         keywordstyle=\color{blue}\ttfamily,
         stringstyle=\color{red}\ttfamily,
         commentstyle=\color{purple}\ttfamily,
         morecomment=[l][\color{magenta}]{\#},
       	 basicstyle=\tiny}

% You need the following package in order to include figures in your report:
\usepackage{graphicx}

% With this package you can set the size of the margins manually:
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\renewcommand{\vec}[1]{\mathbf{#1}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

\begin{document}

% Enter the exercise number, your name and date here:
\noindent\parbox{\linewidth}{
 \parbox{.25\linewidth}{ \large ICP, Exercise 13 }\hfill
 \parbox{.5\linewidth}{\begin{center} \large Beat Hubmann \end{center}}\hfill
 \parbox{.2\linewidth}{\begin{flushright} \large Dec 24, 2018 \end{flushright}}
}
\noindent\rule{\linewidth}{2pt}

\section{Introduction}

As a final exercise, the wave equation in one dimension gets treated by a finite difference method.

\section{Algorithm Description}
The second-order derivatives of the wave equation are approximated by a second-order central finite difference scheme.
Periodic boundary conditions are observed by adding a ghost position beyond both ends of the interval considered for the wave equation.

\section{Results}

The program was implemented as described above and submitted with this report. \\
The proposed Gaussian wave packet was found to move in the positive $x$ direction as expected.\\
For $b > 1$, the solution blows up, i.e. the numerical scheme becomes unstable as predicted by the CFL criterion.\\
A wave stationary for $t < 0$ was found to split in two packets moving in opposite directions. Figure~\ref{fig:1} shows the split shortly after $t=0$ for the same
Gaussian packet as above fixed in position for $t < 0$ .

\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.7]{fig_1.png}
\end{center}
\caption{Split of Gaussian wave packet stationary for $t<0$ seen shortly after $t=0$.}
\label{fig:1}
\end{figure}

\section{Discussion}
The results are as expected and are a lovely illustration of the strengths and weaknesses of simple numerical methods.
% \begin{thebibliography}{99}

% \bibitem{elman}
% Elman, H., Silvester, D., Wathen, A. \\
% \emph{Finite Elements and Fast Iterative Solvers},\\
% Oxford University Press,\\
% 2014.

% \bibitem{metropolis}
% Metropolis, N.,
% Rosenbluth, A.W.,
% Rosenbluth, M.N.,
% Teller, A.H.,
% Teller, E.\\
% \emph{Equations of State Calculations by Fast Computing Machines},\\
% Journal of Chemical Physics. 21 (6): 1087,\\
% 1953.

% \bibitem{herrmann}
% 	Herrmann, H. J.,
% 	Singer, H. M.,
% 	Mueller L.,
% 	Buchmann, M.-A.,\\
% 	\emph{Introduction to Computational Physics - Lecture Notes},\\
% 	ETH Zurich,\\
% 	2017.

% \bibitem{Gottschling}
% Gottschling, Peter\\
% \emph{Discovering Modern C++},\\
% Addison-Wesley,\\
% 2016.

% \end{thebibliography}

\end{document}


\documentclass[xcolor=dvipsnames]{beamer}
\input{style}

\title{Zeichnen mit TikZ}
\author{Dennis Labitzke}
%\institute{MetaNook}
\date{11.11.2016 -- MetaNook}

\setbeamerfont{frametitle}{size=\small}
\setbeamerfont{framesubtitle}{size=\tiny}

\newsavebox{\mycandle}
\savebox{\mycandle}{
\begin{tikzpicture}[scale=.1]
\shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.2) and (1,.5) .. (0,2) .. controls (-1,.5)  and  (-1,.2) .. (0,0);
\fill[yellow!90!black] (.8,0) rectangle (-.8,-5);
\end{tikzpicture} }
\tikzset{
  paint/.style={draw=#1!50!black, fill=#1!50},
  my star/.style={decorate,decoration={shape backgrounds,shape=star},
                  star points=#1}
}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}{Überblick}
\tableofcontents
\end{frame}

\section{Einführung}
\begin{frame}{Was ist TikZ?}
    \begin{itemize}
        \item
            TikZ ist kein Zeichenprogramm
        \item
            TikZ ist Makropaket zum Zeichnen von Grafiken mit \LaTeX
        \item
            TikZ verfügt über eine sehr ausführliche und gute Anleitung
    \end{itemize}
\end{frame}

\begin{frame}{Ein erstes Beispiel}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm,gray,very thin] (0,0) grid (1.4,1.4);
            \draw (1,0) arc (0:90:1cm);
            \draw[->] (0,0) -- (1.5,0) node[right] {$x$};
            \draw[->] (0,0) -- (0,1.5) node[above] {$y$};
            \draw (1,1pt) -- (1,-1pt) node[below] {$1$};
            \draw (1pt,1) -- (-1pt,1) node[left] {$1$};
            \filldraw[fill=green!20,draw=green!50!black]
                (0,0) -- (3mm,0pt) arc (0:30:3mm);
            \draw (15:2mm) node[green!50!black] {$\alpha$};
            \draw[very thick,red]
                (30:1cm) -- node[left]
                    {$\sin \alpha$} (30:1cm |- 0,0);
            \draw[very thick,blue]
                (0,0) -- node[below]
                    {$\cos \alpha$} (30:1cm |- 0,0);
            \path [name path=upward line]
                (1,0) -- (1,1);
            \path [name path=sloped line]
                (0,0) -- (30:1.5cm);
            \draw [name intersections=
                {of=upward line and sloped line, by=tan}]
                    [very thick,orange] (1,0) -- node [right]
                        {$\displaystyle \tan \alpha \color{black}=
                            \frac{{\color{red}\sin \alpha}}
                            {\color{blue}\cos \alpha}$} (tan);
            \draw (0,0) -- (tan);
        \end{tikzpicture}
    }
\end{frame}

\subsection{Verwendung}
\begin{frame}[fragile]{TikZ verwenden}
    \tikzexample{
        Wir beginnen mit
        \begin{tikzpicture}
            \draw (0,1) -- (0,0) -- (1,0);
        \end{tikzpicture}
        einem Winkel.
    }

    \begin{lstlisting}[gobble=8]
        \documentclass{scrartcl}
        \usepackage{tikz}
        \begin{document}
            Wir beginnen mit
            \begin{tikzpicture}
                \draw (0,1) -- (0,0) -- (1,0);
            \end{tikzpicture}
            einem Winkel.
        \end{document}
    \end{lstlisting}
\end{frame}

\subsection{Pfade}
\begin{frame}[fragile]{Pfade}
    \begin{itemize}
        \item
            Ein Pfad ist eine Folge von Koordinaten
            \begin{itemize}
                \item
                    Links unten ist der Ursprung $(0{,}0)$
                \item
                    Erste Koordinate: $x$-Richtung
                \item
                    Zweite Koordinate: $y$-Richtung
            \end{itemize}
        \item
            Linien zeichnen mit \lstinline{--}
        \item
            Relative Koordinaten beginnen mit  \lstinline{++}
    \end{itemize}

    \tikzexample{
        \begin{tikzpicture}
            \draw
                (0,0) -- ++ (1,0) ++ (0,1) -- ++ (-1,0)
                (2,0) rectangle (3,1);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}
            \draw (0,0) -- ++ (1,0) ++ (0,1) -- ++ (-1,0);
            \draw (2,0) rectangle (3,1);
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Gitterpfade}
    \tikzexample{
        \begin{tikzpicture}
            \draw [step=0.5cm] (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}
            \draw [step=0.5cm]
                (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Skalierung}
    \tikzexample{
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm] (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm]
                (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Stile}
    \tikzexample{
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm,gray,very thin] (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm,gray, very thin]
                (0,0) grid (1.4,1.4);
            \draw (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Pfeilspitzen}
    \tikzexample{
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm,gray,very thin] (0,0) grid (1.4,1.4);
            \draw [<->] (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm,gray, very thin]
                (0,0) grid (1.4,1.4);
            \draw [<->] (0,1.5) -- (0,0) -- (1.5,0);
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Bogenpfade}
    \tikzexample{
        \begin{tikzpicture}[scale=2]
            \draw [step=0.5cm,gray,very thin] (0,0) grid (1.4,1.4);
            \draw [<->] (0,1.5) -- (0,0) -- (1.5,0);
            \draw (1,0) arc (0:90:1cm) (3mm,0pt) arc (0:30:3mm);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \draw % 0 bis 90 Grad, Radius 1 cm
            (1,0) arc (0:90:1cm)
            % 0 bis 30 Grad, Radius 3 mm
            (3mm,0pt) arc (0:30:3mm);
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Farbig zeichnen}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \draw [green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \draw [green!50!black]
            (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Farbig füllen}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \fill [green!20] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \fill [green!20]
            (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Farbig zeichnen und füllen}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \filldraw [fill=green!20,draw=green!50!black]
            (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Polarkoordinaten und Schnittpunkte}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- (30:1cm |- 0,0);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \draw [very thick, red] (30:1cm) -- (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- (30:1cm |- 0,0);
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Schnittpunkte von Pfaden definieren}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- (30:1cm |- 0,0);

            \draw [name path=l1] (1,0) -- (1,1);
            \draw [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \draw [name path=l1] (1,0) -- (1,1);
            \draw [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Unsichtbare Pfade}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- (30:1cm |- 0,0);

            \path [name path=l1] (1,0) -- (1,1);
            \path [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \path [name path=l1] (1,0) -- (1,1);
            \path [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Schnittpunkte von Pfaden verwenden}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,0) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- (30:1cm |- 0,0);

            \path [name path=l1] (1,0) -- (1,1);
            \path [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];

            \draw [very thick, orange] (1,0) -- (tan);
            \draw (0,0) -- (tan);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \draw [very thick, orange] (1,0) -- (tan);
            \draw (0,0) -- (tan);
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Beschriftungen}
    \tikzexample{
        \begin{tikzpicture}[scale=3.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.1,.9);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \clip (0,-.1) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- node [left] {$\sin \alpha$} (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- node [below] {$\cos \alpha$} (30:1cm |- 0,0);

            \path [name path=l1] (1,0) -- (1,1);
            \path [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];

            \draw [very thick, orange] (1,0) -- (tan);
            \draw (0,0) -- (tan);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \draw [very thick, red] (30:1cm) --
                node [left] {$\sin \alpha$} (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) --
                node [below] {$\cos \alpha$} (30:1cm |- 0,0);
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Beschriftungen der Achsen}
    \tikzexample{
        \begin{tikzpicture}[scale=2.5]
            \draw [step=.5cm, very thin, gray] (0,0) grid (1.2,1.2);
            \filldraw [fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc (0:30:3mm) -- cycle;

            \draw[->] (0,0) -- (1.3,0) node[right] {$x$};
            \draw[->] (0,0) -- (0,1.2) node[above] {$y$};
            \draw (1,1pt) -- (1,-1pt) node[below] {$1$};
            \draw (1pt,1) -- (-1pt,1) node[left] {$1$};

            %\clip (0,-.1) rectangle (1.1,.9);
            \draw (1,0) arc (0:90:1cm);

            \draw [very thick, red] (30:1cm) -- node [left] {\footnotesize$\sin \alpha$} (30:1cm |- 0,0);
            \draw [very thick, blue] (0,0) -- node [below] {\footnotesize$\cos \alpha$} (30:1cm |- 0,0);

            \path [name path=l1] (1,0) -- (1,1);
            \path [name path=l2] (0,0) -- (30:1.5cm);
            \draw [name intersections={of=l1 and l2, by=tan}];

            \draw [very thick, orange] (1,0) -- (tan);
            \draw (0,0) -- (tan);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=12]
            \draw[->] (0,0) -- (1.5,0) node[right] {$x$};
            \draw[->] (0,0) -- (0,1.5) node[above] {$y$};
            \draw (1,1pt) -- (1,-1pt) node[below] {$1$};
            \draw (1pt,1) -- (-1pt,1) node[left] {$1$};
    \end{lstlisting}
\end{frame}

\section{Graphen}
\subsection{Knoten und Kanten}
\begin{frame}[fragile]{Knoten}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    \node at (0,4) {Eingabe $a,b$};
                    \node at (0,3) {$r = a \mod b$};
                    \node at (0,2) {$a=b, b=r$};
                    \node at (0,1) {$b=0?$};
                    \node at (0,0) {Ausgabe $a$};
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=12]
                \node at (0,4) {...};
                \node at (0,3) {...};
                \node at (0,2) {...};
                \node at (0,1) {...};
                \node at (0,0) {...};
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]{Knoten haben Stile}{Ein- und Ausgabe}
    \tikzexample{
        \begin{tikzpicture}
            [io/.style={trapezium,
                trapezium left angle=70,
                trapezium right angle=110,
                fill=magenta!10, draw=magenta}, thick]
            \node[io] {Eingabe $a,b$};
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}
            [io/.style={trapezium,
                trapezium left angle=70,
                trapezium right angle=110,
                fill=magenta!10, draw=magenta}, thick]
            \node[io] {Eingabe $a,b$};
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Knoten haben Stile}{Operationen}
    \tikzexample{
        \begin{tikzpicture}
            [op/.style={rectangle,
                fill=orange!10, draw=orange}, thick]
            \node[op] {$R = a \mod b$};
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}
            [op/.style={rectangle,
                fill=orange!10, draw=orange}, thick]
            \node[op] {$R = a \mod b$};
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Knoten haben Stile}{Entscheidungen}
    \tikzexample{
        \begin{tikzpicture}
            [cn/.style={diamond,
                aspect=2,
                fill=red!10, draw=red}, thick]
            \node[cn] {$b=0$};
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \begin{tikzpicture}
            [cn/.style={diamond,
                aspect=2,
                fill=red!10, draw=red}, thick]
            \node[cn] {$b=0$};
        \end{tikzpicture}
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Knoten haben Namen}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [io/.style={trapezium,
                        trapezium left angle=70,
                        trapezium right angle=110,
                        fill=magenta!10, draw=magenta},
                    op/.style={rectangle,
                        fill=orange!10, draw=orange},
                    cn/.style={diamond,
                        aspect=2,
                        fill=red!10, draw=red},
                    thick]

                    \node[io] at (0,4)
                        (in) {Eingabe $a,b$};
                    \node[op] at (0,3)
                        (div) {$r = a \mod b$};
                    \node[op] at (0,2)
                        (set) {$a=b, b=r$};
                    \node[cn] at (0,1)
                        (cond) {$b=0?$};
                    \node[io] at (0,0)
                        (out) {Ausgabe $a$};
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=16]
                \node[io] at (0,4)
                    (in) {Eingabe $a,b$};
                \node[op] at (0,3)
                    (div) {$r = a \mod b$};
                \node[op] at (0,2)
                    (set) {$a=b, b=r$};
                \node[cn] at (0,1)
                    (cond) {$b=0?$};
                \node[io] at (0,0)
                    (out) {Ausgabe $a$};
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]{Knoten relativ positionieren}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [io/.style={trapezium,
                        trapezium left angle=70,
                        trapezium right angle=110,
                        fill=magenta!10, draw=magenta},
                    op/.style={rectangle,
                        fill=orange!10, draw=orange},
                    cn/.style={diamond,
                        aspect=2,
                        fill=red!10, draw=red},
                    thick, node distance=.5cm]

                    \node[io] (in)
                        {Eingabe $a,b$};
                    \node[op, below=of in]
                        (div) {$r = a \mod b$};
                    \node[op, below=of div]
                        (set) {$a=b, b=r$};
                    \node[cn, below=of set]
                        (cond) {$b=0?$};
                    \node[io, below=of cond]
                        (out) {Ausgabe $a$};
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=16]
                \node[io]
                    (in) {Eingabe $a,b$};
                \node[op, below=of in]
                    (div) {$r = a \mod b$};
                \node[op, below=of div]
                    (set) {$a=b, b=r$};
                \node[cn, below=of set]
                    (cond) {$b=0?$};
                \node[io, below=of cond]
                    (out) {Ausgabe $a$};
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]{Kanten}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [io/.style={trapezium,
                        trapezium left angle=70,
                        trapezium right angle=110,
                        fill=magenta!10, draw=magenta},
                    op/.style={rectangle,
                        fill=orange!10, draw=orange},
                    cn/.style={diamond,
                        aspect=2,
                        fill=red!10, draw=red},
                    thick, node distance=.5cm]

                    \node[io] (in)
                        {Eingabe $a,b$};
                    \node[op, below=of in]
                        (div) {$r = a \mod b$};
                    \node[op, below=of div]
                        (set) {$a=b, b=r$};
                    \node[cn, below=of set]
                        (cond) {$b=0?$};
                    \node[io, below=of cond]
                        (out) {Ausgabe $a$};

                    \path[->]
                        (in)    edge (div)
                        (div)   edge (set)
                        (set)   edge (cond)
                        (cond)  edge (out);
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=16]
                \path[->]
                    (in)    edge (div)
                    (div)   edge (set)
                    (set)   edge (cond)
                    (cond)  edge (out);
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]{Ein Pfad um die Ecke}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [io/.style={trapezium,
                        trapezium left angle=70,
                        trapezium right angle=110,
                        fill=magenta!10, draw=magenta},
                    op/.style={rectangle,
                        fill=orange!10, draw=orange},
                    cn/.style={diamond,
                        aspect=2,
                        fill=red!10, draw=red},
                    thick, node distance=.5cm]

                    \node[io] (in)
                        {Eingabe $a,b$};
                    \node[op, below=of in]
                        (div) {$r = a \mod b$};
                    \node[op, below=of div]
                        (set) {$a=b, b=r$};
                    \node[cn, below=of set]
                        (cond) {$b=0?$};
                    \node[io, below=of cond]
                        (out) {Ausgabe $a$};

                    \path[->]
                        (in)    edge (div)
                        (div)   edge (set)
                        (set)   edge (cond)
                        (cond)  edge (out);

                    \draw[->]
                        (cond)  -- ++ (1.5,0)
                                |- (div);
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=16]
                \draw[->]
                    (cond)  -- ++ (1.5,0)
                            |- (div);
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]{Ein Pfad um die Ecke}
    \begin{columns}
        \begin{column}{.4\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [io/.style={trapezium,
                        trapezium left angle=70,
                        trapezium right angle=110,
                        fill=magenta!10, draw=magenta},
                    op/.style={rectangle,
                        fill=orange!10, draw=orange},
                    cn/.style={diamond,
                        aspect=2,
                        fill=red!10, draw=red},
                    thick, node distance=.5cm]

                    \node[io] (in)
                        {Eingabe $a,b$};
                    \node[op, below=of in]
                        (div) {$r = a \mod b$};
                    \node[op, below=of div]
                        (set) {$a=b, b=r$};
                    \node[cn, below=of set]
                        (cond) {$b=0?$};
                    \node[io, below=of cond]
                        (out) {Ausgabe $a$};

                    \path[->]
                        (in)    edge (div)
                        (div)   edge (set)
                        (set)   edge (cond);

                    \path[->]
                        (cond) edge
                            node[right] {Ja}
                                (out);
                    \draw[->]
                        (cond)  --
                            node[below] {Nein}
                                ++ (1.5,0) |- (div);
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.6\textwidth}
            \begin{lstlisting}[gobble=16]
                \path[->]
                    (cond) edge
                        node[right] {Ja}
                            (out);

                \draw[->] (cond)  --
                    node[below] {Nein}
                        ++ (1.5,0) |- (div);
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\subsection{Automaten}
\begin{frame}[fragile]
    \tikzexample{
        \begin{tikzpicture}
            % Platzhalter
            \draw[draw=red!5] (-2,-1) rectangle (4.5,1.7);

            \node[initial, state] (q0) {$q_0$};
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \node[initial, state] (q0) {$q_0$};
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
    \tikzexample{
        \begin{tikzpicture}
            % Platzhalter
            \draw[draw=red!5] (-2,-1) rectangle (4.5,1.7);

            \node[initial, state] (q0) {$q_0$};
            \node[state, right=of q0] (q1) {$q_1$};
            \path    (q0) edge[->] node[above] {0} (q1)
                    (q1) edge[->, loop above] node {0} ();
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \node[initial, state] (q0) {$q_0$};
        \node[state, right=of q0] (q1) {$q_1$};
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
        \path (q0)    edge[->] node[above] {0} (q1)
              (q1)    edge[->, loop above] node {0} ();
        (*@\vphantom{h}@*)
        (*@\vphantom{h}@*)
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
    \tikzexample{
        \begin{tikzpicture}
            % Platzhalter
            \draw[draw=red!5] (-2,-1) rectangle (4.5,1.7);

            \node[initial, state] (q0) {$q_0$};
            \node[state, accepting, right=of q1] (q2) {$q_2$};
            \node[state, right=of q0] (q1) {$q_1$};
            \path  (q0)  edge[->] node[above] {0} (q1)
                   (q1)  edge[->, loop above] node {0} ()
                         edge[->, bend left] node[above] {1} (q2)
                   (q2)  edge[->, bend left] node[below] {0} (q1);
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \node[initial, state] (q0) {$q_0$};
        \node[state, right=of q0] (q1) {$q_1$};
        \node[state, accepting, right=of q1] (q2) {$q_2$};
        (*@\vphantom{h}@*)
        \path (q0)    edge[->] node[above] {0} (q1)
              (q1)    edge[->, loop above] node {0} ()
                      edge[->, bend left] node[above] {1} (q2)
              (q2)    edge[->, bend left] node[below] {0} (q1);
    \end{lstlisting}
\end{frame}

\subsection{Bäume}
\begin{frame}[fragile]
    \begin{columns}
        \begin{column}{.45\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [
                        every node/.style={draw,circle,thick, minimum size=.75cm},
                        every path/.style={thick},
                        level 1/.style={sibling distance=2cm},
                        level 2/.style={sibling distance=1cm}
                    ]

                    % Platzhalter
                    \draw[draw=red!5] (-2,.5) rectangle (2,-4);

                    \node {a};
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.55\textwidth}
            \begin{lstlisting}[gobble=16]
                \node {a};
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \begin{columns}
        \begin{column}{.45\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [
                        every node/.style={draw,circle,thick, minimum size=.75cm},
                        every path/.style={thick},
                        level 1/.style={sibling distance=2cm},
                        level 2/.style={sibling distance=1cm}
                    ]

                    % Platzhalter
                    \draw[draw=red!5] (-2,.5) rectangle (2,-4);

                    \node {a}
                        child { node {b} };
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.55\textwidth}
            \begin{lstlisting}[gobble=16]
                \node {a}
                    child { node {b} };
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \begin{columns}
        \begin{column}{.45\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [
                        every node/.style={draw,circle,thick, minimum size=.75cm},
                        every path/.style={thick},
                        level 1/.style={sibling distance=2cm},
                        level 2/.style={sibling distance=1cm}
                    ]

                    % Platzhalter
                    \draw[draw=red!5] (-2,.5) rectangle (2,-4);

                    \node {a}
                        child { node {b}
                            child { node {c} }
                            child { node {d} }
                        };
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.55\textwidth}
            \begin{lstlisting}[gobble=16]
                \node {a}
                    child { node {b}
                        child { node {c} }
                        child { node {d} }
                    };
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \begin{columns}
        \begin{column}{.45\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [
                        every node/.style={draw,circle,thick, minimum size=.75cm},
                        every path/.style={thick},
                        level 1/.style={sibling distance=2cm},
                        level 2/.style={sibling distance=1cm}
                    ]

                    % Platzhalter
                    \draw[draw=red!5] (-2,.5) rectangle (2,-4);

                    \node {a}
                        child { node {b}
                            child { node {c} }
                            child { node {d} }
                        }
                        child { node {e} };
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.55\textwidth}
            \begin{lstlisting}[gobble=16]
                \node {a}
                    child { node {b}
                        child { node {c} }
                        child { node {d} }
                    }
                    child { node {e} };
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
                (*@\vphantom{h}@*)
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \begin{columns}
        \begin{column}{.45\textwidth}
            \tikzexample{
                \begin{tikzpicture}
                    [
                        every node/.style={draw,circle,thick, minimum size=.75cm},
                        every path/.style={thick},
                        level 1/.style={sibling distance=2cm},
                        level 2/.style={sibling distance=1cm}
                    ]

                    % Platzhalter
                    \draw[draw=red!5] (-2,.5) rectangle (2,-4);

                    \node {a}
                        child { node {b}
                            child { node {c} }
                            child { node {d} }
                        }
                        child { node {e}
                            child { node {f} }
                            child { node {g} }
                        };
                \end{tikzpicture}
            }
        \end{column}
        \begin{column}{.55\textwidth}
            \begin{lstlisting}[gobble=16]
                \node {a}
                    child { node {b}
                        child { node {c} }
                        child { node {d} }
                    }
                    child { node {e}
                        child { node {f} }
                        child { node {g} }
                    };
            \end{lstlisting}
        \end{column}
    \end{columns}
\end{frame}

\section{Fortgeschrittene Verwendung}
\subsection{Funktionen plotten}
\begin{frame}{Beispiel eines Funktionsplots}
    \tikzexample{
        \begin{tikzpicture}
            []

            \draw[very thin,gray] (0,-1.4) grid (4.9,3.4);

            \draw[->] (0,-1.5) -- (0,3.5) node[above] {$f(x)$};
            \foreach \y in {-1,...,3} {
                \draw (2pt,\y) -- ++ (-4pt,0) node[left] {$\y$};
            }
            \draw[->] (0,0) -- (5.5,0) node[right] {$x$};
            \foreach \x in {1,...,5} {
                \draw (\x,2pt) -- ++ (0,-4pt) node[below,fill=red!5] {$\x$};
            }

            \draw[domain=0:5,red] plot (\x,\x/3) node[right] {$f(x) = \frac{x}{3}$};
            \draw[domain=0:5,blue] plot (\x,{sin(\x r)}) node[right] {$f(x) = \sin x$};
            \draw[domain=0:5,orange] plot (\x,{exp(\x)/50}) node[right] {$f(x) = \frac{e^x}{50}$};
        \end{tikzpicture}
    }
\end{frame}

\begin{frame}[fragile]
    \tikzexample{
        \begin{tikzpicture}
            \draw[blue,domain=0:5] plot (\x,{sin(\x r)});
            \draw[orange,domain=0:4] plot (\x,{exp(\x)/50});
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \draw[blue,domain=0:5] plot (\x,{sin(\x r)});
        \draw[orange,domain=0:4] plot (\x,{exp(\x)/50});
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Koordinatensystem}
    \tikzexample{
        \begin{tikzpicture}
            \draw[very thin,gray] (0,-1.4) grid (4.9,1.4);
            \draw[->] (0,0) -- (5.2,0) node[right] {$x$};
            \draw[->] (0,-1.5) -- (0,1.5) node[above] {$f(x)$};

            \draw[blue,domain=0:5] plot (\x,{sin(\x r)});
            \draw[orange,domain=0:4] plot (\x,{exp(\x)/50});
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \draw[very thin,gray] (0,-1.4) grid (4.9,1.4);
        \draw[->] (0,0) -- (5.2,0) node[right] {$x$};
        \draw[->] (0,-1.5) -- (0,1.5) node[above] {$f(x)$};
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Beschriftung der Achsen}
    \tikzexample{
        \begin{tikzpicture}
            [
                scale=.75
            ]

            \draw[very thin,gray] (0,-1.4) grid (4.9,1.4);
            \draw[->] (0,0) -- (5.2,0) node[right] {$x$};
            \draw[->] (0,-1.5) -- (0,1.5) node[above] {$f(x)$};

            \foreach \x in {1,...,4}
                \draw (\x cm,2pt) -- (\x cm,-2pt)
                    node[below,fill=red!5] {$\x$};
            \foreach \y in {-1,...,1}
                \draw (2pt,\y cm) -- (-2pt,\y cm)
                    node[left,fill=red!5] {$\y$};

            \draw[blue,domain=0:5] plot (\x,{sin(\x r)});
            \draw[orange,domain=0:4] plot (\x,{exp(\x)/50});
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \foreach \x in {1,...,4}
            \draw (\x cm,2pt) -- (\x cm,-2pt)
                node[below,fill=white] {$\x$};
        \foreach \y in {-1,...,1}
            \draw (2pt,\y cm) -- (-2pt,\y cm)
                node[left,fill=white] {$\y$};
    \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Beschriftung der Graphen}
    \tikzexample{
        \begin{tikzpicture}
            \draw[very thin,gray] (0,-1.4) grid (4.9,1.4);
            \draw[->] (0,0) -- (5.2,0) node[right] {$x$};
            \draw[->] (0,-1.5) -- (0,1.5) node[above] {$f(x)$};

            \foreach \x in {1,...,4}
                \draw (\x cm,2pt) -- (\x cm,-2pt)
                    node[below,fill=red!5] {$\x$};
            \foreach \y in {-1,...,1}
                \draw (2pt,\y cm) -- (-2pt,\y cm)
                    node[left,fill=red!5] {$\y$};

            \draw[blue,domain=0:5] plot (\x,{sin(\x r)}) node[right,fill=red!5] {$f(x) = \sin x$};
            \draw[orange,domain=0:4] plot (\x,{exp(\x)/50}) node[right,fill=red!5] {$f(x) = \frac{e^x}{50}$};
        \end{tikzpicture}
    }

    \begin{lstlisting}[gobble=8]
        \draw[blue,domain=0:5] plot (\x,{sin(\x r)})
            node[right,fill=white] {$f(x) = \sin x$};
        \draw[orange,domain=0:4] plot (\x,{exp(\x)/50})
            node[right,fill=white] {$f(x) = \frac{e^x}{50}$};
    \end{lstlisting}
\end{frame}

\subsection{Weitere Beispiele}
\begin{frame}[shrink]{Computer science mindmap}{Autor: Till Tantau}
        \begin{tikzpicture}
        \path[mindmap,concept color=black,text=white]
    node[concept] {Computer Science}
    [clockwise from=0]
    child[concept color=green!50!black] {
      node[concept] {practical}
      [clockwise from=90]
      child { node[concept] {algorithms} }
      child { node[concept] {data structures} }
      child { node[concept] {pro\-gramming languages} }
      child { node[concept] {software engineer\-ing} }
    }
    child[concept color=blue] {
      node[concept] {applied}
      [clockwise from=-30]
      child { node[concept] {databases} }
      child { node[concept] {WWW} }
    }
    child[concept color=red] { node[concept] {technical} }
    child[concept color=orange] { node[concept] {theoretical} };
\end{tikzpicture}
\end{frame}

\begin{frame}{A family tree}{Autor: Stefan Kottwitz}
    \begin{tikzpicture}[
  man/.style={rectangle,draw,fill=blue!20},
  woman/.style={rectangle,draw,fill=red!20,rounded corners=.8ex},
  grandchild/.style={grow=down,xshift=1em,anchor=west,
    edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}},
  first/.style={level distance=6ex},
  second/.style={level distance=12ex},
  third/.style={level distance=18ex},
  level 1/.style={sibling distance=5em}]
    % Parents
    \coordinate
      child[grow=left] {node[man,anchor=east]{Jim}}
      child[grow=right] {node[woman,anchor=west]{Jane}}
      child[grow=down,level distance=0ex]
    [edge from parent fork down]
    % Children and grandchildren
    child{node[man] {Alfred}
      child[grandchild,first] {node[man]{Joe}}
      child[grandchild,second] {node[woman]{Heather}}
      child[grandchild,third] {node[woman] {Barbara}}}
    child{node[woman] {Berta}
      child[grandchild,first] {node[man]{Howard}}}
    child {node[man] {Charles}}
    child {node[woman]{Doris}
      child[grandchild,first] {node[man]{Nick}}
      child[grandchild,second] {node[woman]{Liz}}};
\end{tikzpicture}
\end{frame}

\begin{frame}[shrink]{Christmas tree with balls, candles and snowflakes}{Autor: Alain Matthes}
      \begin{tikzpicture}[  ball red/.style={
    decorate,
    decoration={
      markings,
      mark=between positions .2 and 1 step 3cm
      with
      {
        \pgfmathsetmacro{\sz}{2 + .5 * rand}
        \path[shading=ball,ball color=red] (0,0) circle[radius=\sz mm];
      }
    }
  } ,ball blue/.style={
    decorate,
    decoration={
      markings,
      mark=between positions 0.1 and .9 step 3cm
      with
      {
        \pgfmathsetmacro{\sz}{2 + .5 * rand}
        \path[shading=ball,ball color=blue] (0,0) circle[radius=\sz mm];
      }
    }
  }
]

\draw[fill=Maroon,ultra thick]
      (.75,-1)  ..  controls (.5,.5)  and   (.5,3)    .. (0.5,4)
   -- (-0.5,4)  ..  controls (-.5,3) and (-.5,.5)     .. (-.75,-1) ;
\draw[ultra thick,fill=green!50!black]
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7)
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25)
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2)
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4)
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25)
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ;

\foreach \candle in {(2,5),(-2,5),(0.5,7.5),(-0.5,7.5),(-3,2.5), (3,2.5),
                    (1.5,1.75),(-1.5,1.75)}
\node at \candle {\usebox{\mycandle}} ;
\node [star, star point height=.5cm, minimum size=.5cm,draw,fill=yellow,thick]
      at (0,10) {};
\begin{scope}[decoration={shape sep=.2cm, shape size=.25cm}]
    \draw [my star=6, paint=red]  (-4,2)
             ..  controls (0,2)     and   (1,3.5)   .. (1,4.40);
    \draw [my star=6, paint=red]  (-1.5,5.40)
             ..  controls (0,5.40)     and   (0.5,6.5)      .. (0.5,7);
    \draw [my star=6, paint=blue]  (4,2)
             ..  controls  (0,2) and (-1,3.5)      .. (-1,4.40);
    \draw [my star=6, paint=blue]  (1.5,5.40)
             ..  controls (0,5.40)     and   (-0.5,6.5)      .. (-0.5,7);
\end{scope}
% the balls
\path[ball red]
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7)
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25)
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2)
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4)
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25)
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ;
\path[ball blue]
      (0,10) .. controls  (0,8)     and   (1,7)    .. (1.5,7)
             ..  controls (1,7)     and   (1,7)    .. (0.5,7.25)
             ..  controls (1.5,5)   and   (2.5,4)  .. (3,4)
             ..  controls (2,4)     and   (1.25,4) .. (1,4.5)
             ..  controls (2,2)     and   (3.5,2)  .. (4,2)
             ..  controls (1,1)     and   (-1,1)   .. (-4,2)
             ..  controls (-3.5,2)  and   (-2,2)   .. (-1,4.5)
             ..  controls (-1.25,4) and   (-2,4)   .. (-3,4)
             ..  controls (-2.5,4)  and   (-1.5,5) .. (-0.5,7.25)
             ..  controls  (-1,7)   and   (-1,7)   .. (-1.5,7)
             ..  controls  (-1,7)   and   (0,8)    .. (0,10)
              ;
 % the snow
\foreach \i in {0.5,0.6,...,1.6}
     \fill [white!80!blue,decoration=Koch snowflake,opacity=.9]
           [shift={(rand*5,rnd*8)},scale=\i]
           [double copy shadow={opacity=0.2,shadow xshift=0pt,
           shadow yshift=3*\i pt,fill=white,draw=none}]
        decorate {
          decorate {
            decorate {
              (0,0) -- ++(60:1) -- ++(-60:1) -- cycle
            }
          }
        };
\end{tikzpicture}
\end{frame}

\begin{frame}[shrink]{Membrane-like surface}{Autor: Yotam Avital}
  \begin{tikzpicture}[scale=0.8]
    \def\nuPi{3.1459265}
    \foreach \i in {11,10,...,0}{% This one doesn't matter
      \foreach \j in {5,4,...,0}{% This will crate a membrane
                                 % with the front lipids visible
        % top layer
        \pgfmathsetmacro{\dx}{rand*0.1}% A random variance in the x coordinate
        \pgfmathsetmacro{\dy}{rand*0.1}% A random variance in the y coordinate,
                                       % gives a hight fill to the lipid
        \pgfmathsetmacro{\rot}{rand*0.1}% A random variance in the
                                        % molecule orientation
        \shade[ball color=red] ({\i+\dx+\rot},{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)}) circle(0.45);
        \shade[ball color=gray] (\i+\dx,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-0.9}) circle(0.45);
        \shade[ball color=gray] (\i+\dx-\rot,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-1.8}) circle(0.45);
        % bottom layer
        \pgfmathsetmacro{\dx}{rand*0.1}
        \pgfmathsetmacro{\dy}{rand*0.1}
        \pgfmathsetmacro{\rot}{rand*0.1}
        \shade[ball color=gray] (\i+\dx+\rot,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-2.8}) circle(0.45);
        \shade[ball color=gray] (\i+\dx,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-3.7}) circle(0.45);
        \shade[ball color=red] (\i+\dx-\rot,{0.5*\j+\dy+0.4*sin(\i*\nuPi*10)-4.6}) circle(0.45);
      }
    }
  \end{tikzpicture}
\end{frame}

\section{Zusammenfassung}
\begin{frame}{Zusammenfassung}
  \begin{enumerate}
    \item TikZ-Zeichnungen bestehen aus \alert{Pfaden}, die über \alert{Koordinaten} definiert werden.
    \item Fast alle schematischen Zeichnungen sind ein \alert{Graph}, bestehen also aus \alert{Knoten} und \alert{Kanten} und
      werden auch als solche in TikZ gezeichnet.
    \item TikZ ist sehr umfangreich und enthält \alert{sehr viele Bibliotheken}.
    \item Bei Problemen und Fragen \alert{lies die Anleitung!}
  \end{enumerate}
\end{frame}

\begin{frame}{Zum Weiterlesen}
  \begin{mybib}
    \bibitem{Tantau4}
      Till Tantau.
      \newblock \emph{The TikZ and pgf Packages},
      \newblock Manual for version 2.10,
      \newblock \alt<presentation>{\href{http://www.texample.net/media/pgf/builds/pgfmanualCVS2012-11-04.pdf}{\texttt{pgfmanual.pdf}}}{\url{http://www.texample.net/media/pgf/builds/pgfmanualCVS2012-11-04.pdf}}, November 2012.

    \bibitem{Texample}
      Kjell Magne Fauske und Stefan Kottwitz.
      \newblock \emph{\TeX ample.net},
      \newblock Sample resources for TeX users,
      \newblock \alt<presentation>{\href{http://www.texample.net/tikz/examples/}{\texttt{texample.net}}}{\url{http://www.texample.net/tikz/examples/}}.
  \end{mybib}
\end{frame}

\begin{frame}{GitHub -- Links}
\begin{itemize}
    \item Meine Dateien: \newline
    \url{https://github.com/labitzkedennis/Nook2016-TikZ}
    \item \LaTeX{} - Präsentationen mit Beamer von Anika Oellerich \newline
    \url{https://github.com/anioell/Nook-LaTeX-Beamer}
    \item Einführung in \LaTeX{} von Malte Schmitz\newline
    \url{https://github.com/malteschmitz/latex}
\end{itemize}
\end{frame}

\end{document}


\lab{Getting Started}{Getting Started}

The individual mandatory assignments (called ``labs'' in the following) in the second part of DM561 aim to introduce to applications of Linear Algebra and to train your Python programming skills. There will be weekly programming tasks for which you have to submit a solution.

\section*{Submitting Assignments} % ===========================================

\subsection*{Labs}

Every lab has a corresponding specifications file with some code to get you started and to make your submission compatible with automated test drivers. The template code will be provided via IMADA Git Server at \url{https://git.imada.sdu.dk}. How to proceed in detail will be described below.

To submit a lab, modify the provided specifications file and use \texttt{git} to submit your solution (discussed in the next section).
The submissions will be automatically graded.
For example, the first assignment (which will not be graded, and is just used to introduce you to the procedure of how you should submit your solutions and how your solution is graded) has the specifications file \texttt{asg0-onlytesting/onlytesting.py}.
To complete that assignment, provide your implementation in the file \texttt{asg0-onlytesting/asg0.py} and submit it via \texttt{git}.
After grading, you will be able to get access to a file called \texttt{asg0-onlytesting/grade.txt} with your score and some feedback. Each assignment will have a formal deadline. However we will provide testing results once every hour (at minute 00), such that you can improve your code. The grading will be based on your implementation at the exact time of the deadline of the assignment.

\begin{warn}
Do \textbf{not} move or rename the lab folders or the enclosed
specifications files; if you do, the test drivers will not be able to
find your assignment. Do \textbf{not} edit the file
\texttt{grade.txt}. This file is overwritten when you pull with git from
the remote server and must stay unchanged.
\end{warn}

\newpage
\section*{Setup} % ============================================================

\begin{warn}
We strongly recommend using a Unix-based operating system (Mac or Linux) for the labs.
Unix has a true bash terminal, works well with git and python, and is the preferred platform for computational and data scientists.
It is possible to do this curriculum with Windows, but expect some road bumps along the way. We will ensure that all the exercises can be solved in the IMADA Computer Lab. You can use your own environment, but you should not expect that we are able to answer your environment specific questions.
\end{warn}

Code has to be submitted using git.

\subsection*{Setup With Git} % ------------------------------------------------

\emph{Git} is a program that manages updates between an online code
repository and the copies of the repository, called \emph{clones},
stored locally on computers. Git is installed in the IMADA Computer
Lab. The instructions given below in this document should be enough for
the needs in this course. The tutorials linked below will provide much
more information than needed in this course. Nevertheless, git is an industry-standard collaboration tool, and being able to use it efficiently is an asset.

If you decide to use your own computer, and git is not already installed on your computer, you can download it at \url{http://git-scm.com/downloads} (or use the installation procedure of your specific system).
If you have never used git, you might want to read a few of the following resources.
\begin{itemize}
\item Official git tutorial: \url{https://git-scm.com/docs/gittutorial}
\item Bitbucket git tutorials: \url{https://www.atlassian.com/git/tutorials}
\item GitHub git cheat sheet: \href{https://education.github.com/git-cheat-sheet-education.pdf}{\texttt{https://education.github.com/github-git-cheat-sheet.pdf}}
\item GitLab git tutorial: \url{https://docs.gitlab.com/ce/gitlab-basics/start-using-git.html}
\item Codecademy git lesson: \url{https://www.codecademy.com/learn/learn-git}
\item Training video series by GitHub: \href{https://www.youtube.com/playlist?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-}{\texttt{https://www.youtube.com/playlist?list=PLg7.../}}
\end{itemize}

There are many websites for hosting online git repositories. IMADA has its own server for hosting git repositories  \url{https://git.imada.sdu.dk}. While not needed for submitting your code, you can login to the webpage using your university account name and the same password as you use for reading your mail or logging into blackboard. Choose as authentication source ``SDU''. See Fig.~\ref{fig:gogs} for an example. Via the webpage you will always be able to see the state of your code that will be used for auto-grading.

\begin{figure}
  \includegraphics[width=\textwidth]{gitea_login}
  \caption{IMADA Git Server (Gitea) login page}
  \label{fig:gogs}
\end{figure}

\begin{enumerate}

\item \emph{Clone your existing repository}.

  Usually, you have to create a repository. However, we already created a repository for each student of DM561. You will not have to create any repositories, but only clone it.

\item \emph{Connect your folder to the new repository}.
\label{step:connect-folder}\label{step:download-data}
In a shell application (Terminal on Linux or Mac, or Git Bash (\url{https://gitforwindows.org/} on Windows), enter the following commands (we will use the student with the username ``username'' as example, of course you have to change this).

\begin{lstlisting}
# Navigate to the folder where you want to store your files
$ <b<cd>b> /path/to/folder  # cd means 'change directory'.

# Make sure you are in the right place.
$ <b<pwd>b>                 # pwd means 'print working directory'.
/path/to/folder

# Clone the repository we provided

$ git clone https://git.imada.sdu.dk/DM561_2021/username-repo.git

Cloning into 'username-repo'...
Username for 'https://git.imada.sdu.dk': username
Password for 'https://username@git.imada.sdu.dk': ********
remote: Counting objects: 48, done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 48 (delta 16), reused 0 (delta 0)
Unpacking objects: 100% (48/48), done.
$ ls
username-repo

$ cd username-repo
$ ls -rtl
-rw------- 1 username username   66 Oct 31 19:48 README.md
-rw------- 1 username username  134 Oct 31 19:48 Info.md
drwx------ 2 username username 4096 Oct 31 19:48 asg0-onlytesting

# Record your credentials (has to be done once only).
$ git config --local user.name "Firstname Surname"
$ git config --local user.email "username@student.sdu.dk"
\end{lstlisting}

\item \emph{Install Python package dependencies}.
\label{step:install-dependencies}
Some of the labs require third-party Python packages that you might not have installed on your system. If they are missing you will see an error message similar to
\begin{lstlisting}
$ python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import matplotlib
ImportError: No module named matplotlib
\end{lstlisting}

You can easily install missing packages via

\begin{lstlisting}
$ pip3 install --user matplotlib
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/b2/58/5842588fa67b45ffb451c4c98eda283c0c42b8f2c5e503e4f6d9ff3c3a63/matplotlib-3.0.1-cp35-cp35m-manylinux1_x86_64.whl (12.9MB)
  [...]
  \end{lstlisting}

\end{enumerate}

%\subsection*{Setup Without Git} % ---------------------------------------------

Note, that you must have git installed in order to i.) get the data files for each lab and ii.) to submit you solution. Git is installed in the Computer Lab --- if you want to install it within your own environment, \url{http://git-scm.com/downloads} is a good starting point.

\section*{Using Git} % ========================================================

Git manages the history of a file system through \emph{commits}, or checkpoints.
Use \li{git status} to see the files that have been changed since the last commit.
These changes are then moved to the (local) \emph{staging area} (a list of files for the next commit) with \li{git add <filename(s)>}.
Record the changes in the staging area with the command \li{git commit -m "<A brief message describing the changes>"}.

All of these commands are done within a ``clone'' of the repository, which is stored somewhere on a computer.
This repository must be manually synchronized with the remote repository server via two other git commands: \li{git pull}, to pull updates from the web to the computer; and \li{git push}, to push updates from the computer to the git server.

In a nutshell, for the Labs in DM561 you usually have to modify one file only. This file first has to be added to the staging area, then it has to be commited, and then it has to be pushed to the remote server. In order to get the grading, you have to pull the corresponding file from the server after we tested your solution and created the grading file.

\begin{table}[H]
\begin{tabular}{l|l}
    Command & Explanation \\ \hline
    \li{git status} & Display the staging area and untracked changes. \\
    \li{git pull} & Pull changes from the online repository. \\
    \li{git push} & Push changes to the online repository. \\
    \li{git add <filename(s)>} & Add a file or files to the staging area. \\
    \li{git commit -m "<message>"} & Save the changes in the staging area with a given message. \\
\end{tabular}
\caption{Most common git commands needed for DM561.}
\end{table}

\begin{table}[H]
\begin{tabular}{l|l}
    Command & Explanation \\ \hline
    \li{git add -u} & Add all modified, tracked files to the staging area. \\
    \li{git checkout -- <filename>} & Revert changes to an unstaged file since the last commit. \\
    \li{git reset HEAD -- <filename>} & Remove a file from the staging area. \\
    \li{git diff <filename>} & See the changes to an unstaged file since the last commit. \\
    \li{git diff --cached <filename>} & See the changes to a staged file since the last commit. \\
    \li{git config --local <option>} & Record your credentials (\li{user.name}, \li{user.email}, etc.). \\
\end{tabular}
\caption{Some more git commands.}
\end{table}

\begin{info}
When pulling updates with \li{git pull origin master}, your terminal may sometimes display the following message.
\begin{lstlisting}
Merge branch 'master' of https://git.imada.sdu.dk/<name>/<repo> into master

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
~
~
\end{lstlisting}
This means that someone else (the grading system) has pushed a commit
(e.g., the file containing your grades) that you do not yet have, while
you have also made one or more commits locally that they (the grading system) do not have.
This screen, displayed in \emph{vim} (\url{https://en.wikipedia.org/wiki/Vim_(text_editor)}), is asking you to enter a message (or use the default message) to create a \emph{merge commit} that will reconcile both changes.
To close this screen and create the merge commit, type \li{:wq} and press \li{enter}.
\end{info}

% TODO: git staging area diagram.

\subsection*{Example Work Session}
Cloning and giving details on your name and email has only to be done once. The below work session assumes this has been done already.

Short version:
\begin{lstlisting}
$ <b<cd>b> ~/Desktop/Student-Materials/
$ git pull                                         # Pull updates.

# Make changes to a file (in this example onlytesting.py)

# Record the changes in git.
$ git add onlytesting.py                           # Track changes.
$ git commit -m "Made some changes."               # Commit changes.
$ git push                                         # Push updates.
\end{lstlisting}

Long version:
\begin{lstlisting}
# Navigate to the clone of the repository.
$ <b<cd>b> ~/Desktop/Student-Materials/

# Pull any updates from the online repository (such as preliminary feedback and grading), if they exist.

$ git pull

remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://git.imada.sdu.dk/DM561-2021/username-repo
   6dde06d..e24cee5  master     -> origin/master
Updating 6dde06d..e24cee5
Fast-forward
 asg0-onlytesting/grade.txt | 33 +++++----------------------------
 1 file changed, 5 insertions(+), 28 deletions(-)

# It seems someone graded your solution, and you would find the result in the file asg0-onlytesting/grade.txt

# Work on the labs. For example, modify asg0-onlytesting/onlytesting.py

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   asg0-onlytesting/onlytesting.py

no changes added to commit (use "git add" and/or "git commit -a")

$ git add asg0-onlytesting/onlytesting.py
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   asg0-onlytesting/onlytesting.py

# Commit the changes to the repository with an informative message.
$ git commit -m "Made some changes"
[master 72a5ab3] Made some changes
 1 file changed, 1 insertion(+)
<<[master fed9b34] Made some changes
 1 file changed, 10 insertion(+) 1 deletion(-)>>

# Push the changes to the online repository.
$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 373 bytes | 373.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To https://git.imada.sdu.dk/DM561-2021/username-repo.git
   e24cee5..72a5ab3  master -> master

# The changes have been saved and the online repository updated.
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
\end{lstlisting}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


%----------------------------------------------------------------------------------------
%	PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size

\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm,amssymb} % Math packages
\usepackage{mathrsfs}
\usepackage{algorithm, algorithmic}
\renewcommand{\algorithmicrequire}{\textbf{Input:}} %Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} %UseOutput in the format of Algorithm
\usepackage{listings}
\lstset{language=Matlab}
\usepackage{enumerate}
\usepackage{graphicx}

\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps
\usepackage{fancyhdr} % Custom headers and footers
\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers
\fancyhead{} % No page header - if you want one, create it in the same way as the footers below
\fancyfoot[L]{} % Empty left footer
\fancyfoot[C]{} % Empty center footer
\fancyfoot[R]{\thepage} % Page numbering for right footer
\renewcommand{\headrulewidth}{0pt} % Remove header underlines
\renewcommand{\footrulewidth}{0pt} % Remove footer underlines
\setlength{\headheight}{13.6pt} % Customize the height of the header

\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\title{
\normalfont \normalsize
\textsc{Shanghai Jiao Tong University, UM-SJTU JOINT INSTITUTE} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Introduction to Numerical Analysis \\ HW8 \\ % The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}

\author{Yu Cang \\ 018370210001} % Your name

\date{\normalsize \today} % Today's date or a custom date

\begin{document}

\maketitle % Print the title

\section{Question 1}
	\begin{enumerate}[(a)]
		\item
			It's convex as $f''(x) = e^x > 0$.
		\item
			Let
			\begin{equation}
				RHS \triangleq t f(x) + (1-t)f(y)
			\end{equation}
			\begin{equation}
				LHS \triangleq - f(tx+(1-t)y)
			\end{equation}
			It's concave as
			\begin{equation}
				\begin{aligned}
				  & RHS-LHS\\
						   = &[t x_1 x_2 + (1-t)y_1 y_2] -[t x_1 + (1-t)y_1][t x_2 + (1-t)y_2]\\
						   = &-t(1-t)(x_1 y_2 + x_2 y_1) < 0
				\end{aligned}
			\end{equation}
		\item
			Convex.

		\item
			Convex.

		\item
			Convex.

		\item
			Concave.

	\end{enumerate}

\section{Question 2}
	\begin{enumerate}[(a)]
		\item
			\begin{proof}
				Suppose $x = (x_1, x_2, ... , x_m)$, then it's left to prove that
				\begin{equation}
					\frac{\partial f}{\partial x_i} = 0
				\end{equation}
				for $i=1,2, ... , m$ at $x=x^*$.
			\end{proof}
			The partial derivative of $f$ at $x=x^*$ is defined as
			\begin{equation}
				\frac{\partial f}{\partial x_i}\Big|_{x=x^*} =
				\lim\limits_{\Delta x_i \rightarrow 0}\frac{f(x_1, x_2, ... ,x_i^* + \Delta x_i, ... , x_m) - f(x_1, x_2, ... ,x_i^*, ... , x_m)}{\Delta x_i}
			\end{equation}
			Since $f(x^*)$ is the local minimum, $f(x_1, x_2, ... ,x_i^* + \Delta x_i, ... , x_m) \geq f(x_1, x_2, ... ,x_i^*, ... , x_m)$ however $\Delta x_i$ changes.\\
			Thus
			\begin{equation}
				\frac{f(x_1, x_2, ... ,x_i^* + \Delta x_i, ... , x_m) - f(x_1, x_2, ... ,x_i^*, ... , x_m)}{\Delta x_i} \leq 0
			\end{equation}
			if $\Delta x_i < 0$.\\
			And
			\begin{equation}
				\frac{f(x_1, x_2, ... ,x_i^* + \Delta x_i, ... , x_m) - f(x_1, x_2, ... ,x_i^*, ... , x_m)}{\Delta x_i} \geq 0
			\end{equation}
			if $\Delta x_i > 0$.\\
			Hence, $\frac{\partial f}{\partial x_i}\Big|_{x=x^*} = 0$ as $f$ is continuously differentiable.
			Therefore, $\triangledown f(x^*) =0$.
		\item
			\begin{proof}
				With taylor expansion of $f(x)$ at $x=x^*$
				\begin{equation}
					\begin{aligned}
						  &f(x) - f(x^*) \geq 0 \quad \quad (\text{$f(x^*)$ is the local minimum})\\
		  \Leftrightarrow &\triangledown f(x^*) \Delta x + \frac{1}{2} \Delta \xi H(x^*) \Delta \xi ^T \geq 0\\
		  \Leftrightarrow &\frac{1}{2} \Delta \xi H(x^*) \Delta \xi ^T \geq 0 \quad \quad (\text{gradient be 0})
					\end{aligned}
				\end{equation}
				where $d(\Delta \xi, x^*) \leq d(x, x^*)$, and the gradient is $0$ as been proved above.
				Thus, $ \Delta \xi H(x^*) \Delta \xi ^T \geq 0$ for any $\Delta \xi$ within the local neighbourhood of $x=x^*$.\\
				Hence $H(x^*)$ is semi-positive finite.

			\end{proof}
		\item
			\begin{proof}
				($\Leftarrow$)The global minimum must be a local minimum, and the gradient is therefore 0 as $f$ is differentiable.

				($\Rightarrow$)As has been proved above, $\triangledown f(x^*)=0$ indicates that $f(x^*)$ is the local minimum. It's left to prove that local minimum is also global minimum for a convex function.
				Suppose there exist $x'$ s.t.
				\begin{equation}
					f(x') < f(x^*)
				\end{equation}
				Then, by convexity
				\begin{equation}
					f(t x' + (1-t)x^*) \leq t f(x') + (1-t) f(x^*) < \leq t f(x^*) + (1-t) f(x^*) = f(x^*)
				\end{equation}
				When $t\rightarrow1$, the inequality above contradicts local optimality of $x^*$.\\
				Thus, the assumption fails, which indicates that $f(x^*)$ is the global minimum for $f$.

			\end{proof}
		\item
			\begin{proof}
				($\Rightarrow$)By Taylor expansion
				\begin{equation}
					f(x+ d) = f(x) + \triangledown f(x) d + \frac{1}{2} d^T H(x) d + O(||d||^2)
				\end{equation}
				If the Hessian matrix $H$ is semi-definite positive, then
				\begin{equation}
					d^T H(x) d \geq 0
				\end{equation}
				Thus
				\begin{equation}
					f(x+ d) \geq f(x) + \triangledown f(x) d
				\end{equation}
				which is the so called 1-st order condition, and it implies that the function $f$ is convex.

				($\Leftarrow$)By Taylor expansion
				\begin{equation}
					f(x+ t d) = f(x) + t \triangledown f(x) d + \frac{t^2}{2} d^T H(x) d + O(||d||^2)
				\end{equation}
				With the 1-st order condition
				\begin{equation}
					f(x+ t d) \geq f(x) + t \triangledown f(x) d
				\end{equation}
				Thus
				\begin{equation}
					\frac{t^2}{2} d^T H(x) d + O(t||d||^2) \geq 0
				\end{equation}
				Dividing it by $\frac{t^2}{2}$ and set $t \rightarrow 0$, it gives out that for any $d\in \mathbb{R}^n$, $d^T H(x) d \geq 0$.

			\end{proof}

	\end{enumerate}

\section{Question 4}
	The genetic algorithm is adopted as there exists intensive oscillation when $x$ approaches $0$, and optimization algorithms dependent on the gradient info are easy to fall into local minimum.\\
	The global minimum found is $x_0=0.217, f(x_0)=-0.0249$.

\section{Question 6}
	The plot of $g(y)$ is given as follows
	\begin{figure}[!htbp]
		\centering
		\includegraphics[width=15cm]{../pic/Task6.eps}
	\end{figure}

\section{Question 7}
	According to the geometric relations, the allowable length of the ladder is given as
	\begin{equation}
		L(\alpha) = \min\limits_{\beta} (\frac{1}{sin(\beta)} + \frac{1}{sin(\alpha + \beta)})
	\end{equation}
	By solving the minimisation problem, the plot of $L$ versus $\alpha$ is given as follows
	\begin{figure}[!htbp]
		\centering
		\includegraphics[width=15cm]{../pic/Task7.eps}
	\end{figure}

\end{document}