×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.J1() Function with Examples

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

math.J1()

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

It accepts a parameter (x) and returns the order-one Bessel function of the first kind.

Syntax

func J1(x float64) float64

Parameters

  • x : The value to be used to get the order-one Bessel function of the first kind.

Return Value

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

Special Cases

  • J1(±Inf) = 0
    If the parameter is ±Inf, the function returns 0.
  • J1(NaN) = NaN
    If the parameter is NaN, the function returns the same (NaN).

Example 1

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

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.J1(1))
	fmt.Println(math.J1(1.5))
	fmt.Println(math.J1(5))

	fmt.Println(math.J1(-1))
	fmt.Println(math.J1(-1.5))
	fmt.Println(math.J1(-5))

	fmt.Println(math.J1(0))
	fmt.Println(math.J1(math.Inf(1)))
	fmt.Println(math.J1(math.Inf(-1)))
	fmt.Println(math.J1(math.NaN()))
}

Output:

0.4400505857449335
0.5579365079100996
-0.32757913759146523
-0.4400505857449335
-0.5579365079100996
0.32757913759146523
0
0
0
NaN

Example 2

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var J1X float64

	x = 1
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)

	x = 10.5
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)

	x = 0
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)

	x = math.NaN()
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)

	x = math.Inf(1)
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)

	x = math.Inf(-1)
	J1X = math.J1(x)
	fmt.Println("J1(", x, ") = ", J1X)
}

Output:

J1( 1 ) =  0.4400505857449335
J1( 10.5 ) =  -0.0788500142273315
J1( 0 ) =  0
J1( NaN ) =  NaN
J1( +Inf ) =  0
J1( -Inf ) =  0

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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