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

6.11.2017: Algorithmen: Differentialgleichungen

parent 5e7c8891
Branches
No related tags found
No related merge requests found
No preview for this file type
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this % Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>. % document. If not, see <http://creativecommons.org/licenses/>.
% README: Bibliotheken % README: Bibliotheken, Differentialgleichungen
\documentclass[10pt,t]{beamer} \documentclass[10pt,t]{beamer}
...@@ -898,6 +898,48 @@ ...@@ -898,6 +898,48 @@
\end{frame} \end{frame}
\setcounter{section}{4}
\section{Algorithmen}
\subsection{Differentialgleichungen}
\begin{frame}[fragile]
\showsection
\showsubsection
\vspace*{-2\bigskipamount}
\begin{picture}(0,0)
\put(8,-6.5){\includegraphics{pendulum.pdf}}
\end{picture}
\begin{eqnarray*}
\varphi'(t) &=& \omega(t) \\[\medskipamount]
\omega'(t) &=& -\frac{g}{l}\cdot\sin\varphi(t)\hspace*{7.1cm}
\end{eqnarray*}
\begin{itemize}
\item
Von Hand (analytisch):\\
Lösung raten (Ansatz), Parameter berechnen
\item
Mit Computer (numerisch):\\
Eulersches Polygonzugverfahren
\end{itemize}
\medskip
\begin{lstlisting}[gobble=0]
phi += dt * omega;
omega += - dt * g / l * sin (phi);
\end{lstlisting}
\pause
\bigskip
Praktikumsaufgabe: Basketball
\end{frame}
\nosectionnonumber{\inserttitle} \nosectionnonumber{\inserttitle}
\begin{frame} \begin{frame}
...@@ -927,6 +969,13 @@ ...@@ -927,6 +969,13 @@
\end{itemize} \end{itemize}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung} \item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\item[\textbf{5}] \textbf{Algorithmen} \item[\textbf{5}] \textbf{Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Differentialgleichungen
\color{black}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke} % \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
\item[\textbf{\dots}] \item[\textbf{\dots}]
\end{itemize} \end{itemize}
......
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
void init_opengl (int *argcp, char **argv, char *window_name)
{
glutInit (argcp, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (1024, 768);
glutCreateWindow (window_name);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (20.0, -1.33333, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
static GLfloat light0_position[] = { 1.0, 0.0, 1.0, 0.0 };
glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
}
void set_material_color (float r, float g, float b)
{
GLfloat color[] = { r, g, b };
glMaterialfv (GL_FRONT, GL_AMBIENT, color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, color);
}
extern void init_opengl (int *argcp, char **argv, char *window_name);
extern void set_material_color (float r, float g, float b);
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
phi += dt * omega;
omega += dt * (-g / l) * sin (phi);
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 1.0 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi = phi0;
double omega = omega0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 1.0, 0.8);
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, l, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += dt;
phi += dt * omega;
omega += dt * (-g / l) * phi;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 0.5 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi_with_sin = phi0;
double omega_with_sin= omega0;
double phi_without_sin = phi0;
double omega_without_sin= omega0;
void draw_pendulum (double phi)
{
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, 1.0, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glutSwapBuffers ();
}
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
draw_pendulum (phi_with_sin);
set_material_color (1.0, 0.8, 0.8);
draw_pendulum (phi_without_sin);
set_material_color (0.8, 1.0, 0.8);
double A = phi0;
double B = 0.5 * M_PI; /* 90° */
double phi_analytic = A * sin (sqrt (g / l) * t + B);
draw_pendulum (phi_analytic);
glFlush ();
}
void timer_handler (int value)
{
t += dt;
phi_with_sin += dt * omega_with_sin; /* geg. Differentialgleichung */
omega_with_sin += - dt * g / l * sin (phi_with_sin); /* geg. Differentialgleichung */
/* _ohne_ Kleinwinkelnäherung */
phi_without_sin += dt * omega_without_sin; /* geg. Differentialgleichung */
omega_without_sin += - dt * g / l * phi_without_sin; /* geg. Differentialgleichung */
/* _mit_ Kleinwinkelnäherung */
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutPostRedisplay ();
glutMainLoop ();
return 0;
}
../common/pendulum.pdf
\ No newline at end of file
...@@ -20,7 +20,7 @@ Vortragsfolien: ...@@ -20,7 +20,7 @@ Vortragsfolien:
* [09.10.2017: Einführung, Einführung in C (bis Schleifen)](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171009/hp-20171009.pdf) * [09.10.2017: Einführung, Einführung in C (bis Schleifen)](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171009/hp-20171009.pdf)
* [16.10.2017: Ergänzungen zu printf() und scanf(), Seiteneffekte, Funktionen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171016/hp-20171016.pdf) * [16.10.2017: Ergänzungen zu printf() und scanf(), Seiteneffekte, Funktionen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171016/hp-20171016.pdf)
* [23.10.2017: Zeiger, Arrays und Strings, Strukturen, Dateien und Fehlerbehandlung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171023/hp-20171023.pdf) * [23.10.2017: Zeiger, Arrays und Strings, Strukturen, Dateien und Fehlerbehandlung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171023/hp-20171023.pdf)
* [06.11.2017: Bibliotheken](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171106/hp-20171106.pdf) * [06.11.2017: Bibliotheken, Differentialgleichungen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171106/hp-20171106.pdf)
* [30.10.2017: Sonderveranstaltung: E-Mail Verschlüsselung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171030/verschluesselung-20171030.pdf) * [30.10.2017: Sonderveranstaltung: E-Mail Verschlüsselung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20171030/verschluesselung-20171030.pdf)
* [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/hp-slides-2017ws.pdf) * [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/hp-slides-2017ws.pdf)
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment