We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 51936d7 commit 3060849Copy full SHA for 3060849
contents/forward_euler_method/code/coconut/euler.coco
@@ -0,0 +1,23 @@
1
+import numpy as np
2
+
3
+def forward_euler(time_step, n):
4
+ y = 1
5
+ for _ in range(n):
6
+ yield y
7
+ y *= (1 - 3 * time_step)
8
9
10
+def check(result, threshold, time_step):
11
+ x = np.linspace(0, 1, 1 / time_step)
12
+ solution = np.exp(-3 * x)
13
+ return np.abs(solution - result) <= threshold).all()
14
15
16
+if __name__ == '__main__':
17
+ time_step = 0.01
18
+ n = 100
19
+ threshold = 0.01
20
21
+ result = np.array(list(forward_euler(time_step, n)))
22
+ approx = check(result, threshold, time_step)
23
+ print("All values within threshold") if approx else print("Value(s) not in threshold")
0 commit comments