名字
complex - 基础复数数学
概要
#include <complex.h>
描述
复数是一种形如 z = a + b*i,这里的 a 和 b 都是实数且 i = sqrt(-1),因此 i*i = -1。
还存在其它表达这种数的方式。一个实数对(a, b) 被看作是水平面的一个点,此时给定了 X 和 Y 轴值。相同的点也可以通过给定一个实数对 (r, phi) 来确定,此时 r 是点到原点 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
几乎所有的数学函数都有复数的对应版本但却有复数特有的函数。
示例
如果的你的 C 编译器支持 C99 标准则它就可以与复数一些工作,此时需要链接 -lm 选项。虚单位使用 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)