real and imaginary parts of an expression
hello, I would like to know how I can get the real part and the imaginary part of an expression (GiNaC::ex)... for example : #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 ? Thanks Martin
"MD" == Martin DRUON <martin.druon@wanadoo.fr> writes: MD> hello, I would like to know how I can get the real part and the MD> imaginary part of an expression (GiNaC::ex)...
You may use the method conjugate(): the expression (e+e.conjugate())/2 will give you (in most cases) the real part of e. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
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/>
participants (3)
-
Martin DRUON
-
Richard B. Kreckel
-
Vladimir Kisil