Re: (very) slow recursive function
- From: "Ralf Schaa" <schaa@xxxxxxxxxxxxxxxx>
- Date: 30 Oct 2006 18:15:32 -0800
Thanks everyone for your answers.
There was an error in the program: 'LegendrePoly_' of course is
'LegendrePoly';
For whom is interested: here is a program that calculates the modified
Bessel function of the first kind with fractional order. Works fine and
is recursive but really slow for order>20. But it calculates complex
arguments.
pure recursive function Inu(z,nu) result(I_nu)
! Computes the modified Besselfunction of
! order 1/2, 3/2, ... , n/2 with complex argument
! using a recursion relationship together with
! explicit formulas for I_1/2 and I_3/2.
!
! Works fine for nu < 20.
implicit none
complex(dc), intent(in) :: z ! complex argument
real(dp), intent(in) :: nu ! fractional order
complex(dc) :: I_nu ! function result
complex(dc) :: sinh_z ! sinh for complex arguments
complex(dc) :: cosh_z ! cosh for complex arguments
sinh_z = (exp(z)-exp(-z))/2.0d0
cosh_z = (exp(z)+exp(-z))/2.0d0
! mind divisions with 'z' -> z cannot be 0 !
if(nu == 0.5d0) then
I_nu = sqrt(2.0d0/PI)*sinh_z/sqrt(z)
elseif(nu == 1.5d0) then
I_nu = (2.0d0*cosh_z - 2.0d0*sinh_z/z)/sqrt(2.0d0*PI*z)
else
I_nu = Inu(z,nu-2.0d0) - 2.0d0*(nu-1.0d0)*Inu(z,nu-1.0d0)/z
endif
end function Inu
.
- References:
- (very) slow recursive function
- From: Ralf Schaa
- (very) slow recursive function
- Prev by Date: Re: io-unit has been opened
- Next by Date: Re: READ-statement and a segmentation fault
- Previous by thread: Re: (very) slow recursive function
- Next by thread: IEEE intrinsic modules
- Index(es):