Bessel function Of First Kind

Share your advanced PureBasic knowledge/code with the community.
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Bessel function Of First Kind

Post by Guimauve »

Hello everyone,

This the Bessel function Of First Kind for use in heat transfer calculation.

N.B. The factorial function is commented, uncomment it if needed.

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Projet name : Bessel function Of First Kind
; File name : BesselOfFirstKind.pb
; File version : 1.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 12-06-2010
; Update : 12-06-2010
; PureBasic version : 4.50
; Plateform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; Procedure.d Factorial(valeur.l)
;   
;   Resultat.d = 1
;   
;   For n = 2 To valeur
;     Resultat * n
;   Next
;   
;   ProcedureReturn Resultat
; EndProcedure

Procedure.d BesselOfFirstKind(x.d, Order.b, Max.l = 50) ; Order = {0,1,2,3,4,...}

  For K = 0 To Max
    
    Result.d = Result + Pow(-1 / 4 * x * x, K) / (Factorial(K) * Factorial(K + Order))
    
  Next
 
  ProcedureReturn Result * Pow(x/2, Order)
EndProcedure 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
; <<<<< !!! WARNING - YOU ARE NOW IN A TESTING ZONE - WARNING !!! <<<<< 
; <<<<< !!! WARNING - THIS CODE SHOULD BE COMMENTED - WARNING !!! <<<<< 
; <<<<< !!! WARNING - BEFORE THE FINAL COMPILATION. - WARNING !!! <<<<< 
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

Debug "    x             J0 ()           J1 ()"

For Index = 0 To 24
  
  Debug StrD(Index/10, 5) + "     " + StrD(BesselOfFirstKind(Index/10, 0), 4) + "     " + StrD(BesselOfFirstKind(Index/10, 1), 4)
  
Next 

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
Guimauve