diff options
author | haddoucher <reda.haddouche@ost.ch> | 2022-08-16 14:36:07 +0200 |
---|---|---|
committer | haddoucher <reda.haddouche@ost.ch> | 2022-08-16 14:36:07 +0200 |
commit | f031b148a79d1dafb0e3405643be05e7a7eb1222 (patch) | |
tree | 3f0c7d27ba90e10874a885cae9026fdbaa0b01e6 /buch/papers/kra/scripts/simulation.py | |
parent | Update tschebyscheff_beispiel.tex (diff) | |
parent | Merge pull request #5 from haddoucher/sturmliouville/erik-branch (diff) | |
download | SeminarSpezielleFunktionen-f031b148a79d1dafb0e3405643be05e7a7eb1222.tar.gz SeminarSpezielleFunktionen-f031b148a79d1dafb0e3405643be05e7a7eb1222.zip |
Merge remote-tracking branch 'origin/master' into sturmliouville/redabranch
Diffstat (limited to 'buch/papers/kra/scripts/simulation.py')
-rw-r--r-- | buch/papers/kra/scripts/simulation.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/buch/papers/kra/scripts/simulation.py b/buch/papers/kra/scripts/simulation.py new file mode 100644 index 0000000..8bccb6a --- /dev/null +++ b/buch/papers/kra/scripts/simulation.py @@ -0,0 +1,40 @@ +import sympy as sp
+
+
+class Simulation:
+ def __init__(self):
+ self.k_1, self.k_2, self.k_c = sp.symbols("k_1 k_2 k_c")
+ self.m_1, self.m_2 = sp.symbols("m_1 m_2")
+ self.t = sp.symbols("t")
+ K = sp.Matrix(
+ [[-(self.k_1 + self.k_c), self.k_c], [self.k_c, -(self.k_2 + self.k_c)]]
+ )
+ M = sp.Matrix([[1 / self.m_1, 0], [0, 1 / self.m_2]])
+ A = M * K
+
+ self.eigenvecs = []
+ self.eigenvals = []
+ for ev, mult, vecs in A.eigenvects():
+ self.eigenvecs.append(sp.Matrix(vecs))
+ self.eigenvals.extend([ev] * mult)
+
+ def __call__(self, t, x_0, k_1, k_c, k_2, m_1, m_2):
+ params = {
+ self.k_1: k_1,
+ self.k_c: k_c,
+ self.k_2: k_2,
+ self.m_1: m_1,
+ self.m_2: m_2,
+ }
+ x_0 = sp.Matrix(x_0)
+ eig_mat = sp.Matrix.hstack(*self.eigenvecs).subs(params)
+ g = eig_mat.inv() * x_0
+ L = sp.Matrix(
+ [
+ g[0] * sp.cos(self.eigenvals[0].subs(params) * self.t),
+ g[1] * sp.cos(self.eigenvals[1].subs(params) * self.t),
+ ]
+ )
+ x = eig_mat * L
+ f = sp.lambdify(self.t, x, "numpy")
+ return f(t).squeeze()
|