如何在Golang中查詢給定值的雙曲反正弦?
在本教程中,我們將學習如何在Golang程式語言中查詢給定值的雙曲反正弦。Golang語言有很多包,其中包含預定義函式,開發者可以使用這些函式而無需編寫完整的邏輯。
為了執行數學運算和邏輯,Golang中有一個math包。我們只使用這個包來查詢給定值的雙曲反正弦。我們還將看到如何匯入包,以及如何透過編寫Golang程式碼來呼叫該包包含的函式。
雙曲反正弦
定義
雙曲反正弦是一個類似於三角函式的函式。雙曲反正弦等於三角函式的類似物。雙曲反正弦的公式如下所示,雙曲反正弦在不同角度的值也不同。
語法
asinh(x) = ln(x + √x^2 + 1)
圖形

雙曲反正弦在不同角度的值
asinh(0) = 0
asinh(30) = 4.094622224331
asinh(45) = 4.499933104264
asinh(60) = 4.787561179994
asinh(90) = 5.192987713659
演算法
步驟1 - 宣告變數以儲存float32型別的值和結果。
步驟2 - 初始化變數的值。
步驟3 - 呼叫雙曲反正弦函式並傳遞值。
步驟4 - 列印結果。
示例
在這個例子中,我們將編寫一個Golang程式,在這個程式中我們將匯入一個math包並呼叫雙曲反正弦函式。
package main
import (
// fmt package provides the function to print anything
"fmt"
// math package provides multiple functions for different
// mathematical operations
"math"
)
func main() {
// declaring the variables to store the value of \value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc sine of a given value in the Golang programming language using a math package.")
// initializing the value of the variable value
value = 4.5
// finding Hyperbolic Arc sine for the given value
answer = math.Asinh(value)
// printing the result
fmt.Println("The Hyperbolic Arc sine value with the value of", value, "is", answer)
}
輸出
Program to find the Hyperbolic Arc sine of a given value in the Golang programming language using a math package. The Hyperbolic Arc sine value with the value of 4.5 is 2.209347708615334
演算法
步驟1 - 宣告變數以儲存float32型別的值和結果。
步驟2 - 初始化變數的值。
步驟3 - 呼叫我們定義的雙曲反正弦函式,並將值作為引數傳遞
步驟4 - 列印結果。
示例
在這個例子中,我們將編寫一個Golang程式,在這個程式中我們將匯入一個math包,在一個單獨的函式中呼叫雙曲反正弦函式,然後在主函式中呼叫該函式。
package main
import (
// fmt package provides the function to print anything
"fmt"
// math package provides multiple functions for different
// mathematical operations
"math"
)
// this is a function with a parameter of float64 type and a return type of float64
func HyperbolicArcSine(angle float64) float64 {
// returning the Hyperbolic Arc Sine of the angle
return math.Asinh(angle)
}
func main() {
// declaring the variables to store the value of value and answer
var value, answer float64
fmt.Println("Program to find the Hyperbolic Arc Sine of a given value in the Golang programming language using a separate function in the same program.")
// initializing the value of the value
value = 1
// finding Hyperbolic Arc sine for the given value in a separate function
answer = HyperbolicArcSine(value)
// printing the result
fmt.Println("The Hyperbolic Arc Sine value with the value of", value, "is", answer)
}
輸出
Program to find the Hyperbolic Arc Sine of a given value in the Golang programming language using a separate function in the same program. The Hyperbolic Arc Sine value with the value of 1 is 0.8813735870195432
結論
這兩種方法都是使用math包中的函式並將值作為引數傳遞來查詢雙曲反正弦的方法。第二種方法將為程式提供抽象。要了解更多關於Golang的資訊,您可以瀏覽這些教程。
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP