C Programming/complex.h/cpow

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Prototypes[edit | edit source]

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);

Description[edit | edit source]

Cpow is a library function in the C programming language, used to calculate powers in the field of complex numbers
It was added to the C programming language, together with complex number support, in the C99 standard.

Introduction[edit | edit source]

In mathematics, complex numbers are often denoted by 'z' .

   z = x + iy

In this number 'x' is the real part and 'y' is imaginary part. 'i' is imaginary unit, such that "i2 = -1 ".
Complex power is defined by the mathematical operation of exponentiation given by "z1z2" .
In C programming language , library function for this is given by Cpow.

Header File[edit | edit source]

Standard Library Header file : <complex.h>(complex arithmetic)

Syntax for function[edit | edit source]

  double complex cpow(double complex x, double complex y);

This function calculates the power of real number 'x' raised to y-th power ,where y is a complex number .
In mathematics ,by Euler's formula, eia = (cos a +i sin a).Here,cos and sin are trigonometric functions.
For xia,
xi .a = ei .a ln(x) = ( cos(a ln(x)) + i sin(a ln(x)) )  ; ln  : logarithmic function to the base e.

Return Value[edit | edit source]

   This function shall return the complex power function value.

Returns the complex power of base x raised to the y-th power using the principal branch, whose cuts are along the negative real axis.

Usage of Cpow function[edit | edit source]

//Program returns the complex number z3
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;