|
@@ -1,8 +1,10 @@
|
|
|
-% Constants for test
|
|
|
|
|
-a = 3; b = 5; d = 12; w = 1;
|
|
|
|
|
|
|
+function main()
|
|
|
|
|
+ % 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]
|
|
|
|
|
|
|
+ % Testing all possible bridge positions (0 to d)
|
|
|
|
|
+ [bridge_pos, path_distance] = fminbnd(@(x) calc_path(a,b,w,d,x), 0, d)
|
|
|
|
|
+end
|
|
|
|
|
|
|
|
% a : vertical distance from town A to the river
|
|
% a : vertical distance from town A to the river
|
|
|
% b : vertical distance from town B to the river
|
|
% b : vertical distance from town B to the river
|
|
@@ -12,15 +14,3 @@ a = 3; b = 5; d = 12; w = 1;
|
|
|
function path_distance = calc_path(a, b, w, d, x)
|
|
function path_distance = calc_path(a, b, w, d, x)
|
|
|
path_distance = sqrt(x^2+a^2) + sqrt((d-x)^2+b^2) + w;
|
|
path_distance = sqrt(x^2+a^2) + sqrt((d-x)^2+b^2) + w;
|
|
|
end
|
|
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"}}
|
|
|
|
|
-%---
|
|
|