Golang math.J1()函数及其使用示例

Golang math.J1()函数及其使用示例

Go语言提供了内置的支持基本常量和数学函数的 math 包。你可以使用 math 包中提供的 J1() 函数查找一类顺序 Bessel 函数。因此,你需要在程序中使用 import 关键字添加 math 包来访问 J1() 函数。

语法:

func J1(a float64) float64
  • 如果 J1(±Inf),则此函数将返回 0。
  • 如果 J1(NaN),则此函数将返回 NaN。

示例1:

// Golang中用于演示math.J1()函数的程序
package main

import (
    "fmt"
    "math"
)

// 主函数
func main() {

    // 使用 J1() 函数获取第一类顺序 Bessel 函数
    res_1 := math.J1(math.Inf(-1))
    res_2 := math.J1(math.Inf(1))
    res_3 := math.J1(4)
    res_4 := math.J1(math.NaN())

    // 显示结果
    fmt.Printf("\nResult 1: %.2f", res_1)
    fmt.Printf("\nResult 2: %.2f", res_2)
    fmt.Printf("\nResult 3: %.2f", res_3)
    fmt.Printf("\nResult 4: %.2f", res_4)

} 

输出:

Result 1: 0.00
Result 2: 0.00
Result 3: -0.07
Result 4: NaN

示例2:

// Golang中用于演示math.J1()函数的程序
package main

import (
    "fmt"
    "math"
)

// 主函数
func main() {

    // 使用 J1() 函数获取第一类顺序 Bessel 函数
    nvalue_1 := math.J1(2.0)
    nvalue_2 := math.J1(4.1)

    // 计算所给数的总和
    res := nvalue_1 + nvalue_2
    fmt.Printf("%.2f + %.2f = %.2f",
            nvalue_1, nvalue_2, res)

} 

输出:

0.58 + -0.10 = 0.47

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程