Code covered by the BSD License  

Highlights from
A MATLAB Script for Predicting Transits of Mercury and Venus

A MATLAB Script for Predicting Transits of Mercury and Venus

by

 

07 Dec 2012 (Updated )

Local circumstances of solar transits of the planets Mercury and Venus.

broot (f, x1in, x2in, factor, dxmax)
function [x1out, x2out] = broot (f, x1in, x2in, factor, dxmax)

% bracket a single root of a nonlinear equation

% input

%  f      = objective function coded as y = f(x)
%  x1in   = initial guess for first bracketing x value
%  x2in   = initial guess for second bracketing x value
%  factor = acceleration factor (non-dimensional)
%  dxmax  = rectification interval

% output

%  x1out = final value for first bracketing x value
%  x2out = final value for second bracketing x value

% Celestial Computing with MATLAB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% evaluate objective function at initial value

f1 = feval(f, x1in);

% save initial value

x3 = x1in;
    
% save initial delta-x

dx = x2in - x1in;

% perform bracketing until the product of the
% two function values is negative

while (1)
   % geometrically accelerate the second point
       
   x2in = x2in + factor * (x2in - x3);
   
   % evaluate objective function at x2
       
   f2 = feval(f, x2in);
       
   % check to see if rectification is required
       
   if (abs(x2in - x3) > dxmax)
      x3 = x2in - dx;
   end

   % is the root bracketed?

   if ((f1 * f2) < 0)
      break;
   end
end

x1out = x1in;

x2out = x2in;

Contact us