×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Jn() Function with Examples

Golang | math.Jn() Function: Here, we are going to learn about the Jn() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 01, 2021

math.Jn()

The Jn() function is an inbuilt function of the math package which is used to get the order-n Bessel function of the first kind.

It accepts two parameters (n, x), and returns the order-n Bessel function of the first kind.

Syntax

func Jn(n int, x float64) float64

Parameters

  • n, x : The values to be used to get the order-n Bessel function of the first kind.

Return Value

The return type of Jn() function is a float64, it returns the order-n Bessel function of the first kind.

Special Cases

  • Jn(n, ±Inf) = 0
    If the second parameter is ±Inf, the function returns 0.
  • Jn(n, NaN) = NaN
    If the second parameter is NaN, the function returns NaN.

Example 1

// Golang program to demonstrate the
// example of math.Jn() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Jn(5, 1))
	fmt.Println(math.Jn(2, 1.5))
	fmt.Println(math.Jn(-1, 5))

	fmt.Println(math.Jn(5, -1))
	fmt.Println(math.Jn(2, -1.5))
	fmt.Println(math.Jn(-1, -5))

	fmt.Println(math.Jn(1, 0))
	fmt.Println(math.Jn(1, math.Inf(1)))
	fmt.Println(math.Jn(2, math.Inf(-1)))
	fmt.Println(math.Jn(3, math.NaN()))
}

Output:

0.0002497577302112345
0.23208767214421475
0.32757913759146523
-0.0002497577302112345
0.23208767214421475
-0.32757913759146523
0
0
0
NaN

Example 2

// Golang program to demonstrate the
// example of math.Jn() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var n int
	var JnX float64

	n = 1
	x = 1
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)

	n = 5
	x = -11.5
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)

	n = -5
	x = -11.5
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)

	n = 2
	x = math.Inf(1)
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)

	n = 2
	x = math.Inf(-1)
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)

	n = 2
	x = math.NaN()
	JnX = math.Jn(n, x)
	fmt.Println("Jn(", n, ",", x, ") = ", JnX)
}

Output:

Jn( 1 , 1 ) =  0.4400505857449335
Jn( 5 , -11.5 ) =  0.17111265188686217
Jn( -5 , -11.5 ) =  -0.17111265188686217
Jn( 2 , +Inf ) =  0
Jn( 2 , -Inf ) =  0
Jn( 2 , NaN ) =  NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.