## Copyright (C) 2018 Anonymous
## 
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
## 
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
## 
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
 
## -*- texinfo -*-
## @deftypefn  {Function File} {@var{semimajoraxis} =} majaxis (@var{semiminoraxis}, @var{ecc}) 
## 
## This will return the semimajor axis given the semiminoraxis (b) and eccentricity (e)
##
## Examples 
##
## Scalar input:
## @example
## earth_b = 6356752.314245;  %m
## earth_ecc = .081819221456;
## a = majaxis ( earth_b, earth_ecc )
## => a =
##   6.3781e+06
## @end example
##
## Vector input:
## @example
## planets_b = [ 6356752.314245 ; 66854000 ]; %m
## planets_ecc = [ .081819221456 ; 0.3543164 ];
## planets_a = majaxis ( planets_b , planets_ecc )
## => planets_a = 
##      6.3781e+06
##      7.1492e+07
## @end example
## 
## 
## @seealso{minaxis} 
## @end deftypefn

function a = majaxis ( b , ecc )
  if nargin < 2
    print_usage ( );
  end
  if ( ischar ( b ) || ischar ( ecc ) )
    error ( 'majaxis.m : numeric input expected' );
  elseif ( ecc > 1 )
    error ( 'majaxis.m: eccentricity should be <=1' )
  else
    a = b ./ sqrt ( 1 - ecc .^ 2 );
  end
endfunction

%! test
%!
%! earth_b = 6356752.314245;  %m
%! earth_ecc = .081819221456;
%! assert ( majaxis ( earth_b. earth_ecc ), 6378137.01608, 10e-6) 
%! planets_b = [ 6356752.314245 ; 66854000 ]; %m
%! planets_ecc = [ .081819221456 ; 0.3543164 ];
%! assert( majaxis ( planets_b , planets_ecc ),[ 6378137.01608; 71492000.609327 ], 10e-6 )
%! error <numeric input expected> majaxis ("ecc")
%! error <numeric input expected> majaxis ("b")