|
@@ -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"}}
|
|
|
|
|
+%---
|