Golang math.Jn()函数及其示例

Golang math.Jn()函数及其示例

Go语言通过math包提供内置支持基本常数和数学函数来执行数字运算。你可以使用math包提供的Jn()函数查找第一类Bessel函数的n阶。因此,您需要通过import关键字在程序中添加math包以访问Jn()函数。

语法:

func Jn(a int, b float64) float64

示例1:

// Golang程序示例 
// math.Jn() 函数
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 使用Jn()函数找到第一类n阶Bessel函数 
res_1 := math.Jn(1, math.Inf(-1))
res_2 := math.Jn(3, math.Inf(1))
res_3 := math.Jn(4, 5)
res_4 := math.Jn(1, math.NaN())
// 显示结果
fmt.Printf("\n结果1: %.2f", res_1)
fmt.Printf("\n结果2: %.2f", res_2)
fmt.Printf("\n结果3: %.2f", res_3)
fmt.Printf("\n结果4: %.2f", res_4)
} 

输出:

结果1: 0.00
结果2: 0.00
结果3: 0.39
结果4: NaN

示例2:

// Golang程序示例 
// math.Jn() 函数
package main
import (
"fmt"
"math"
)
// 主函数
func main() {
// 使用Jn()函数找到第一类n阶Bessel函数 
nvalue_1 := math.Jn(2, 3.3)
nvalue_2 := math.Jn(4, 5.6)
// 给定数字的总和
res := nvalue_1 + nvalue_2
fmt.Printf("%.2f + %.2f = %.2f",
nvalue_1, nvalue_2, res)
} 

输出:

0.48 + 0.39 = 0.87

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程