Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

golang
communitycreator

# What is the Y1 function in Golang?

Faraz Karim

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The programming language Go uses the Y1 function to find the order-one Bessel function of the second kind for the passed argument.

To use this function, you must import the math package in your file and access the Y1 function within it using the . notation (math.Y1). Here, Y1 is the actual function, while math is the Go package that stores the definition of this function.

### The Bessel functions

The Bessel functions are canonical solutions to Bessel’s differential equation. These solutions are in the form below:

$y= AJ_{v}(x) + BY_{v}(x)$

In the equation above, subscript $v$ determines the order of the functions (the Bessel functions are defined for all real values of $v$). So, $for v = 1$, the produced solutions will be of order-one.

$Y$ in the equation above represents the second solution to the Bessel equation, also known as the Bessel function of the second kind.

### Function definition

The definition of the Y1 function inside the math package is as follows:

### Parameters

The Y1 function takes a single argument of type float64 that represents the number for which you want to find the second kind order-one Bessel function.

### Return value

The Y1 function returns a single value of type float64 that represents the second kind order-one Bessel function of the argument.

Some special cases are +Inf, 0, or NAN is passed as an argument:

• If the argument has a +Inf value, the return value will be 0.

• If the argument has a value of 0, the return value will be -Inf.

• If the argument is NAN or a negative value, the return value is NAN.

### Code

Below is a simple example where we find out the order-one Bessel function of the second kind for 5.35.

package mainimport(  "fmt"   "math") func main() {	var x float64 = 5.35 	y := math.Y1(x)	fmt.Print("The second kind order-one Bessel function of ", x," is ", y)}

The example below shows how the Y1 function deals with an argument whose value is infinite (both positive and negative).

To generate the infinite value, we use the Inf function in the math package, which generates an infinite value with the same sign as the argument passed to it.

package mainimport(  "fmt"   "math") func main() {	var x float64 = math.Inf(1)	y := math.Y1(x)	fmt.Print("The second kind order-one Bessel function of ", x," is ", y, "\n")	x = math.Inf(-1)	y = math.Y1(x)	fmt.Print("The second kind order-one Bessel function of ", x," is ", y)}

The example below shows how the Y1 function handles NAN values.

Here, we use the NaN function present in the math package to generate a NAN value.

package mainimport(  "fmt"   "math") func main() {  my_nan := math.NaN()	y := math.Y1(my_nan)	fmt.Print("The second kind order-one Bessel function of ", my_nan," is ", y, "\n")}

RELATED TAGS

golang
communitycreator

CONTRIBUTOR

Faraz Karim

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 