function G = fun(x)
alpha=0.125*pi/180;x1=0;z1=5;x2=0;z2=25;L1=5;L2=5;f=30;h0=20;n2=1.49386;
G1 = tan(alpha) - x(1)/x(2);
G2 = n2*sin(atan((x1 - x(1))/(z1 - x(2))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 - alpha + atan((x1 - x(1))/(z1 - x(2)))) ;
G3 = n2*sin(atan((x2 - x(3))/(z2 - x(4))) - atan((x(2) - x(4))/(x(1) - x(3)))) - sin(pi/2 + atan((x2 - x(3))/(z2 - x(4))));
G4 = L1 + L2 - f + h0 - h0*n2 + n2*((x(1) - x(3))^2 + (x(2) - x(4))^2)^(1/2);
G = G1.^2 + G2.^2 + G3.^2 + G4.^2;
----------------------------------------------------------------------------------------------------------------------------------------------
X0 = [0.01,5.01,0.01,25.01];
options=optimset('Algorithm', 'levenberg-marquardt','Display','iter', 'MaxFunEvals',20000,'MaxIter',1000);
T = lsqnonlin(@fun,X0,[],[],options)
----------------------------------------------------------------------------------------------------------------------------------------------
First-Order Norm of
Iteration Func-count Residual optimality Lambda step
0 5 0.0589634 9.75e+07 0.01
Local minimum possible.
lsqnonlin stopped because the relative size of the current step is less than
the default value of the step size tolerance.
T =
0.010000000000000 5.010000000000000 0.010000000000000 25.010000000000002