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

second exercise

parent 45134172
No related branches found
No related tags found
No related merge requests found
......@@ -52,14 +52,20 @@ v = np.zeros(nt) # Speicherzuweisung für Geschwindigkeitarray
# Hier plotten wir die Ergebnisse der Integration
import matplotlib.pyplot as plt
# Analytische Lösung
v_ana = lambda t: a * t
import matplotlib.pyplot as plt
plt.ion() # Interaktives Plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
plt.plot(t,v,'.') # Punkt-Plot der numerische Lösung
plt.plot(t,v_ana(t),'-') # Linien-Plot der analytische Lösung
if not plt.fignum_exists(1):
plt.figure(1)
plt.title('Geshwindigkeit')
plt.xlabel('Zeit [s]')
plt.ylabel('v [m/s]')
plt.grid()
plt.plot(t,v_ana(t),'-') # Linien-Plot der analytische Lösung
plt.plot(t,v,'.--') # Punkt-Plot der numerische Lösung
plt.show() # Zeigt den Plot
......@@ -54,7 +54,7 @@ v = np.zeros(nt) # Speicherzuweisung für Geschwindigkeitarray
wallclk = time.time()
v[0] = v0
for i in range(nT - 1):
for i in range(nt - 1):
v[i+1] = v[i] + a * dt
print ('Elapsed', time.time() - wallclk)
......@@ -76,9 +76,17 @@ import matplotlib.pyplot as plt
# Analytische Lösung
v_ana = lambda t: a * t
import matplotlib.pyplot as plt
plt.ion() # Interaktives Plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
plt.plot(t,v,'.') # Punkt-Plot der numerische Lösung
plt.plot(t,v_ana(t),'-') # Linien-Plot der analytische Lösung
if not plt.fignum_exists(1):
plt.figure(1)
plt.title('Geshwindigkeit')
plt.xlabel('Zeit [s]')
plt.ylabel('v [m/s]')
plt.grid()
plt.plot(t,v_ana(t),'-') # Linien-Plot der analytische Lösung
plt.plot(t,v,'.--') # 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
import time
# Dies sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
a = -9.81 # Beschleunigung == Erdbeschleunigung [m/s^2]
v0 = 0.0 # Anfangsgeschwindigkeit [m/s]
y0 = 30 # Anfangshöhe [m]
t_end = 2.4 # Simulierte Dauer [s]
dt = 0.1 # Zeitschritt [s]
# Analytische Geschwindigkeit
v_ana = lambda t: v0 + a * t
# Hier wir weisen Speicher zu
t = np.arange(0, t_end + dt/2, dt) # Zeitwertarray
nt = len(t) # Anzahl der Zeitschritte
y = np.zeros(nt) # Speicherzuweisung für die Y-Koordinate
'''
Implementiere dein explizites Euler-Verfahren in den folgenden Zeilen
Erinnerung: Das explizite Euler-Verfahren, kurz erklärt:
a) Approximation der Ableitung
∂y y(t+dt) - y(t)
----(t) ~ ------------------- := v(t)
∂t dt
b) Aktualisierung der Unbekannten
y(t+dt) = y(t) + v(t) * dt
'''
# Gib hier deinen Code ein
# Hier plotten wir die Ergebnisse der Integration
# Analytische Lösung
y_ana = lambda t: y0 + v0*t + 0.5 * a * t**2
import matplotlib.pyplot as plt
plt.ion() # Interaktives Plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
if not plt.fignum_exists(2):
plt.figure(2)
plt.title('Y-Koordinate')
plt.xlabel('Zeit [s]')
plt.ylabel('y [m]')
plt.grid()
plt.plot(t,y_ana(t),'-') # Linien-Plot der analytische Lösung
plt.plot(t,y,'.--') # 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
import time
# Dies sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
a = -9.81 # Beschleunigung == Erdbeschleunigung [m/s^2]
v0 = 0.0 # Anfangsgeschwindigkeit [m/s]
y0 = 30 # Anfangshöhe [m]
t_end = 2.4 # Simulierte Dauer [s]
dt = 0.1 # Zeitschritt [s]
# Analytische Geschwindigkeit
v_ana = lambda t: v0 + a * t
# Hier wir weisen Speicher zu
t = np.arange(0, t_end + dt/2, dt) # Zeitwertarray
nt = len(t) # Anzahl der Zeitschritte
y = np.zeros(nt) # Speicherzuweisung für die Y-Koordinate
'''
Implementiere dein explizites Euler-Verfahren in den folgenden Zeilen
Erinnerung: Das explizite Euler-Verfahren, kurz erklärt:
a) Approximation der Ableitung
∂y y(t+dt) - y(t)
----(t) ~ ------------------- := v(t)
∂t dt
b) Aktualisierung der Unbekannten
y(t+dt) = y(t) + v(t) * dt
'''
# Gib hier deinen Code ein
''' Lösung: Schleife '''
wallclk = time.time()
y[0] = y0
for i in range(nt - 1):
y[i+1] = y[i] + v_ana(t[i]) * dt
print ('Elapsed', time.time() - wallclk)
# Hier plotten wir die Ergebnisse der Integration
# Analytische Lösung
y_ana = lambda t: y0 + v0*t + 0.5 * a * t**2
import matplotlib.pyplot as plt
plt.ion() # Interaktives Plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
if not plt.fignum_exists(2):
plt.figure(2)
plt.title('Y-Koordinate')
plt.xlabel('Zeit [s]')
plt.ylabel('y [m]')
plt.grid()
plt.plot(t,y_ana(t),'-') # Linien-Plot der analytische Lösung
plt.plot(t,y,'.--') # Punkt-Plot der numerische Lösung
plt.show() # Zeigt den Plot
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment