在 Golang 中查詢指定數字的反雙曲餘弦


Golang 是一種靜態型別的編譯型程式語言,因其簡單性、併發支援和垃圾回收而受到開發人員的歡迎。在本文中,我們將討論如何在 Golang 中查詢指定數字的反雙曲餘弦。

反雙曲餘弦函式用於查詢其雙曲餘弦等於給定數字的角度。它表示為 acosh(x),其中 x 是輸入值。

Golang 提供了 math 包,其中包含各種數學函式,包括反雙曲餘弦函式。我們可以使用 math.Acosh() 函式在 Golang 中查詢指定數字的反雙曲餘弦。

語法

使用 math.Acosh() 函式的語法如下:

func Acosh(x float64) float64

Acosh() 函式以 float64 值作為輸入,並將其反雙曲餘弦作為 float64 值返回。

示例 1

讓我們舉一個例子來了解如何在 Golang 中使用 Acosh() 函式。

package main

import (
   "fmt"
   "math"
)

func main() {
   x := 1.5

   // Finding Inverse Hyperbolic Cosine of x
   result := math.Acosh(x)

   fmt.Printf("Inverse Hyperbolic Cosine of %.2f is %.2f", x, result)
}

輸出

Inverse Hyperbolic Cosine of 1.50 is 0.96

在上面的示例中,我們使用了 math.Acosh() 函式來查詢 1.5 的反雙曲餘弦。輸出為 0.96

示例 2

package main

import (
   "fmt"
   "math"
)

func main() {
   x := 3.14
   y := 1 / math.Sqrt(x*x-1)
   result := math.Log(x + y)

   fmt.Printf("The inverse hyperbolic cosine of %.2f is %.2f\n", x, result)
}

輸出

The inverse hyperbolic cosine of 3.14 is 1.25

在這個例子中,我們首先將 x 的值定義為 3.14。然後,我們使用公式 1 / sqrt(x^2 - 1) 計算 y 的值。最後,我們使用公式 ln(x + y) 計算 x 的反雙曲餘弦,並將結果儲存在變數 result 中。然後,我們使用 fmt.Printf 函式打印出結果。

結論

在本文中,我們討論瞭如何在 Golang 中使用 math.Acosh() 函式查詢指定數字的反雙曲餘弦。我們還提供了一個示例來說明如何在 Golang 中使用此函式。

更新於: 2023年4月12日

96 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.