Reputation: 863
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?
Upvotes: 0
Views: 2286
Reputation: 106267
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;
}
Upvotes: 2
Reputation: 34839
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 );
Upvotes: 1
Reputation: 12272
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
Upvotes: 0