3
$\begingroup$

Sometimes it is useful to split a complex equation into its real and imaginary parts. Consider the following ode

ode = y'''[x] - k^3*y[x] == I*k*a*((2*x - c)*(y''[x] - k^2*y[x]) + 2*y[x])
bc1 = y'[0] == 0;
bc2 = y''[1] + k^2*y[1]/(1 - c) == 0;

in which y[x] is a complex function with a real independent variable x, $a$ is a real parameter, and $k$ and $c$ are complex parameters. If we write y[x]=yr[x]+I yi[x], k=kr+ I ki, and c=cr+I ci, how can I transfer the system in terms of two real equations odereal and odeimag togeter with their boundary conditions bc1real, bc1imag, bc2real, bc2imag.

For example,

y[x_] := yr[x] + I*yi[x]
bc1 /. y -> y[x]
(*I Derivative[1][yi][0] + Derivative[1][yr][0] == 0*)

Problem: We can see that the real and imaginary parts still are written together in the boundary condition. Note also that I did not need to solve the equation at present. What I want is, for example,

bc1real = Derivative[1][yr][0] == 0
bc1imag = Derivative[1][yi][0] == 0

with a similar split-form for the ode and bc2. Thank you for any suggestions.

$\endgroup$

1 Answer 1

1
$\begingroup$

Splitting complex equations (or expressions) into real and imaginary parts

Uses: I, Re, Im, Assumptions, Alternatives (|), Element, Simplify, Map

I find this comes up most most often with equations. So will illustrate it that way. I just made up the equation below. Key idea is that a and c are assumed real. It's usually the case that I occurs explicitly.

exampleComplexEquation = Expand[(a + I)^4 + 2 a^2 == 30 + 40*c*I];


exampleComplexEquation2 = a + b*I == 3 + 4 I;

Two functions are defined as below. Look up Element to understand acceptable values for arg. These functions are meant to illustrate an approach.

realPart[ex_, arg_] := 
 Simplify[Map[Re, ex], Assumptions -> Element[arg, Reals]]

imagPart[ex_, arg_] := 
 Simplify[Map[Im, ex], Assumptions -> Element[arg, Reals]]

And an example of use. The functions are meant as examples rather than complete solutions.

realEquation = realPart[exampleComplexEquation, a | c]
  a^4 == 29 + 4 a^2
imagEquation = imagPart[exampleEquation, a | c]
  a^3 == a + 10 c

You can also use Solve directly in some cases. The syntax for Element here is a bit different.

Solve[exampleComplexEquation2 && Element[{a, b}, Reals], {a, b}]
  {{a -> 3, b -> 4}}
exampleComplexEquation3 = (a + 2*b*I)^2 == 3 + 4*I;

Solve[exampleComplexEquation3 && Element[{a, b}, Reals], {a, b}]
   {{a -> -2, b -> -(1/2)}, {a -> 2, b -> 1/2}}

Hope this helps lead you down a productive road.

$\endgroup$
1
  • $\begingroup$ your approach is informative but it is cannot deal with a simple ode with an exponential. e.g. extending func definition: realPart[eq_, real_, imag_] := Simplify[Map[Re, eq], Assumptions -> Element[real, Reals] && Element[imag,Complexes]]; imagPart[eq_, real_, imag_] := Simplify[Map[Im, eq], Assumptions -> Element[real, Reals] && Element[imag, Complexes]]; testing with ode = Expand[I*(y''[x] + k^2) + a == 0], realode = realPart[ode, x | a, y | k] gives a == Im[k^2] + Im[(y^\[Prime]\[Prime])[x]]. Well, it is expected to yield a == 2 Re[k] Im[k] + Im[(y^\[Prime]\[Prime])[x]]. $\endgroup$
    – Nobody
    Commented Jul 7, 2020 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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