% 始点の近傍で区間を細かく分割して計算

xend = 10; yend = 3;

options = optimset('MaxFunEvals', 1e+6, 'MaxIter', 1e+5, 'TolFun',1e-10);

set(0,'defaultAxesFontSize',16);
set(0,'defaultTextFontSize',16);

n = 9;
h = xend/(n+1);
xnodal1 = transpose((1:n)*h);
xnodal2 = xnodal1/10;
xnodal = [xnodal2; xnodal1];
ynodal = (yend/xend)*xnodal;
sz = size(xnodal); n = sz(1);
f = @(y) time_along_linear_approx_path( n, xnodal, y, xend, yend );
[yopt,fopt] = fminsearch(f, ynodal, options);
%n, fopt

xall = [0; xnodal; xend];
yall = [0; yopt;   yend];

plot(xall, yall);
set(gca,'YDir','reverse');
ylim([0,5]);
pbaspect([1 1/2 1]);
xlabel('x');
ylabel('y');
grid on;
saveas(gcf, 'fastest-10-3-linear-uneven.eps', 'eps');

fprintf("始点の近傍で区間を細かく分割\n");
fprintf("%d分割  時間 %f\n", n+1, fopt);
fprintf("一時停止：何かのキーを押してください\n");
pause;
