Golang math.J0()函数示例

Golang math.J0()函数示例

Go语言提供了内置支持基本常数和数学函数的功能,以便通过math包对数字执行操作。您可以通过math包中提供的J0()函数找到一类的第一种零阶贝塞尔函数。因此,您需要使用import关键字在程序中添加math包以访问J0()函数。

语法:

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

例子 1:

// Golang程序演示math.J0()函数
package main
   
import (
    "fmt"
    "math"
)
   
//主功能
func main() {
   
    // 寻找第一类第一类 Bessel函数
    //使用J0()函数
    res_1 := math.J0(math.Inf(-1))
    res_2 := math.J0(math.Inf(1))
    res_3 := math.J0(5)
    res_4 := math.J0(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.18
Result 4: NaN

例子 2:

// Golang程序演示math.J0()函数
package main
 
import (
    "fmt"
    "math"
)
 
//主功能
func main() {
 
    // 寻找第零类第一类 Bessel函数
    //使用J0()函数
    nvalue_1 := math.J0(2.0)
    nvalue_2 := math.J0(4.1)
 
    // 给定数字的总和
    res := nvalue_1 + nvalue_2
    fmt.Printf("%.2f + %.2f = %.2f",
            nvalue_1, nvalue_2, res)
 
   
} 

输出:

0.22 + -0.39 = -0.16

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程