[GiNaC-list] real and imaginary parts of an expression
Richard B. Kreckel
kreckel at ginac.de
Mon May 28 22:05:32 CEST 2007
Martin DRUON wrote:
> #include <iostream>
> #include <ginac/ginac.h>
>
> using namespace GiNaC;
>
> int main(int argc, char **argv)
> {
> symbol x("x"), y("y"); // My complex number : x + iy
> symbol Q("Q"), a("a"); // Parameters
>
> // My expression
> ex f = (Q / 2 * Pi) * log(((x + I * y) - a) / ((x + I * y) + a));
>
> std::cout << f << std::endl;
>
> // f.real() -> How I can get real part ???
> // f.imag() -> How I can get imaginary part ???
>
> return EXIT_SUCCESS;
> }
>
> Is it possible easily ?
If write that x+I*y is your complex number, then you're most certainly
assuming that x and y are real. You should express that by declaring x
and y as objects of class realsymbol. I guess the same is true for Q and
a. By default, GiNaC assumes that symbols are complex!
With GiNaC 1.4 you can use ex::real_part() and ex::imag_part(). With
GiNaC 1.3, you'll have to use ex::conjugate(), as already pointed out by
Vladimir Kisil.
-richy.
--
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>
More information about the GiNaC-list
mailing list