complex 中文man頁面
名字
complex - 基礎(chǔ)復(fù)數(shù)數(shù)學(xué)
概要
#include <complex.h>
描述
復(fù)數(shù)是一種形如 z = a + b*i,這里的 a 和 b 都是實(shí)數(shù)且 i = sqrt(-1),因此 i*i = -1。
還存在其它表達(dá)這種數(shù)的方式。一個(gè)實(shí)數(shù)對(a, b) 被看作是水平面的一個(gè)點(diǎn),此時(shí)給定了 X 和 Y 軸值。相同的點(diǎn)也可以通過給定一個(gè)實(shí)數(shù)對 (r, phi) 來確定,此時(shí) r 是點(diǎn)到原點(diǎn) O 的距離,而 phi 是線 Oz 與 X 軸的夾角。如此 z = r*exp(i*phi) = r*(cos(phi)+i*sin(phi))。
對 z = a+b*i 和 w= c+d*i 的基本操作定義如下:
- 加法: z+w = (a+c) + (b+d)*i
- 乘法: z*w = (a*c - b*d) + (a*d + b*c)*i
- 除法: z/w = ((a*c + b*d)/(c*c + d*d)) + ((b*c - a*d)/(c*c + d*d))*i
幾乎所有的數(shù)學(xué)函數(shù)都有復(fù)數(shù)的對應(yīng)版本但卻有復(fù)數(shù)特有的函數(shù)。
示例
如果的你的 C 編譯器支持 C99 標(biāo)準(zhǔn)則它就可以與復(fù)數(shù)一些工作,此時(shí)需要鏈接 -lm 選項(xiàng)。虛單位使用 I 表示。
/* 檢測 exp(i * pi) == -1 */ #include <math.h> /* for atan */ #include <stdio.h> #include <complex.h> int main(void) { double pi = 4 * atan(1.0); double complex z = cexp(I * pi); printf("%f + %f * i\n", creal(z), cimag(z)); }
參看
cabs(3)、carg(3)、cexp(3)、cimag(3)、creal(3)
#p#
NAME
complex - basics of complex mathematics
SYNOPSIS
#include <complex.h>
DESCRIPTION
Complex numbers are numbers of the form z = a+b*i, where a and b are real numbers and i = sqrt(-1), so that i*i = -1.
There are other ways to represent that number. The pair (a,b) of real numbers may be viewed as a point in the plane, given by X- and Y-coordinates. This same point may also be described by giving the pair of real numbers (r,phi), where r is the distance to the origin O, and phi the angle between the X-axis and the line Oz. Now z = r*exp(i*phi) = r*(cos(phi)+i*sin(phi)).
The basic operations are defined on z = a+b*i and w = c+d*i as:
- addition: z+w = (a+c) + (b+d)*i
- multiplication: z*w = (a*c - b*d) + (a*d + b*c)*i
- division: z/w = ((a*c + b*d)/(c*c + d*d)) + ((b*c - a*d)/(c*c + d*d))*i
Nearly all math function have a complex counterpart but there are some complex only functions.
EXAMPLE
Your C-compiler can work with complex numbers if it supports the C99 standard. Link with -lm. The imaginary unit is represented by I.
/* check that exp(i*pi) == -1 */ #include <math.h> /* for atan */ #include <complex.h> main() { double pi = 4*atan(1); complex z = cexp(I*pi); printf("%f+%f*i\n", creal(z), cimag(z)); }
SEE ALSO
cabs(3), carg(3), cexp(3), cimag(3), creal(3)