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

ฟังก์ชัน sinh() สำหรับจำนวนเชิงซ้อน (Complex Number) ใน C++

บทความนี้สาธิตการใช้งานฟังก์ชัน sinh() (ไฮเปอร์บอลิกไซน์) สำหรับจำนวนเชิงซ้อนใน C++ ฟังก์ชันนี้อยู่ในเฮดเดอร์ <complex> ใช้คำนวณค่า hyperbolic sine ของจำนวนเชิงซ้อน

ไวยากรณ์ (Syntax)

template<class T> complex<T> sinh(const complex<T>& x);

พารามิเตอร์

x – จำนวนเชิงซ้อนที่ต้องการคำนวณ (พารามิเตอร์บังคับ)

ประเภทค่าที่ส่งคืน

ส่งคืนค่าจำนวนเชิงซ้อน (complex value) เป็นผลลัพธ์ของ sinh(x)

ตัวอย่าง Input/Output

InputOutput
sinh(0, 1)(0, 0.84147)
sinh(1, 9)(-1.0707, 0.6359)

ตัวอย่างโค้ดที่ 1

#include <iostream>
#include <complex>
using namespace std;

int main() {
    complex<double> x(2, 7);  // 2 + 7i
    cout << "The sinh of " << x << " = " << sinh(x) << endl;
    return 0;
}

ผลลัพธ์

The sinh of (2,7) = (2.734,2.4717)

ตัวอย่างโค้ดที่ 2

#include <iostream>
#include <complex>
using namespace std;

int main() {
    complex<double> x(5, 3);  // 5 + 3i
    cout << "The sinh of " << x << " = " << sinh(x) << endl;
    return 0;
}

ผลลัพธ์

The sinh of (5,3) = (-73.4606,10.4725)

พื้นฐานทางคณิตศาสตร์

สำหรับจำนวนเชิงซ้อน z = x + yi สูตร hyperbolic sine คือ:

sinh(z) = sinh(x)cos(y) + i·cosh(x)sin(y)

โดยที่:

  • sinh, cosh – ฟังก์ชันไฮเปอร์บอลิก
  • sin, cos – ฟังก์ชันตรีโกณมิติทั่วไป

ความแตกต่างระหว่าง sin() และ sinh()

ฟังก์ชันสูตร (z = x + yi)ประเภท
sin(z)sin(x)cosh(y) + i·cos(x)sinh(y)ตรีโกณมิติ
sinh(z)sinh(x)cos(y) + i·cosh(x)sin(y)ไฮเปอร์บอลิก

ฟังก์ชันที่เกี่ยวข้องใน <complex>

  • cosh() – ไฮเปอร์บอลิกโคไซน์
  • tanh() – ไฮเปอร์บอลิกแทนเจนต์
  • asin(), asinh() – ฟังก์ชันผกวน