fixed page breaking of code and exercises

This commit is contained in:
2020-12-11 23:22:40 +01:00
parent 0380b7a96f
commit 0e30a01a45
13 changed files with 362 additions and 538 deletions

View File

@@ -204,7 +204,7 @@ random walk\footnote{A random walk is a simple simulation of Brownian
(listing \ref{chaoticcode}) then in cleaner way (listing
\ref{cleancode})
\begin{lstlisting}[label=chaoticcode, caption={Chaotic implementation of the random-walk.}]
\begin{pagelisting}[label=chaoticcode, caption={Chaotic implementation of the random-walk.}]
num_runs = 10; max_steps = 1000;
positions = zeros(max_steps, num_runs);
@@ -217,18 +217,15 @@ for step = 2:max_steps
x = randn(1);
if x<0
positions(step, run)= positions(step-1, run)+1;
elseif x>0
positions(step,run)=positions(step-1,run)-1;
end
end
end
\end{lstlisting}
\end{pagelisting}
\pagebreak[4]
\begin{lstlisting}[label=cleancode, caption={Clean implementation of the random-walk.}]
\begin{pagelisting}[label=cleancode, caption={Clean implementation of the random-walk.}]
num_runs = 10;
max_steps = 1000;
positions = zeros(max_steps, num_runs);
@@ -243,7 +240,7 @@ for run = 1:num_runs
end
end
end
\end{lstlisting}
\end{pagelisting}
\section{Using comments}
@@ -275,7 +272,6 @@ avoided:\\ \varcode{ x = x + 2; \% add two to x}\\
make it even clearer.}{Steve McConnell}
\end{important}
\pagebreak[4]
\section{Documenting functions}
All pre-defined \matlab{} functions begin with a comment block that
describes the purpose of the function, the required and optional
@@ -335,8 +331,7 @@ used within the context of another function \matlab{} allows to define
within the same file. Listing \ref{localfunctions} shows an example of
a local function definition.
\pagebreak[3]
\lstinputlisting[label=localfunctions, caption={Example for local
\pageinputlisting[label=localfunctions, caption={Example for local
functions.}]{calculateSines.m}
\emph{Local function} live in the same \entermde{m-File}{m-file} as