Skip to content
Snippets Groups Projects
Commit 668e75ed authored by JuanPi Carbajal's avatar JuanPi Carbajal
Browse files

Exercises 03

parent dc1a95e7
No related branches found
No related tags found
No related merge requests found
Aufgabe 1
Zwei Autofahrer erblicken gleichzeitig ein Hindernis.
Am dieses Moment beide Autos sind am gleiche Abstand von der Hindernis.
Die Autofahrer und die Autos sind in allen relevanten Aspekten identisch, d.h. gleiche Reaktionszeit, Gewicht, Bremsverzögerung, usw.
Fahrer $\alpha$ fahrt mit eine Geschwindigkeit $v_{\alpha o}$ und er schafftes,
sein Auto genau vor dem Hindernis anzuhalten, d.h. $v(t_f)_\alpha = 0$ km/h.
Die Geschwindigkeit von Fahrer $\beta$ ist $v_{\beta o}$.
Was ist die Geschwindigkeit vom Fahrer $\beta$ ($v(t_f)_\beta$), wenn er der Hindernis erreicht?
Laden Sie den Programmcode via Moodle herunter und erfüllen Sie folgende Aufgaben.
\begin{itemize}
\item Ergänzen Sie \texttt{.py} und \texttt{.py}
\item Lösen Sie die Aufgabe mit $v_{\alpha o} = 120$ km/h und $v_{\beta o} = 180$ km/h
\item Plotten Sie die Endsgeschwindigkeit des Auto $\beta$ gegen seine Anfangsgeschwindigkeit.
Vergleichen Sie mit der Analytische Lösung.
\end{itemize}
Aufgabe 2
Beschleunigung $a(t) = -g + k v(t)^2$
Laden Sie den Programmcode via Moodle herunter und erfüllen Sie folgende Aufgaben.
\begin{itemize}
\item Plotten Sie Zeit bis zum Geschwindigkeit ähnlich der maximalen theoretischen Geschwindigkeit gegen Masse.
Vergleichen Sie mit der Analytische Lösung.
\item Plotten Sie Zeit $t_*$ bis zum $y(t_*) = 0$ gegen Masse.
Vergleichen Sie der vorheriges Ergebnis.
\end{itemize}
PhysikfuerInfaormatik_PhAI/img/autos.png

50 KiB

Source diff could not be displayed: it is too large. Options to address this: view the blob.
'''
Copyright (C) 2018 - Juan Pablo Carbajal
This program is free software; you can redistribute it and/or modify
it 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
'''
# Author: Juan Pablo Carbajal <juanpablo.carbajal@hs.ch>
import numpy as np
from scipy.optimize import newton
from integrator import ex_euler
kmh_ms = 1e3 / 3600 # Umrechnung km/h --> m/s
# Dies sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
v_a0 = 120 * kmh_ms # Anfangsgeschwindigkeit Auto alpha [m/s]
v_b0 = 180 * kmh_ms # Anfangsgeschwindigkeit Auto beta [m/s]
a_B = 5.0 # Bremsverzögerung [m/s^2]
t_H = v_a0 / a_B # Zeit bis zum Hindernis [s]
x_H, v_a, t_aend = ex_euler(t_H, x0=0, v0=v_a0, a=-a_B)
def func(t,v):
x,_,_ = ex_euler(t, x0=0, v0=v, a=-a_B)
return x_H - x
t_b = newton(lambda t: func(t,v_b0), t_H)
x_b, v_b, t_bend = ex_euler(t_b, x0=0, v0=v_b0, a=-a_B)
print('Endwerte:')
print(u'Auto \u03b1:\nZeit bis zum Hindernis: {t:.3f}, Koor: {x:.2f} m, Gesch: {v:.2f} km/h'.
format(t=t_aend, x=x_H,
v=v_a / kmh_ms))
print(u'Auto \u03b2:\nZeit bis zum Hindernis: {t:.3f}, Koor: {x:.2f} m, Gesch: {v:.2f} km/h'.
format(t=t_bend, x=x_b,
v=v_b / kmh_ms))
nv = 20
v_b0 = np.linspace(v_a0, 1.5*v_a0, nv)
v_b = np.zeros(nv)
for i,v0 in enumerate(v_b0):
t_b = newton(lambda t: func(t,v0), t_H)
x_b, v_, t_bend = ex_euler(t_b, x0=0, v0=v0, a=-a_B)
v_b[i] = v_
## Hier plotten wir die Ergebnisse
import matplotlib.pyplot as plt
## Analytische Lösung
v_ana = np.sqrt (v_b0**2 - v_a0**2)
import matplotlib.pyplot as plt
plt.ion() # Interaktives Plotten "on"
#plt.close(1) # Diese Zeile auskommentieren, um den Plot zu leeren
if not plt.fignum_exists(1):
plt.figure(1)
plt.title('Kollision Geshwindigkeit')
plt.xlabel('Anfangsgeshwindigkeit [km/h]')
plt.ylabel('Endgeshwindigkeit [km/h]')
plt.grid()
plt.plot(v_b0 / kmh_ms, v_ana / kmh_ms,'-') # Linien-Plot der analytische Lösung
plt.plot(v_b0 / kmh_ms, v_b / kmh_ms, '.--') # Punkt-Plot der numerische Lösung
plt.show() # Zeigt den Plot
'''
Copyright (C) 2018 - Juan Pablo Carbajal
This program is free software; you can redistribute it and/or modify
it 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
'''
# Author: Juan Pablo Carbajal <juanpablo.carbajal@hs.ch>
import numpy as np
from scipy.optimize import newton
from integrator import ex_euler
kmh_ms = 1e3 / 3600 # Umrechnung km/h --> m/s
# Dies sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
y0 = 20 # Anfangkoordinate [m]
g = 9.81 # Erdbeschleunigung [m/s^2]
A = 1 # Quer zur Srömung liegende Fläche [m^2]
rho = 1.2 # Luftdichte [kg / m^3]
c_W = 1.1 # Stärke des Luftwiderstands
m = 2.5 # Masse [kg]
k = 0.5 * A * rho * c_W / m # Luftwiederstandsfaktor [1/m]
a = lambda t,x,v: -g + k * v**2 # Beschleunigung [m/s^2]
v_max = np.sqrt(g / k)
t = 2;
y, v, t_end = ex_euler(t, y0, v0=0.0, a=a)
print('Endwerte:')
print('Koor: {y:.2f} m, Gesch: {v:.2f} km/h, Max Gesch: {vm:.2f} km/h'.
format(y=y,v=v / kmh_ms, vm=-v_max / kmh_ms))
faktor = 0.95 # Geschwindigkeitsverhältnis
def func(t):
_,vf,_ = ex_euler(t, y0, v0=0.0, a=a)
return faktor*v_max + vf
t_max = newton(func, 1)
y, v, t_end = ex_euler(t_max, y0, v0=0.0, a=a)
print('Werte @ {:.3f}:'.format(t_max))
print('Koor: {y:.2f} m, Gesch: {v:.2f} km/h, Max Gesch: {vm:.2f} km/h'.
format(y=y,v=v / kmh_ms, vm=-v_max / kmh_ms))
print('Geschwindigkeitsverhältnis: {r:.4f}'.format(r=-v/v_max))
'''
Copyright (C) 2018 - Juan Pablo Carbajal
This program is free software; you can redistribute it and/or modify
it 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
'''
# Author: Juan Pablo Carbajal <juanpablo.carbajal@hs.ch>
import numpy as np
from types import FunctionType
from copy import copy
def ex_euler(t, x0, v0, *, dt=1e-3, a=0.0):
'''Explizite Euler Integration für eine bestimmte Dauer
Eingabeargumente:
t (float): Zeitdauer
x0 (float): Anfangskoordinate
v0 (float): Anfangsgeschwindigkeit
Keyword Argumente:
dt (float): Zeitschritt
a (float, :obj:`function`): Beschleunigung
Wenn die eine Zahl (float) ist, die Beschleunigung ist eine Konstante.
Wenn die ein Funktion ist, die Rückgabewerts ist der
BeschleunigungwertSignatur für gegebene Zeit, Koordinate und
Geschwindigkeit, d.h. `a = func (t, x, v)`.
'''
if not isinstance(a, FunctionType):
a_val = copy(a)
a = lambda t, x, v: a_val
t_n = 0
v = v0
x = x0
while t_n+dt < t:
a_n = a(t_n, x, v)
x, v = ex_euler_schritt (x, v, a_n, dt)
t_n += dt
dt_end = t - t_n
if dt_end < dt:
a_n = a(t_n, x, v)
dt = t - t_n
x, v = ex_euler_schritt (x, v, a_n, dt)
t_n += dt
return x,v, t_n
def ex_euler_schritt(x, v, a, dt):
'''Ein Schritt des explizite Euler-Verfahren'''
x += v * dt
v += a * dt
return x, v
if __name__ == "__main__":
x0 = 10.0;
v0 = 0.0;
a = -9.81;
t_end = 1.0;
x,v,t = ex_euler(t_end, x0, v0, a=a)
print('Beispiel 1: Freie Fall')
print('Zeit: 0 s, Koor: {x} m, Gesch: {v} m/s'.format(x=x0,v=v0))
print('Zeit: {t:.2f} s, Koor: {x:.2f} m, Gesch: {v:.2f} m/s'.format(t=t,x=x,v=v))
x0 = 0.0;
v0 = 17.2;
a = -9.81;
t_end = 3.5;
dt = 1e-3
x,v,t = ex_euler(t_end, x0, v0, a=a, dt=dt)
print('Beispiel 2: Senkrechter Wurf')
print ('Zeit: 0 s, Koor: {x} m, Gesch: {v} m/s'.format(x=x0,v=v0))
print ('Zeit: {t:.2f} s, Koor: {x:.2f} m, Gesch: {v:.2f} m/s'.format(t=t,x=x,v=v))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment