# Working with complex valued functions

I have a function which has real and imaginary parts and I need to differentiate both parts separately. This is a simpler example of what I have tried, without success:

f[x_] = x^2 + I x^3
g[x_] = Re[f[x]]
h[x_] = g'[x]


but h[1] gives me -3 Im'[1] + 2 Re'[1]

How can I find such derivatives?

• D[f[x], x] or f'[x] or f'[1] gives you the derivatives of the real and imaginary parts simultaneously. Oct 9, 2018 at 8:15
• How then can I extract, as a function, only the derivative of the imaginary part? Oct 9, 2018 at 8:20

Mma does not know in advance if x is real, or complex. Indeed, if one defines your function and tries to get its real part:

f[x_] := x^2 + I x^3
Re[f[x]]

(* -Im[x^3] + Re[x^2] *)


Mma returns the result as if x were complex. One can use the functionality of Simplify, to fix it:

Simplify[ Re[f[x]], x \[Element] Reals]
Simplify[ Im[f[x]], x \[Element] Reals]

(*  x^2

x^3   *)


There is, however another way, that may seem you comfortable. Assuming f[x], has already been defined, let us define its imaginary and real parts as follows:

    Ref[x_] := (List @@ f[x])[[1]]
IImf[x_] := (List @@ f[x])[[2]]


Then

    D[Ref[x], x]
D[IImf[x], x]

(*  2 x

3 I x^2  *)


Have fun!

• ComplexExpand[] will automatically assume real variables unless explicitly told otherwise. Oct 9, 2018 at 10:17

Try

f[x_] := x^2 + I x^3
g[x_] := Re[f[x]]
h[x_] = g'[x] // ComplexExpand

h[1]


2