Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

คำนวณโคไซน์ไฮเปอร์โบลิก (cosh) ใน Python ด้วย numpy.cosh()

เมธอด numpy.cosh() คำนวณโคไซน์ไฮเปอร์โบลิก เทียบเท่า 1/2 * (np.exp(x) + np.exp(-x)) และ np.cos(1j*x) คืนค่าสเกลาร์หาก x เป็นสเกลาร์

ขั้นตอนการใช้งาน

import numpy as np

คำนวณ cosh ค่าต่างๆ

print("Get the Trigonometric Hyperbolic cosine...")
print("\nResult...", np.cosh(np.pi*1j))
print("\nResult...", np.cosh(np.pi/2.))
print("\nResult...", np.cosh(np.pi/3.))
print("\nResult...", np.cosh(np.pi/4.))
print("\nResult...", np.cosh(np.pi/6.))
print("\nResult...", np.cosh(0))

โค้ดตัวอย่างสมบูรณ์

import numpy as np

print("Get the Trigonometric Hyperbolic cosine...")
print("\nResult...", np.cosh(np.pi*1j))
print("\nResult...", np.cosh(np.pi/2.))
print("\nResult...", np.cosh(np.pi/3.))
print("\nResult...", np.cosh(np.pi/4.))
print("\nResult...", np.cosh(np.pi/6.))
print("\nResult...", np.cosh(0))

ผลลัพธ์ที่คาดหวัง

Get the Trigonometric Hyperbolic cosine...
Result... (-1+0j)
Result... 2.5091784786580567
Result... 1.600286857702386
Result... 1.3246090892520057
Result... 1.1402383210764286
Result... 1.0