weekly update
This commit is contained in:
parent
6be60df0a1
commit
50f9a1c0a2
@ -1,3 +1,4 @@
|
|||||||
|
#import "@preview/cetz:0.4.1"
|
||||||
#set math.mat(align: left)
|
#set math.mat(align: left)
|
||||||
|
|
||||||
== Differentialgleichungen
|
== Differentialgleichungen
|
||||||
@ -113,8 +114,24 @@ h^' (t) eq frac(Q_i, A) minus frac(A_a, A) dot root(, 2 dot g dot h)
|
|||||||
$
|
$
|
||||||
|
|
||||||
$ cases(
|
$ cases(
|
||||||
"OED: " h^' (t) &eq frac(Q_i, A) minus frac(A_a, A) dot root(, 2 dot g dot h) \
|
"OED: " h^' (t) &eq frac(Q_i, A) minus frac(A_a, A) dot root(, 2 dot g dot h),
|
||||||
"IC: " h(t_0) &eq h_0
|
"IC: " h(t_0) &eq h_0
|
||||||
) $
|
) $
|
||||||
|
|
||||||
|
=== Mechanik
|
||||||
|
#cetz.canvas({
|
||||||
|
import cetz.draw: *
|
||||||
|
rect((0, 0), (2, 1), )
|
||||||
|
line((0, 0.5), (-1.5, 0.5), mark: (end: ">"), fill: black, stroke: black)
|
||||||
|
line((2, 0.7), (3, 0.7), mark: (end: ">"), fill: black, stroke: black)
|
||||||
|
line((2, 0.3), (4, 0.3), mark: (end: ">"), fill: black, stroke: black)
|
||||||
|
content((1, 0.5), [Data])
|
||||||
|
content((-1, 0.9), [$F_1$], anchor: "west")
|
||||||
|
content((2.3, 1.1), [$F_2$], anchor: "west")
|
||||||
|
content((2.3, -0.1), [$F_n$], anchor: "west")
|
||||||
|
})
|
||||||
|
|
||||||
|
Newton-Aktionsprinzip $m dot a eq F eq F_1 plus F_2 plus ... plus F_n$ \
|
||||||
|
Fall 1: Geschwindigkeit $m dot v^' eq F_1(v) plus F_2(v) plus ... plus F_n (v)$ \
|
||||||
|
Fall 2: Weg $m dot s^'' eq F_1(s) plus F_2(s) plus ... plus F_n (s)$ \
|
||||||
|
Fall 3: Wrg und Geschwindigkeit $m dot s^'' eq F_1(s, s^') plus F_2(s, s^') plus ... plus F_n (s, s^')$ \
|
||||||
|
|||||||
@ -316,11 +316,17 @@ import cetz.draw: *
|
|||||||
})], [```typ
|
})], [```typ
|
||||||
content((0, 0), [1])
|
content((0, 0), [1])
|
||||||
content((0, -1), [Median = 4])
|
content((0, -1), [Median = 4])
|
||||||
|
content((0, -2), [$integral x dot "dt"$], anchor: "north-west")
|
||||||
|
- north
|
||||||
|
- south
|
||||||
|
- west
|
||||||
|
- east
|
||||||
```], [
|
```], [
|
||||||
#cetz.canvas({
|
#cetz.canvas({
|
||||||
import cetz.draw: *
|
import cetz.draw: *
|
||||||
content((0, 0), [1])
|
content((0, 0), [1])
|
||||||
content((0, -1), [Median = 4])
|
content((0, -1), [Median = 4])
|
||||||
|
content((0, -2), [$integral x dot "dt"$], anchor: "north-west")
|
||||||
})], [```typ
|
})], [```typ
|
||||||
|
|
||||||
```],[]
|
```],[]
|
||||||
|
|||||||
@ -116,6 +116,13 @@ if (x > 3){
|
|||||||
} else {
|
} else {
|
||||||
printf("x ist gleich 3 oder kleiner.");
|
printf("x ist gleich 3 oder kleiner.");
|
||||||
}
|
}
|
||||||
|
```],
|
||||||
|
[Short Hand If...Else:],
|
||||||
|
[```c
|
||||||
|
int time = 20;
|
||||||
|
(time < 18) ? printf("Good day.") : printf("Good evening.");
|
||||||
|
|
||||||
|
variable = (condition) ? expressionTrue : expressionFalse;
|
||||||
```]
|
```]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -471,6 +471,172 @@ print(my_read_in_dict)
|
|||||||
[`"r"`], [Lesen modus],
|
[`"r"`], [Lesen modus],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
=== Klassen (Objektorientierte Programmierung (OOP))
|
||||||
|
==== Klassen
|
||||||
|
```py my_obj = MyClass() ``` my_obj ist eine Instanz von der klasse MyClass. \
|
||||||
|
Einfache Klasse:
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class MyClass:
|
||||||
|
pass
|
||||||
|
```])
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
print(MyClass.__name__) # -> MyClass
|
||||||
|
mc = MyClass() # liefert auch bereits Funktionalität
|
||||||
|
# -> die Klasse ist ‘callable’
|
||||||
|
# -> sie liefert eine Instanz der Klasse zurück!
|
||||||
|
print(isinstance(mc, MyClass)) # True
|
||||||
|
```])
|
||||||
|
|
||||||
|
===== Atriebute
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Person:
|
||||||
|
name = "Marco"
|
||||||
|
eye_color = "blue"
|
||||||
|
```])
|
||||||
|
Zugriff auf die Variablen
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
Person.name # 'Marco'
|
||||||
|
Person.exe_color # 'blue'
|
||||||
|
```])
|
||||||
|
Modifikation der Variablen
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
setattr(Person, 'name', 'Sandra') # alternativ aber Dot-Notation üblich
|
||||||
|
getattr(Person, 'name') # 'Sandra'
|
||||||
|
|
||||||
|
Person.name = 'Sandra'
|
||||||
|
Person.name # 'Sandra'
|
||||||
|
```])
|
||||||
|
|
||||||
|
===== Methoden
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Person:
|
||||||
|
def say_hello(self):
|
||||||
|
print(f"Hello {self.name}!")
|
||||||
|
|
||||||
|
p1 = Person()
|
||||||
|
p1.name = "Marco"
|
||||||
|
p1.say_hello() # Hello Marco!
|
||||||
|
p2 = Person()
|
||||||
|
p2.name = "Sarah"
|
||||||
|
p2.say_hello() # Hello Sarah!
|
||||||
|
```])
|
||||||
|
mit zusätzlichem parameter:
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Person:
|
||||||
|
def say_hello(self, mark):
|
||||||
|
print(f"Hello {self.name}{mark}")
|
||||||
|
|
||||||
|
p1 = Person()
|
||||||
|
p1.name = "Marco"
|
||||||
|
p1.say_hello('!!!!!') # Hello Marco!!!!!
|
||||||
|
p2 = Person()
|
||||||
|
p2.name = "Sarah"
|
||||||
|
p2.say_hello('?') # Hello Sarah?
|
||||||
|
```])
|
||||||
|
|
||||||
|
===== Initialisierung
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Person:
|
||||||
|
def __init__(self, name="Unbekannter"):
|
||||||
|
self.name = name
|
||||||
|
def say_hello(self):
|
||||||
|
print(f"Hallo {self.name}")
|
||||||
|
|
||||||
|
p1 = Person()
|
||||||
|
p1.say_hello() # Hallo Unbekannter
|
||||||
|
p2 = Person(name="Marco")
|
||||||
|
p2.say_hello() # Hallo Marco
|
||||||
|
```])
|
||||||
|
|
||||||
|
==== Objekte
|
||||||
|
===== Dunder-Methode
|
||||||
|
#table(columns: (0.2fr, 1fr),
|
||||||
|
table.cell(colspan: 2, fill: gray)[Initialisierung],
|
||||||
|
[```py __init__```], [Wird beim initialisieren aufgerufen.],
|
||||||
|
[```py __del__```], [Wird beim löschen aufgerufen. (destructor)],
|
||||||
|
table.cell(colspan: 2, fill: gray)[Arithmetische Operatoren],
|
||||||
|
[```py __add__```], [`+`],
|
||||||
|
[```py __sub__```], [`-`],
|
||||||
|
[```py __mul__```], [`*`],
|
||||||
|
[```py __floordiv__```], [`//`],
|
||||||
|
[```py __truediv__```], [`/`],
|
||||||
|
[```py __mod__```], [`%`],
|
||||||
|
[```py __pow__```], [`**`],
|
||||||
|
[```py __lshift__```], [`<<`],
|
||||||
|
[```py __rshift__```], [`>>`],
|
||||||
|
[```py __and__```], [`&`],
|
||||||
|
[```py __or__```], [`|`],
|
||||||
|
[```py __xor__```], [`^`],
|
||||||
|
[```py __invert__```], [`~`],
|
||||||
|
table.cell(colspan: 2, fill: gray)[Strings],
|
||||||
|
[```py __str__```], [Was passiert wenn geprintet wird.],
|
||||||
|
table.cell(colspan: 2, fill: gray)[Vergleichsoperatoren],
|
||||||
|
[```py __eq__```], [`==`],
|
||||||
|
[```py __ne__```], [`!=`],
|
||||||
|
[```py __lt__```], [`<`],
|
||||||
|
[```py __gt__```], [`>`],
|
||||||
|
[```py __le__```], [`<=`],
|
||||||
|
[```py __ge__```], [`>=`],
|
||||||
|
)
|
||||||
|
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Point:
|
||||||
|
def __init__(self, x=0, y=0):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
if not isinstance(other, Point):
|
||||||
|
raise Exception(f"Nur Objekte vom Typ Point werden berücksichtigt")
|
||||||
|
return Point(self.x + other.x, self.y + other.y)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Point({self.x}, {self.y})"
|
||||||
|
|
||||||
|
p1 = Point(1, 2)
|
||||||
|
p2 = Point(3, 4)
|
||||||
|
p3 = p1 + p2
|
||||||
|
print(p3) # Point(4, 6)
|
||||||
|
```])
|
||||||
|
|
||||||
|
===== Statische Methode
|
||||||
|
Statische methoden haben weder zugrif auf ```py self``` oder ```py cls```.
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Mathe:
|
||||||
|
@staticmethod
|
||||||
|
def addiere(x, y):
|
||||||
|
return x + y
|
||||||
|
|
||||||
|
resultat = Mathe.addiere(3, 5)
|
||||||
|
print(resultat) # 8
|
||||||
|
```])
|
||||||
|
|
||||||
|
===== Klassen Methode
|
||||||
|
Wie Statische Methoden hat aber zugiff auf klassen Objekte(```py cls```)(Klassenattribut). cls sind wie globale Variablen inerhalb einer klasse. Das ```py self``` hat zugriff auf das ```py cls``` sowie auf die eigene Instanz.
|
||||||
|
#table(columns: 1fr, [```py
|
||||||
|
class Auto:
|
||||||
|
anzahl_autos = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def number_of_cars_instantiated(cls):
|
||||||
|
return cls.anzahl_autos
|
||||||
|
|
||||||
|
def __init__(self, marke, farbe):
|
||||||
|
self.marke = marke
|
||||||
|
self.farbe = farbe
|
||||||
|
Auto.anzahl_autos += 1
|
||||||
|
|
||||||
|
print(Auto.number_of_cars_instantiated())
|
||||||
|
bmw = Auto('BMW', 'white')
|
||||||
|
audi = Auto('Audi', 'blue')
|
||||||
|
print(Auto.number_of_cars_instantiated())
|
||||||
|
```])
|
||||||
|
|
||||||
|
==== Vererbung
|
||||||
|
==== Polymorphismus
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== Runden
|
=== Runden
|
||||||
#table(columns: (1fr, 1fr),
|
#table(columns: (1fr, 1fr),
|
||||||
[```py
|
[```py
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user