dbeskn.f90 834 Bytes
real(8) function dbeskn(n,x)
    implicit none
    ! This function compute the rank n Bessel Y function
    ! using recurrence relation :
    ! Kn+1(x)=2n/x * Kn(x) + Kn-1(x)
    !
    integer :: n
    real(8) :: x

    real(8),external :: dbesk0,dbesk1
    real(8) :: two_on_x,bknm1,bkn,bktmp
    integer :: i

    if (n==0) then
        dbeskn=dbesk0(x)
        return
    end if
    if (n==1) then
        dbeskn=dbesk1(x)
        return
    end if

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

    two_on_x=2./x
    bknm1=dbesk0(x)
    bkn=dbesk1(x)

    do i=1,n-1
        bktmp=two_on_x*bkn*i+bknm1
        bknm1=bkn
        bkn=bktmp
    end do
    dbeskn=bktmp
end function