×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Yn() Function with Examples

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

math.Yn()

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

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

Syntax

func Yn(n int, x float64) float64

Parameters

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

Return Value

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

Special Cases

  • Yn(n, +Inf) = 0
    If the second parameter (x) is +Inf, the function returns 0.
  • Yn(n ≥ 0, 0) = -Inf
    If the first parameter (n) is greater than or equal to 0 and the second parameter (x) is 0, the function returns -Inf.
  • Yn(n < 0, 0) = +Inf if n is odd, -Inf if n is even
    If the first parameter (n) is less than 0 and the second parameter (x) is 0, the function returns +Inf if n is odd, -Inf if n is even.
  • Yn(n, x < 0) = NaN
    If the second parameter (x) is less than 0, the function returns NaN.
  • Yn(n, NaN) = NaN
    If the second parameter (x) is Nan, the function returns NaN.

Example 1

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

package main

import (
	"fmt"
	"math"
)

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

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

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

Output:

-260.4058666258122
-0.9321937597629739
-0.1478631433912268
NaN
NaN
NaN
-Inf
0
NaN
NaN

Example 2

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

package main

import (
	"fmt"
	"math"
)

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

	n = 1
	x = 1
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)

	n = 5
	x = -11.5
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)

	n = -5
	x = -11.5
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)

	n = 2
	x = math.Inf(1)
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)

	n = 2
	x = math.Inf(-1)
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)

	n = 2
	x = math.NaN()
	YnX = math.Yn(n, x)
	fmt.Println("Yn(", n, ",", x, ") = ", YnX)
}

Output:

Yn( 1 , 1 ) =  -0.7812128213002887
Yn( 5 , -11.5 ) =  NaN
Yn( -5 , -11.5 ) =  NaN
Yn( 2 , +Inf ) =  0
Yn( 2 , -Inf ) =  NaN
Yn( 2 , NaN ) =  NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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