msta2 Function

function msta2(x, n, mp)

************80

! MSTA2 determines a backward recurrence starting point for Jn(x).

Discussion:

This procedure determines the starting point for a backward
recurrence such that all Jn(x) has MP significant digits.

Licensing:

This routine is copyrighted by Shanjie Zhang and Jianming Jin.  However,
they give permission to incorporate this routine into a user program
provided that the copyright is acknowledged.

Modified:

08 July 2012

Author:

Shanjie Zhang, Jianming Jin

Reference:

Shanjie Zhang, Jianming Jin,
Computation of Special Functions,
Wiley, 1996,
ISBN: 0-471-11963-6,
LC: QA351.C45.

Parameters:

Input, real ( kind = 8 ) X, the argument of Jn(x).

Input, integer ( kind = 4 ) N, the order of Jn(x).

Input, integer ( kind = 4 ) MP, the number of significant digits.

Output, integer ( kind = 4 ) MSTA2, the starting point.

Arguments

Type IntentOptional Attributes Name
real(kind=8) :: x
integer(kind=4) :: n
integer(kind=4) :: mp

Return Value integer(kind=4)


Calls

proc~~msta2~2~~CallsGraph proc~msta2~2 msta2 envj envj proc~msta2~2->envj

Source Code

function msta2 ( x, n, mp )

  !*****************************************************************************80
  !
  !! MSTA2 determines a backward recurrence starting point for Jn(x).
  !
  !  Discussion:
  !
  !    This procedure determines the starting point for a backward
  !    recurrence such that all Jn(x) has MP significant digits.
  !
  !  Licensing:
  !
  !    This routine is copyrighted by Shanjie Zhang and Jianming Jin.  However, 
  !    they give permission to incorporate this routine into a user program 
  !    provided that the copyright is acknowledged.
  !
  !  Modified:
  !
  !    08 July 2012
  !
  !  Author:
  !
  !    Shanjie Zhang, Jianming Jin
  !
  !  Reference:
  !
  !    Shanjie Zhang, Jianming Jin,
  !    Computation of Special Functions,
  !    Wiley, 1996,
  !    ISBN: 0-471-11963-6,
  !    LC: QA351.C45.
  !
  !  Parameters:
  !
  !    Input, real ( kind = 8 ) X, the argument of Jn(x).
  !
  !    Input, integer ( kind = 4 ) N, the order of Jn(x).
  !
  !    Input, integer ( kind = 4 ) MP, the number of significant digits.
  !
  !    Output, integer ( kind = 4 ) MSTA2, the starting point.
  !
  implicit none

  real ( kind = 8 ) a0
  real ( kind = 8 ) ejn
  ! real ( kind = 8 ) envj
  real ( kind = 8 ) f
  real ( kind = 8 ) f0
  real ( kind = 8 ) f1
  real ( kind = 8 ) hmp
  integer ( kind = 4 ) it
  integer ( kind = 4 ) mp
  integer ( kind = 4 ) msta2
  integer ( kind = 4 ) n
  integer ( kind = 4 ) n0
  integer ( kind = 4 ) n1
  integer ( kind = 4 ) nn
  real ( kind = 8 ) obj
  real ( kind = 8 ) x

  a0 = abs ( x )
  hmp = 0.5D+00 * mp
  ejn = envj ( n, a0 )

  if ( ejn <= hmp ) then
     obj = mp
     n0 = int ( 1.1D+00 * a0 )
  else
     obj = hmp + ejn
     n0 = n
  end if

  f0 = envj ( n0, a0 ) - obj
  n1 = n0 + 5
  f1 = envj ( n1, a0 ) - obj

  do it = 1, 20
     nn = n1 - ( n1 - n0 ) / ( 1.0D+00 - f0 / f1 )
     f = envj ( nn, a0 ) - obj
     if ( abs ( nn - n1 ) < 1 ) then
        exit
     end if
     n0 = n1
     f0 = f1
     n1 = nn
     f1 = f
  end do

  msta2 = nn + 10

  return
end function msta2