function time = linear_approx( n, xnodal, ynodal, xend, yend )
% 区分線形補間で表された経路における降下時間を計算
% (0,0), (xnodal(1),ynodal(1)), ..., (xnodal(n),ynodal(n)), (xend,yend)
  time = 0;
  
  xi = 0; xj = xnodal(1);
  yi = 0; yj = ynodal(1);
  L = @(x) yi.*(xj-x)/(xj-xi) + yj.*(x-xi)/(xj-xi);
  Ld = @(x) -yi/(xj-xi) + yj/(xj-xi);
  ts = falling_time(L, Ld, xi, xj);
  time = time + ts;
  
  for k=1:n-1
    xi = xnodal(k); xj = xnodal(k+1);
    yi = ynodal(k); yj = ynodal(k+1);
    L = @(x) yi.*(xj-x)/(xj-xi) + yj.*(x-xi)/(xj-xi);
    Ld = @(x) -yi/(xj-xi) + yj/(xj-xi);
    ts = falling_time(L, Ld, xi, xj);
    time = time + ts;
  end
  
  xi = xnodal(n); xj = xend;
  yi = ynodal(n); yj = yend;
  L = @(x) yi.*(xj-x)/(xj-xi) + yj.*(x-xi)/(xj-xi);
  Ld = @(x) -yi/(xj-xi) + yj/(xj-xi);
  ts = falling_time(L, Ld, xi, xj);
  time = time + ts;
end
