หากต้องการคำนวณไซน์ไฮเปอร์โบลิก (Hyperbolic sine) ให้ใช้เมธอด numpy.sinh() ในไลบรารี NumPy ของ Python เมธอดนี้เทียบเท่ากับสูตร 1/2 * (np.exp(x) - np.exp(-x)) หรือ -1j * np.sin(1j*x) ผลลัพธ์ที่ได้คือค่าไซน์ไฮเปอร์โบลิกที่ตรงกัน หาก x เป็นสเกลาร์ ผลลัพธ์ก็จะเป็นสเกลาร์เช่นกัน
พารามิเตอร์สำคัญ
- x (พารามิเตอร์แรก): อาร์เรย์อินพุต
- out (พารามิเตอร์ที่สอง - ไม่บังคับ): ตำแหน่งที่เก็บผลลัพธ์ ต้องมีรูปร่างที่สามารถ broadcast ได้จากอินพุต หากไม่ระบุ จะสร้างอาร์เรย์ใหม่
- where (พารามิเตอร์ที่สาม - ไม่บังคับ): เงื่อนไขที่ broadcast ไปยังอินพุต ที่เงื่อนไขเป็น True จะตั้งค่าผลลัพธ์ ufunc ที่เหลือจะเก็บค่าเดิม
ขั้นตอนการใช้งาน
เริ่มต้นด้วยการนำเข้าไลบรารีที่จำเป็น:
import numpy as np
ตัวอย่างการคำนวณค่า sinh ต่างๆ
# หา sinh ของ π * 1j
print("\nResult...", np.sinh(np.pi*1j))
# หา sinh 90 องศา (π/2 เรเดียน)
print("\nResult...", np.sinh(np.pi/2.))
# หา sinh 60 องศา (π/3 เรเดียน)
print("\nResult...", np.sinh(np.pi/3.))
# หา sinh 45 องศา (π/4 เรเดียน)
print("\nResult...", np.sinh(np.pi/4.))
# หา sinh 30 องศา (π/6 เรเดียน)
print("\nResult...", np.sinh(np.pi/6.))
# หา sinh 0 องศา
print("\nResult...", np.sinh(0))
โค้ดตัวอย่างสมบูรณ์
import numpy as np
print("Get the Trigonometric Hyperbolic sine...")
# find sinh
print("\nResult...", np.sinh(np.pi*1j))
# finding sinh 90 degrees
print("\nResult...", np.sinh(np.pi/2.))
# finding sinh 60 degrees
print("\nResult...", np.sinh(np.pi/3.))
# finding sinh 45 degrees
print("\nResult...", np.sinh(np.pi/4.))
# finding sinh 30 degrees
print("\nResult...", np.sinh(np.pi/6.))
# finding sinh 0 degrees
print("\nResult...", np.sinh(0))
ผลลัพธ์ที่คาดหวัง
Get the Trigonometric Hyperbolic sine... Result... (-0+1.2246467991473532e-16j) Result... 2.3012989023072947 Result... 1.2493670505239751 Result... 0.8686709614860095 Result... 0.5478534738880397 Result... 0.0