简体   繁体   中英

Find exponential of a complex number

I want to calculate the exponential of a complex number such as 2+3i .

I already know this formula

exp( i z ) = cos(z) + i sin(z)

Is there a built-in function in OpenCV? If yes, could you please explain it to me with an example?

I think the function you're looking for is atan2 . For example, for the number 2+3i , you would compute the angle as

T = atan2( 3.0, 2.0 );

What's wrong with the cexp( ) function declared in complex.h ? Why do you want to use OpenCV instead of the standard library?

#include <complex.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
    double complex z = 2 + 3*I;
    double complex w = cexp(z);
    printf("%f + %fi\n", creal(w), cimag(w));
    return 0;
}

If you're targeting a platform that doesn't provide complex types or operations, you can use the following for a quick-and-dirty solution:

struct mycomplex { double real; double imag; }

struct mycomplex my_exp(struct mycomplex z) {
    struct mycomplex w;
    w.real = exp(z.real)*cos(z.imag);
    w.imag = exp(z.real)*sin(z.imag);
    return w;
}

And finally, since you're using MSVC, a very rudimentary C++ example:

#include <complex>
#include <iostream>

int main(int argc, char *argv[]) {
    auto z = std::complex<double>(2,3);
    auto w = std::exp(z);
    std::cout << w << std::endl;
    return 0;
}

i dont think there is any inbuild function in c to solve this. in fact when we were doing FFT transform in c, we used the basic cos + jsin version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM