Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PhAI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scientific Computing and Engineering Group
Teaching
PhAI
Commits
31a0185a
Commit
31a0185a
authored
7 years ago
by
JuanPi Carbajal
Browse files
Options
Downloads
Patches
Plain Diff
Explicit euler exercise
parent
0f7b0cec
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler.py
+61
-0
61 additions, 0 deletions
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler.py
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler_loesung.py
+79
-0
79 additions, 0 deletions
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler_loesung.py
with
140 additions
and
0 deletions
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler.py
0 → 100644
+
61
−
0
View file @
31a0185a
'''
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
# Die sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
a
=
-
9.81
# Beschleunigung == Erdbeschleunigung [m/s^2]
v0
=
0.0
# Anfangsgeschwindigkeit [m/s]
T
=
3
# Simulierte Dauer [s]
dt
=
0.1
# Zeitschritt [s]
# Hier wir weisen Speicher zu
t
=
np
.
arange
(
0
,
T
+
dt
/
2
,
dt
)
# Zeitwertarray
nT
=
len
(
t
)
# Anzahl der Zeitschritte
v
=
np
.
zeros
(
nT
)
# Speicherzuweisung für Geschwindigkeitarray
'''
Implementiert deinen Explizite Euler-Verfahren in den folgenden Zeilen
Erinnerung: Das explizite Euler-Verfahren, kurz gesagt
a) Approximation der Ableitung
∂v v(t+dt) - v(t)
----(t) ~ ------------------- := a
∂t dt
b) Aktualisierung des Unbekannten
v(t+dt) = v(t) + a * dt
'''
# Gibt hier deinen Code ein
# Hier plotten wir die Ergebnisse der Integration
import
matplotlib.pyplot
as
plt
plt
.
ion
()
# interaktive plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
plt
.
plot
(
t
,
v
,
'
.-
'
)
# Punkt-Dash-Plot der Funktion
plt
.
show
()
# Zeigt den Plot
This diff is collapsed.
Click to expand it.
PhysikfuerInfaormatik_PhAI/python/ueb1_ExEuler_loesung.py
0 → 100644
+
79
−
0
View file @
31a0185a
'''
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
# Die sind die Problemparameter
# Du kannst verschiedene Werte ausprobieren!
a
=
-
9.81
# Beschleunigung == Erdbeschleunigung [m/s^2]
v0
=
0.0
# Anfangsgeschwindigkeit [m/s]
T
=
3
# Simulierte Dauer [s]
dt
=
0.1
# Zeitschritt [s]
# Hier wir weisen Speicher zu
t
=
np
.
arange
(
0
,
T
+
dt
/
2
,
dt
)
# Zeitwertarray
nT
=
len
(
t
)
# Anzahl der Zeitschritte
v
=
np
.
zeros
(
nT
)
# Speicherzuweisung für Geschwindigkeitarray
'''
Implementiert deinen Explizite Euler-Verfahren in den folgenden Zeilen
Erinnerung: Das explizite Euler-Verfahren, kurz gesagt
a) Approximation der Ableitung
∂v v(t+dt) - v(t)
----(t) ~ ------------------- := a
∂t dt
b) Aktualisierung des Unbekannten
v(t+dt) = v(t) + a * dt
'''
# Gibt hier deinen Code ein
'''
Lösung: Schleife
'''
wallclk
=
time
.
time
()
v
[
0
]
=
v0
for
i
in
range
(
nT
-
1
):
v
[
i
+
1
]
=
v
[
i
]
+
a
*
dt
print
(
'
Elapsed
'
,
time
.
time
()
-
wallclk
)
'''
Lösung: itertools
'''
from
itertools
import
accumulate
wallclk
=
time
.
time
()
dv
=
a
*
dt
step
=
lambda
v
,
dummy
:
v
+
dv
v_
=
np
.
array
(
list
(
accumulate
(
v
,
step
)))
print
(
'
Elapsed
'
,
time
.
time
()
-
wallclk
)
# Hier plotten wir die Ergebnisse der Integration
import
matplotlib.pyplot
as
plt
plt
.
ion
()
# interaktive plotten "on"
#plt.clf() # Diese Zeile auskommentieren, um den Plot zu leeren
plt
.
plot
(
t
,
v
,
'
.-
'
)
# Punkt-Dash-Plot der Funktion
plt
.
show
()
# Zeigt den Plot
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment