跳轉到內容

C 程式設計/complex.h/cpow

來自華夏公益教科書,開放的書籍,為開放的世界
double complex cpow(double complex x, double complex y);
float complex cpowf(float complex x, float complex y);
long double complex cpowl(long double complex x, long double complex y);


Cpow 是 C 程式設計 語言中的一個庫函式,用於計算複數域中的冪
它與複數支援一起被新增到 C 程式語言中,在 C99 標準中。

數學 中,複數通常用 'z' 表示。

   z = x + iy

在這個數字中,'x' 是實部,'y' 是虛部。'i' 是虛數單位,使得 "i2 = -1 "。
複數冪由給定的 "z1z2" 的指數運算定義。
C 程式語言 中,此庫函式由 Cpow 給出。

標頭檔案

[編輯 | 編輯原始碼]


標準庫標頭檔案 : <complex.h>(複數運算)

函式語法

[編輯 | 編輯原始碼]
  double complex cpow(double complex x, double complex y);


此函式計算實數 'x' 提高到 y 次冪的冪,其中 y 是一個複數。
在數學中,根據尤拉公式,eia = (cos a +i sin a)。這裡,cos 和 sin 是三角函式。
對於 xia
xi .a = ei .a ln(x) = ( cos(a ln(x)) + i sin(a ln(x)) )  ; ln  : 以 e 為底的對數函式。

返回值

[編輯 | 編輯原始碼]
   This function shall return the complex power function value.

使用主分支返回基數 x 提高到 y 次冪的複數冪,其割線沿負實軸。

Cpow 函式的使用

[編輯 | 編輯原始碼]
//Program returns the complex number z3
#include<stdio.h>
#include<complex.h>
#include<math.h>
int main()
{       int x, y, p, q;
        double complex z1, z2, z3; //complex variables declaration
        scanf("%d %d %d %d", &x, &y, &p, &q);
        z1 = (p + q * I);
        z2 = (x + y * I);
        z3 = cpow (z2, z1);
        printf("%f + %f * i\n", creal(z3), cimag(z3));
        return 0;
}
華夏公益教科書