Bladeren bron

Mostly done with the homework

Pjotir 1 maand geleden
commit
67568b7160

File diff suppressed because it is too large
+ 28 - 0
Homework2/problem1_popgrowthplot.m


+ 31 - 0
Homework2/problem2_piformula.m

@@ -0,0 +1,31 @@
+fprintf("%.15f", approx_pi(1)) %[output:8ad5a476]
+fprintf("%.15f", approx_pi(3)) %[output:494950f9]
+fprintf("%.15f", approx_pi(5)) %[output:49f53ba2]
+fprintf("%.15f", approx_pi(10)) %[output:2fabe6fd]
+
+
+function r = approx_pi(steps)
+    total = 0;
+    for k = 0:steps
+        total = total + ((-1)^k) / ((2*k+1)*3^k);
+    end
+    r = 2 * sqrt(3) * total;
+end
+
+%[appendix]{"version":"1.0"}
+%---
+%[metadata:view]
+%   data: {"layout":"onright"}
+%---
+%[output:8ad5a476]
+%   data: {"dataType":"text","outputData":{"text":"3.079201435678004","truncated":false}}
+%---
+%[output:494950f9]
+%   data: {"dataType":"text","outputData":{"text":"3.137852891595680","truncated":false}}
+%---
+%[output:49f53ba2]
+%   data: {"dataType":"text","outputData":{"text":"3.141308785462883","truncated":false}}
+%---
+%[output:2fabe6fd]
+%   data: {"dataType":"text","outputData":{"text":"3.141593304503081","truncated":false}}
+%---

+ 26 - 0
Homework2/problem3_shortestpath.m

@@ -0,0 +1,26 @@
+% Constants for test
+a = 3; b = 5; d = 12; w = 1;
+
+% Testing all possible bridge positions (0 to d)
+[bridge_pos, path_distance] = fminbnd(@(x) calc_path(a,b,w,d,x), 0, d) %[output:32ce9065] %[output:590b847e]
+
+% a : vertical distance from town A to the river
+% b : vertical distance from town B to the river
+% w : width of the river
+% d : horizontal distance from town A to town B
+% x : horizontal distance of the bridge from town A
+function path_distance = calc_path(a, b, w, d, x)
+    path_distance = sqrt(x^2+a^2) + sqrt((d-x)^2+b^2) + w;
+end
+
+%[appendix]{"version":"1.0"}
+%---
+%[metadata:view]
+%   data: {"layout":"onright"}
+%---
+%[output:32ce9065]
+%   data: {"dataType":"textualVariable","outputData":{"name":"bridge_pos","value":"4.5000"}}
+%---
+%[output:590b847e]
+%   data: {"dataType":"textualVariable","outputData":{"name":"path_distance","value":"15.4222"}}
+%---

+ 7 - 0
Homework2/problem4_kitchoffslaw.m

@@ -0,0 +1,7 @@
+
+
+%[appendix]{"version":"1.0"}
+%---
+%[metadata:view]
+%   data: {"layout":"onright"}
+%---

Some files were not shown because too many files changed in this diff