1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ D[f[x], x] or f'[x] or f'[1] gives you the derivatives of the real and imaginary parts simultaneously. $\endgroup$ – Αλέξανδρος Ζεγγ Oct 9 '18 at 8:15
  • $\begingroup$ How then can I extract, as a function, only the derivative of the imaginary part? $\endgroup$ – NeonGabu Oct 9 '18 at 8:20
1
$\begingroup$

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!

$\endgroup$
  • 2
    $\begingroup$ ComplexExpand[] will automatically assume real variables unless explicitly told otherwise. $\endgroup$ – J. M. will be back soon Oct 9 '18 at 10:17
2
$\begingroup$

Try

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

h[1]

2

$\endgroup$

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.