% Exa = 1;

switch Exa
case 1     %  find the zero of solution of sin(x)=0
  x0 = fsolve(@(x)sin(x),3) % Octave and Matlab
  x0 = fzero(@(x)sin(x),3)  % Octave and Matlab, one variable only

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 2
  % zero of a Bessel function
  x = linspace(0,15);
  plot(x,besselj(0,x))
  drawnow()

  x0 = 6.0;
  f = @(x)(besselj(0,x));

  [x, fval, info] = fsolve(f,x0)

  clear options
  options.TolFun = 1e-12;
  options.TolX   = 1e-12;
  [x, fval, info] = fsolve(@(x)besselj(0,x),x0,options)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 3  % Octave only
  % zero of a Bessel function, using derivative
  x0 = 6.0  % choose the starting value

  function [y,dy] = f2(x)
    y  = +besselj(0,x);
    dy = -besselj(1,x);
    [x,y]  % displayed for each evaluation of the function
  endfunction

  clear options          % set the options for fsolve
  options.TolFun = 1e-12;
  options.TolX   = 1e-12;
  options.Jacobian = 'on';
  options.Updating = 'off';

  [x2, fval, info] = fsolve(@f2,x0,options)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 4
  % solving a system of nonlinear equations

  x0 = [1;1];  % choose the starting value

%  function y = f(x)
%    y = [x(1)^2 + 4*x(2)^2-1; 
%	 4*x(1)^4 + x(2)^2-1];
%  end%function

  f = @(x)[x(1)^2 + 4*x(2)^2-1;4*x(1)^4 + x(2)^2-1];

  [y,fval,info] = fsolve(f,x0)
end%switch
