calc_path.m 336 B

12345678
  1. % a : vertical distance from town A to the river
  2. % b : vertical distance from town B to the river
  3. % w : width of the river
  4. % d : horizontal distance from town A to town B
  5. % x : horizontal distance of the bridge from town A
  6. function path_distance = calc_path(a, b, w, d, x)
  7. path_distance = sqrt(x^2+a^2) + sqrt((d-x)^2+b^2) + w;
  8. end