besyn.f90 822 Bytes
real(4) function besyn(n,x)
    implicit none
    ! This function compute the rank n Bessel Y function
    ! using recurrence relation :
    ! Yn+1(x)=2n/x * Yn(x) - Yn-1(x)
    !
    integer :: n
    real(4) :: x

    real(4),external :: besy0,besy1
    real(4) :: two_on_x,bynm1,byn,bytmp
    integer :: i

    if (n==0) then
        besyn=besy0(x)
        return
    end if
    if (n==1) then
        besyn=besy1(x)
        return
    end if

    if (n < 0) then
        write(*,*) "Error in besyn, n must be >= 0"
        stop
    end if
    if (x <= 0.) then
        write(*,*) "Error in besyn, x must be strictly positive"
    end if

    two_on_x=2./x
    bynm1=besy0(x)
    byn=besy1(x)

    do i=1,n-1
        bytmp=two_on_x*byn*i-bynm1
        bynm1=byn
        byn=bytmp
    end do
    besyn=bytmp
end function