3
$\begingroup$

Hi I just want to check my code is working properly as I am trying to rule out any errors.

I'm integrating 4 coupled ODE's that have real and imaginary terms, so I have 8 equations.

The section of code I'm worried about is where I separate real and imaginary terms.

dkai1BYdx3 = ComplexExpand[Delta1*kai1 + Delta2*kai3];
Kai1REAL = Re[dkai1BYdx3];
Kai1IMAG = Im[dkai1BYdx3];

Will this code separate the real and imaginary parts of dkaiBYdx3 correctly? It contains non trivial functions.

$\endgroup$
8
$\begingroup$

Re and Im make no assumptions about the domain of unbound symbols, so using them by themselves like this will not do what you appear to want. On the other hand, ComplexExpand assumes unbound symbols represent real numbers, and has rules to rewrite Reand Im. So, put them in the expression you're expanding:

Kai1REAL = ComplexExpand[Re[dkai1BYdx3]];
Kai1IMAG = ComplexExpand[Im[dkai1BYdx3]];
$\endgroup$
  • $\begingroup$ +1 For convenience one can also write {Kai1REAL, Kai1IMAG} = ComplexExpand[ReIm[dkai1BYdx3]] (V10.1 and upwards) or {Kai1REAL, Kai1IMAG} = ComplexExpand[Through[{Re,Im}[dkai1BYdx3]]] (before Version 10.1). $\endgroup$ – Thies Heidecke May 3 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.