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

คำนวณไฮเปอร์โบลิกโคไซน์ใน Python


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

พารามิเตอร์ตัวที่ 2 คือ ndarray ซึ่งเป็นตำแหน่งที่เก็บผลลัพธ์ หากมีให้ต้องมีรูปร่างที่อินพุตออกอากาศไป หากไม่ระบุหรือไม่มี ระบบจะส่งคืนอาร์เรย์ที่จัดสรรใหม่

พารามิเตอร์ที่ 3 คือเงื่อนไขที่ออกอากาศผ่านอินพุต ที่ตำแหน่งที่เงื่อนไขเป็น True อาร์เรย์ out จะถูกตั้งค่าเป็นผลลัพธ์ ufunc ที่อื่น Out Array จะคงค่าเดิมไว้

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

import numpy as np

รับโคไซน์ตรีโกณมิติไฮเปอร์โบลิก ค้นหา cosh -

print("\nResult...",np.cosh(np.pi*1j))

การหา cosh 90 องศา −

print("\nResult...",np.cosh(np.pi/2.))

การหา cosh 60 องศา −

print("\nResult...",np.cosh(np.pi/3.))

การหา cosh 45 องศา −

print("\nResult...",np.cosh(np.pi/4.))

การหา cosh 30 องศา −

print("\nResult...",np.cosh(np.pi/6.))

หา cosh 0 องศา −

print("\nResult...",np.cosh(0))

ตัวอย่าง

import numpy as np

# To compute the Hyperbolic cosine, use the numpy.cosh() method in Python Numpy
# The method is equivalent to 1/2 * (np.exp(x) + np.exp(-x)) and np.cos(1j*x).

print("Get the Trigonometric Hyperbolic cosine...")

# find cosh
print("\nResult...",np.cosh(np.pi*1j))

# finding cosh 90 degrees
print("\nResult...",np.cosh(np.pi/2.))

# finding cosh 60 degrees
print("\nResult...",np.cosh(np.pi/3.))

# finding cosh 45 degrees
print("\nResult...",np.cosh(np.pi/4.))

# finding cosh 30 degrees
print("\nResult...",np.cosh(np.pi/6.))

# finding cosh 0 degrees
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