ADVERTISEMENT
ADVERTISEMENT

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

Parameter(s):

  • 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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.