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$
3
  • $\begingroup$ D[f[x], x] or f'[x] or f'[1] gives you the derivatives of the real and imaginary parts simultaneously. $\endgroup$ Commented Oct 9, 2018 at 8:15
  • $\begingroup$ How then can I extract, as a function, only the derivative of the imaginary part? $\endgroup$
    – NeonGabu
    Commented Oct 9, 2018 at 8:20
  • $\begingroup$ mathematica.stackexchange.com/a/4099/69835 $\endgroup$
    – lotus2019
    Commented Jun 20, 2023 at 22:11

2 Answers 2

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$
1
  • 2
    $\begingroup$ ComplexExpand[] will automatically assume real variables unless explicitly told otherwise. $\endgroup$ Commented Oct 9, 2018 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$
1
  • $\begingroup$ Hi. The code failed in v13. $\endgroup$
    – lotus2019
    Commented Jun 20, 2023 at 22:09

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.