function Show_fsolve()
% Shows how to solve a nonlinear system using fsolve 

clc
for eg=1:10
   x0 = 10*randn(3,1);
   xStar = fsolve(@MyF,x0,optimset('Display','off'));
   fprintf('x0    = %20.15f  %20.15f  %20.15f\n',x0)
   fprintf('xStar = %20.15f  %20.15f  %20.15f\n\n',xStar)
end

 
 
 

  function Fc = MyF(xc)
% xc is a column 3-vector
% This function is zeroed by a point that is on three given elliposids
A1 =  [6  -7   2; -7  10  -3;  2  -3  1];
A2 =  [5  -1   1; -1  10  -1;  1  -1  1];
A3 =  [9   4  -2;  4   2  -1; -2  -1  1];
r =  [2;1;-1];
Fc = [(xc-r)'*A1*(xc-r)-1;...
      (xc-r)'*A2*(xc-r)-1;...
      (xc-r)'*A3*(xc-r)-1];