1

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
NeonGabu
  • 115
  • 3

2 Answers2

2

Try

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

h[1]

2

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
1

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!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96