Menu Close

Bessel Function of Order ‘n’ – FORTRAN

To compute Bessel functions in Fortran, you can use the built-in mathematical functions available in the Fortran standard library.

Let’s see an example that demonstrates how to calculate the Bessel function of order n (in this case, J0) for a given argument x.

The dbesj0 function computes the Bessel function of the first kind with order 0 (J0). You can modify it to calculate other orders by using the dbesjn function instead.

Example (Bessel function of order n)

program bessel_example
  implicit none
  integer :: n
  real(kind=8) :: x
  real(kind=8) :: bessel

  ! Prompt the user for input
  write(*,*) "Enter the order of the Bessel function (n):"
  read(*,*) n
  write(*,*) "Enter the argument of the Bessel function (x):"
  read(*,*) x

  ! Compute the Bessel function
  bessel = dbesj0(x) ! Example for J0 Bessel function, modify for other orders (dbesjn)

  ! Display the result
  write(*,*) "J", n, "(", x, ") = ", bessel
end program bessel_example

Output


 Enter the order of the Bessel function (n):
2
 Enter the argument of the Bessel function (x):
5
 J           2 (   5.0000000000000000      ) =  -0.17759677131433829 

More Related Stuff