function fig9_22

global h delta

delta=0.02;

% number of internal grid points
n=8;

% starting guess for fminsearch routine
ynn=2/(pi-2);
y=linspace(delta,ynn,n+1);
h=y(2)-y(1);
for iy=1:n
    xi(iy)=y(iy)/ynn;
end

[sol,fval,exitflag,output] = fminsearch(@E,xi,optimset('MaxFunEvals',1000000,'MaxIter',1000000,'TolX',1e-6));
x=[0 sol 1];
y=[0 y];

output

figure(1)
clf
% get(gcf)
set(gcf,'Position', [22 1107 658 230])
subaxis(1,1,1,1,'MT',-0.01,'MB',0.2,'MR',-0.01,'ML',0.03,'P',0.04)
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)

plot(x,y,'or','MarkerSize',8,'LineWidth',2)
hold on
% exact solution
th=linspace(0,0.5*pi,100);
for it=1:100
    xe(it)=ynn*(th(it)-sin(th(it)));
    ye(it)=ynn*(1-cos(th(it)));
end
plot(xe,ye,'b','LineWidth',1.6)
grid on
axis([0 1 0 2])
xlabel('x-axis')
ylabel('y-axis')
set(gca,'FontSize',16,'FontWeight','bold')
hold off

%exportgraphics(gcf,'/Users/mark/Desktop/brac.eps')

%  this figure is not in text
figure(2)
clf
% get(gcf)
set(gcf,'Position', [23 808 658 230])
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)

plot(x,y,'or','MarkerSize',8,'LineWidth',2)
hold on
th=linspace(0,0.5*pi,100);
for it=1:100
    xe(it)=ynn*(th(it)-sin(th(it)));
    ye(it)=ynn*(1-cos(th(it)));
end
plot(xe,ye,'b','LineWidth',1.6)
grid on
axis([0 0.1 0 0.2])
xlabel('x-axis')
ylabel('y-axis')
set(gca,'FontSize',16,'FontWeight','bold')

hold off


% error function
function s=E(x)
global h delta
ynn=2/(pi-2);
n=length(x);
for i=2:n
    if i < n
        dxR=(x(i+1)-x(i))/h;
    else
        dxR=(1-x(i))/h;
    end
    dxL=(x(i)-x(i-1))/h;
    y=delta+h*(i-1);
    g(i)=sqrt((1+0.5*dxR^2+0.5*dxL^2)/y);
end
dx1=(x(2)-x(1))/h;
g(1)=0.5*sqrt((1+dx1^2)/delta);
dxn=(1-x(n))/h;
g(n+1)=0.5*sqrt((1+dxn^2)/ynn);
s=0;
for i=1:n+1
    s=s+g(i);
end
dx0=x(1)/delta;
g0=2*sqrt(delta*(1+dx0^2));
s=g0+h*s;


























