aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-09-09 17:08:37 +0200
committerJulian T <julian@jtle.dk>2020-09-09 17:08:37 +0200
commit1db7a9c21c34895840adf1e75e0412a0a9eb87e0 (patch)
treea181fcd111041fbe2b0cdca090bd515cc5e614dd
parentc009693a07276f8d66cd68637431f0a3f0e9ef15 (diff)
Added nonworking solution to sig mm2
-rw-r--r--sem5/sig/mm2/opg2.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/sem5/sig/mm2/opg2.py b/sem5/sig/mm2/opg2.py
new file mode 100644
index 0000000..c2b0815
--- /dev/null
+++ b/sem5/sig/mm2/opg2.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+# 2020-09-09/sig/mm2/opg/2 #bb68
+# Første del kan findes i #91a6/P.
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+class Series:
+ def __init__(self):
+ self.conditions = []
+
+ def add_condition(self, *args):
+ self.conditions.extend(args)
+
+ def evaluate(self, n):
+ res = 0
+ for cond in self.conditions:
+ res += cond(n)
+ return res
+
+ def gen(self, r):
+ res = np.zeros_like(r, dtype=float)
+ # Super inefficient
+ for i, v in enumerate(r):
+ res[i] = self.evaluate(v)
+ return res
+
+ # Uhhh terrible
+ def fold(self, s, r):
+ res = np.zeros_like(r, dtype=float)
+
+ # Evaluate own for the whole range r
+ start = r[0]
+ stop = start + len(r)
+
+ # Terribly inefficient
+ for i, v in enumerate(r):
+ for k in range(start, stop):
+ res[i] += self.evaluate(v) * s.evaluate(v - k)
+ print(v, k, self.evaluate(v), s.evaluate(v - k))
+ return res
+
+print("Starting")
+
+s1 = Series()
+s1.add_condition(lambda n: 1 if n >= 0 and n <= 4 else 0)
+s2 = Series()
+s2.add_condition(lambda n: 1 if n >= 0 and n <= 9 else 0)
+
+n = np.arange(-10, 15)
+plt.plot(n, s1.fold(s2, n), "o")
+# print(n, s1.fold(s2, n))
+plt.show()
+
+