Skip to content
Snippets Groups Projects
Commit 1878ac95 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Praktikumsunterlagen 12.12.2019

parent 2548fb4c
No related branches found
No related tags found
No related merge requests found
File added
% hp-2019ws-p1.pdf - Labor Notes on Low-Level Programming
% Copyright (C) 2014, 2015, 2018, 2019 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Versuch 3, 12. und 19.12.2019: Weltraum-Simulation
\documentclass[a4paper]{article}
\usepackage{pgscript}
\usepackage{multicol}
%\usepackage{sfmath}
\sloppy
\raggedcolumns
\pagestyle{empty}
\addtolength{\textheight}{1cm}
\newcommand{\sep}{~$\cdot$~}
\newcommand{\mylicense}{CC-by-sa (Version 3.0) oder GNU GPL (Version 3 oder höher)}
\begin{document}
\makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill
\makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}}
\par\bigskip\bigskip
\begin{center}
\Large\textbf{Praktikumsversuch 3: Weltraum-Simulation}
\par\medskip
\normalsize Hardwarenahe Programmierung\sep
Wintersemester 2019/20\sep
Prof.~Dr.~Peter Gerwinski
\end{center}
Aufgabe: Schreiben Sie ein C-Programm,
das die Bahnen von mindestens 3 Massenpunkten unter Einfluß der Gravitation
simuliert und in bewegter Grafik darstellt.
\begin{multicols}{2}
\begin{itemize}
\item
Zwei Massenpunkte ("`Himmelskörper"') mit den Massen $m_i$ und $m_j$
an den Orten $\vec{r}_i$ und $\vec{r}_j$ ziehen einander an.
Diese Kraft heißt Gravitation. Sie hat den Betrag:
\begin{equation}
|\vec{F}_{ij}| = \frac{m_j\cdot m_i\cdot G}{|\vec{r}_j - \vec{r}_i|^2}
\end{equation}
Hierbei ist $G$ eine Konstante (Gravitationskonstante).
\item
Die auf einen Himmelskörper wirkende Gesamtkraft $\vec{F}_i$
ergibt sich als Summe der von allen anderen Himmelskörpern herrührenden
Gravitationskräfte:
\begin{equation}
\vec{F}_i = \sum_{j=0,\,j\ne i}^{N - 1} \vec{F}_{ij}
\end{equation}
\item
Die Gravitationskraft beschleunigt jeden Himmelskörper gemäß:
\begin{equation}
\vec{F_i} = m_i\cdot \vec{a_i}
\end{equation}
\item
Beispiel: Wir betrachten zwei Himmelskörper. Einer davon ("`Zentralgestirn"')
ruht im Zentrum ($\vec{r}_0 = 0$, $\vec{v}_0 = 0$)
und hat eine wesentlich größere Masse als der andere
("`Satellit"', $m_1 \ll m_0$). Mit geeignetem Anfangsort $\vec{r}_1$
und geeigneter Anfangsgeschwindigkeit $\vec{v}_1$ beschreibt dann
der Satellit eine elliptische Umlaufbahn um das Zentralgestirn.
\item
Wir rechnen in zwei Dimensionen $x$ und $y$.
\item
Für die Zerlegung einer Kraft $\vec{F}_{ij}$ in $x$- und $y$-Komponenten
benötigen Sie nur die Grundrechenarten und die Wurzelfunktion,
jedoch insbesondere \emph{keine} trigonometrischen Funktionen:
\begin{equation}
\vec{F}_{ij} = |\vec{F}_{ij}| \cdot \frac{\vec{r}_j - \vec{r}_i}{|\vec{r}_j - \vec{r}_i|}
\end{equation}
\columnbreak
\item
Die Wurzelfunktion \lstinline{sqrt()} finden Sie
in der Mathematik-Bibliothek.
Um diese zu nutzen, verwenden Sie \lstinline{#include <math.h>} im Quelltext,
und geben Sie beim \lstinline[style=cmd]{gcc}-Aufruf
\lstinline[style=cmd]{-lm} mit an.
\item
Für die Simulation betrachten wir das System in kurzen Zeitintervallen $dt$
und berechnen die Änderungen des Ortes $\vec{r}_i = (x_i,y_i)$
und der Geschwindigkeit $\vec{v}_i = (v_{xi},v_{yi})$ jedes Himmelskörpers
mit Hilfe des expliziten Eulerschen Polygonzugverfahrens.
\par
(Wer möchte, darf natürlich auch andere Verfahren anwenden,
beispielsweise das klassische Runge-Kutta-Verfahren 4.~Ordnung.)
\item
Für eine derartige Simulation
einschließlich ihrer Darstellung als bewegte Grafik
können Sie sich von dem Beispiel-Programm \gitfile{hp}{20191205}{gtk-16.c}
inspirieren lassen. (Compilieren mit:
\lstinline[style=cmd]{gcc}
\lstinline[style=cmd]{-Wall}
\lstinline[style=cmd]{-O}
\lstinline[style=cmd]{$(pkg-config}
\lstinline[style=cmd]{--cflags}
\lstinline[style=cmd]{--libs}
\lstinline[style=cmd]{gtk+-3.0)}
\lstinline[style=cmd]{gtk-16.c}
\lstinline[style=cmd]{-o}
\lstinline[style=cmd]{gtk-16})
\item
In einer \file{GTK+}-\lstinline{drawing_area}
liegt der Nullpunkt der Zeichnung oben links,
eine Längeneinheit entspricht einem Pixel,
und die $y$-Koordinate wächst nach unten.
Es empfiehlt sich, die Koordinaten so umzurechnen,
daß der Nullpunkt in der Mitte der Zeichnung liegt,
die Längeneinheit Ihrem persönlichen Geschmack entspricht
und die $y$-Koordinate nach oben wächst.
\item
Beispiel-Szenarien für 3 oder mehr Körper:
\vspace{-\smallskipamount}
\begin{itemize}\itemsep0pt
\item
Planet mit Mond umkreist Sonne
\item
Sonne mit mehreren Planeten, die sich gegenseitig beeinflussen
\item
zwei Sonnen umkreisen sich gegenseitig, Planet kreist drumherum
\item
Raumsonde besucht nacheinander mehrere Planeten
\end{itemize}
\end{itemize}
\bigskip
\strut\hfill\emph{Viel Erfolg!}\qquad\qquad
\end{multicols}
\vfill
\begingroup
\small
\setlength{\leftskip}{3cm}
Stand: 10.\ Dezember 2019
% Soweit nicht anders angegeben:\\
Copyright \copyright\ 2014, 2015, 2018, 2019\quad Peter Gerwinski\\
Lizenz: \mylicense
Sie können diese Praktikumsunterlagen einschließlich \LaTeX-Quelltext
% und Beispielprogramme\\
herunterladen unter:\\
\url{https://gitlab.cvh-server.de/pgerwinski/hp}
\endgroup
\end{document}
File added
File added
% pgscript.sty - LaTeX Settings for Lecture Notes
% Copyright (C) 2012, 2015, 2017, 2018 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\usepackage{amsfonts}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[british,german]{babel} % Yes, really "german" and not "ngerman".
\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird.
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{graphicx}
\usepackage{ifluatex}
\usepackage{xcolor}
\usepackage{enumerate}
\usepackage{ifthen}
%% Repair kerning: Automatically insert "\kern{-0.15em}" between "//" % (in URLs).
%% PG20151206: This seems unnecessary here. Maybe due to \sf?
%\ifluatex
%\directlua{
% local glyph = node.id ("glyph")
% local function my_kerning (head)
% for t in node.traverse (head) do
% if t.id == glyph and t.char == 47 then
% if t.next
% and t.next.next
% and t.next.next.id == glyph
% and t.next.next.char == 47 then
% local k = node.new ("kern")
% k.kern = tex.sp ("-0.15em")
% k.next = t.next
% k.prev = t
% t.next.prev = k
% t.next = k
% end
% end
% end
% node.kerning (head)
% end
% luatexbase.add_to_callback ("kerning", my_kerning, "URL kerning")
%}
%\fi
\definecolor{blendedblue}{rgb}{0.2,0.2,0.7}
\definecolor{darkgreen}{rgb}{0.0,0.3,0.0}
\definecolor{darkred}{rgb}{0.7,0.0,0.0}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\newcommand{\breath}{\bigskip\goodbreak}
\newcommand{\subsubsubsection}[1]{\breath\par\textbf{#1}\nopagebreak\par}
\newenvironment{experts}{\color{darkgrey}}{}
\newenvironment{whiteout}{\definecolor{darkgreen}{rgb}{1.0,1.0,1.0}%
\definecolor{darkred}{rgb}{1.0,1.0,1.0}%
\color{white}}{}
\newenvironment{hint}{%
\begin{quote}
\addtolength{\leftskip}{0.6cm}%
% \includegraphics[width=1cm]{Zeichen_101_-_Gefahrstelle,_StVO_1970.pdf}
\makebox(0,0)[r]{\includegraphics[width=1cm]{Zeichen_101_-_Gefahrstelle,_StVO_1970.pdf}\hspace*{0.5em}}%
% \hangindent 1.2cm
% \hangafter 2
\bfseries
% Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar
% Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar
% Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar
% Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar
\ignorespaces
}{%
\end{quote}
}
\urlstyle{sf}
\newcommand{\file}[1]{{\color{blendedblue}#1}}
\newcommand{\textarrow}{{\boldmath $\longrightarrow$}}
\newcommand{\arrowitem}{\item[\textarrow]}
\newcommand{\newterm}[1]{\emph{\color{darkgreen}#1}}
\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}
\newcommand{\solution}{\subsubsection*{Lösung}}
\newcounter{points}
\newcommand{\points}[1]{\ifthenelse{#1=1}{(1 Punkt)}{(#1 Punkte)}\addtocounter{points}{#1}}
\newcommand{\gitfile}[3]{\href{https://gitlab.cvh-server.de/pgerwinski/#1/raw/master/#2/#3}{\file{#3}}}
\usepackage{listings}
\lstset{basicstyle=\color{blendedblue},
language=C,
captionpos=b,
gobble=4,
xleftmargin=1em,
columns=fullflexible,
moredelim=**[is][\color{red}]{¡}{¿}}
\lstdefinestyle{numbered}{xleftmargin=2em,
numbers=left,
numberstyle=\footnotesize\color{gray}}
\lstdefinestyle{terminal}{basicstyle=\ttfamily\color{darkgreen},
language={},
columns=fixed,
moredelim=**[is][\color{darkred}]{¡}{¿},
moredelim=**[is][\color{blendedblue}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\lstdefinestyle{cmd}{basicstyle=\ttfamily\color{darkred},
language={},
columns=fixed,
moredelim=**[is][\color{darkgreen}]{¡}{¿},
moredelim=**[is][\color{blendedblue}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\setlength{\textwidth}{16.5cm}
\setlength{\textheight}{26.0cm}
\setlength{\hoffset}{-1.5cm}
\setlength{\voffset}{-3.0cm}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\medskipamount}
\setlength{\unitlength}{1cm}
% pgslides.sty - LaTeX Settings for Lecture Slides
% Copyright (C) 2012, 2013 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\usepackage{amsfonts}
\usepackage[british,german]{babel} % Yes, really "german" and not "ngerman".
\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird.
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{graphicx}
\usepackage{pstricks}
\hypersetup{colorlinks,allcolors=blue}
%% @@@ Not necessary for slides. Why???
%% Repair kerning: Automatically insert "\kern{-0.15em}" between "//" % (in URLs).
%\directlua{
% local glyph = node.id ("glyph")
% local function my_kerning (head)
% for t in node.traverse (head) do
% if t.id == glyph and t.char == 47 then
% if t.next
% and t.next.next
% and t.next.next.id == glyph
% and t.next.next.char == 47 then
% local k = node.new ("kern")
% k.kern = tex.sp ("-0.15em")
% k.next = t.next
% k.prev = t
% t.next.prev = k
% t.next = k
% end
% end
% end
% node.kerning (head)
% end
% luatexbase.add_to_callback ("kerning", my_kerning, "URL kerning")
%}
\usetheme{default}
\usefonttheme{structurebold}
\setbeamertemplate{navigation symbols}{}
\setbeamersize{text margin left = 0.3cm, text margin right = 0.2cm}
\setbeamertemplate{itemize item}{$\bullet$}
\setbeamertemplate{itemize subitem}{--}
\setbeamerfont{itemize/enumerate subbody}{size=\normalsize}
\setbeamerfont{itemize/enumerate subsubbody}{size=\normalsize}
\setbeamercolor{footline}{fg=gray}
\newcommand{\sep}{~$\cdot$~}
\newif\ifminimalistic
\minimalistictrue
\institute[Hochschule Bochum\sep CVH]{%
\makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill
\makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}}%
}
\setbeamertemplate{headline}{%
\leavevmode
\hbox to \textwidth{%
\ifminimalistic
\strut\hfill
\else
\rule{0pt}{5.7pt}%
\hspace*{8.55pt}\insertinstitute\hspace*{5.7pt}%
\raisebox{-30pt}{\rule{0pt}{1pt}}%
\fi
}%
\vskip0pt%
}
\iffalse
\setbeamertemplate{footline}{}
\else
\setbeamertemplate{footline}{%
\leavevmode
\hbox to \textwidth{%
\usebeamercolor{footline}%
\usebeamerfont{footline}%
\ifminimalistic
\strut\hfill
\else
\,\insertshorttitle\sep
\insertshortauthor\sep
\insertshortinstitute\sep
\insertshortdate\hfill
\fi
\insertframenumber/\inserttotalframenumber
%Folie\,\insertframenumber\sep Seite\,\insertpagenumber\,
}%
\vskip0pt%
}
\fi
\newcommand{\maketitleframe}{%
\ifminimalistic
\begin{frame}[t,plain]
\insertinstitute
\par\vfill
\begin{center}
{\LARGE\color{structure}\inserttitle\par}\bigskip\bigskip
{\large \insertauthor\par}\bigskip\medskip
\insertdate
\end{center}
\end{frame}
\else
\begin{frame}
\vfill
\begin{center}
{\LARGE\color{structure}\inserttitle\par}\bigskip\bigskip
{\large \insertauthor\par}\bigskip\medskip
\insertdate
\end{center}
\vfill
\end{frame}
\fi
}
\definecolor{medgreen}{rgb}{0.0,0.5,0.0}
\definecolor{darkgreen}{rgb}{0.0,0.3,0.0}
\definecolor{lightred}{rgb}{1.0,0.7,0.7}
\definecolor{medred}{rgb}{0.5,0.0,0.0}
\definecolor{bored}{rgb}{0.89,0.0,0.098}
\definecolor{lightgray}{rgb}{0.85,0.85,0.85}
\definecolor{orange}{rgb}{1.0,0.5,0.0}
\definecolor{darkgray}{rgb}{0.4,0.4,0.4}
\newenvironment{experts}{\color{darkgray}}{}
\usepackage{listings}
\lstset{basicstyle=\color{structure},
language=C,
captionpos=b,
gobble=4,
columns=fullflexible,
aboveskip=0pt,
belowskip=0pt,
moredelim=**[is][\color{structure}]{¡}{¿},
moredelim=**[is][\only<2->{\color{structure}}]{²}{¿},
moredelim=**[is][\only<3->{\color{structure}}]{³}{¿},
moredelim=**[is][\only<4->{\color{structure}}]{°}{¿},
moredelim=**[is][\only<5->{\color{structure}}]{¤}{¿},
moredelim=**[is][\only<6->{\color{structure}}]{¢}{¿},
moredelim=**[is][\only<7->{\color{structure}}]{æ}{¿},
moredelim=**[is][\only<8->{\color{structure}}]{ø}{¿}}
\lstdefinestyle{terminal}{basicstyle=\ttfamily\color{darkgreen},
language={},
columns=fixed,
moredelim=**[is][\color{red}]{¡}{¿},
moredelim=**[is][\color{blendedblue}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\lstdefinestyle{cmd}{basicstyle=\ttfamily\color{red},
language={},
gobble=2,
columns=fixed,
moredelim=**[is][\color{darkgreen}]{¡}{¿},
moredelim=**[is][\color{structure}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\lstdefinestyle{shy}{basicstyle=\color{lightgray}}
\setcounter{topnumber}{3}
\renewcommand\topfraction{0.7}
\setcounter{bottomnumber}{3}
\renewcommand\bottomfraction{0.7}
\setcounter{totalnumber}{5}
\renewcommand\textfraction{0.1}
\renewcommand\floatpagefraction{0.9}
\setlength{\unitlength}{1cm}
\newcommand{\protectfile}[1]{#1}
\urlstyle{sf}
\newcommand{\file}[1]{{\color{structure}\protectfile{#1}}}
\newcommand{\textarrow}{{\boldmath $\longrightarrow$}}
\newcommand{\arrowitem}{\item[\textarrow]}
\newcommand{\newterm}[1]{\emph{\color{darkgreen}#1}}
\newcommand{\BIGskip}{\vspace{1cm}}
\newcommand{\shy}{\color{lightgray}}
\newcommand{\hot}{\color{red}}
\newcommand{\shyhot}{\color{lightred}}
\newcommand{\sectionnonumber}[1]{\section{#1}\addtocounter{section}{-1}}
\def\showsectionnonumber{\hbox{\Large\color{structure}\bf
\vtop{\secname}\par}\bigskip}
\newcommand{\nosectionnonumber}[1]{\gdef\nosectionnonumbername{#1}}
\def\shownosectionnonumber{\hbox{\Large\color{structure}\bf
\vtop{\nosectionnonumbername}\par}\bigskip}
\def\showsection{\hbox{\Large\color{structure}\bf
\vtop{\hbox{\arabic{section}}}\kern1em%
\vtop{\secname}\par}\bigskip}
\newcommand{\subsectionnonumber}[1]{\subsection{#1}\addtocounter{subsection}{-1}}
\def\showsubsectionnonumber{{\large\color{structure}\bf\subsecname\par}\bigskip}
\def\showsubsection{\hbox{\large\color{structure}\bf
\vtop{\hbox{\arabic{section}.\arabic{subsection}}}\kern1em%
\vtop{\subsecname}\par}\bigskip}
\newcommand{\subsubsectionnonumber}[1]{\subsubsection{#1}\addtocounter{subsubsection}{-1}}
\def\showsubsubsectionnonumber{{\normalsize\color{structure}\bf\subsubsecname\par}\bigskip}
\def\showsubsubsection{\hbox{\normalsize\color{structure}\bf
\vtop{\hbox{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}}\kern1em%
\vtop{\subsubsecname}\par}\bigskip}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment