1
$\begingroup$

Consider a complex function y with a real argument x and the function y itself is an argument of another function f, which takes the 2nd-derivative of y with respect to x

f[y_] := y''[x]

It seems that ComplexExpand gives the right answer

ComplexExpand[f[yr + I*yi]]

(*((I yi + yr)^\[Prime]\[Prime])[x]*)

Well, when I try to extract its real and imaginary parts separately, the following approaches failed.

ComplexExpand[Re@f[yr + I*yi]]
(*((I yi + yr)^\[Prime]\[Prime])[x]*)

Re@ComplexExpand[f[yr + I*yi]]

(*Re[((I yi + yr)^\[Prime]\[Prime])[x]]*)

ComplexExpand[f[yr + I*yi]] // Re

(*Re[((I yi + yr)^\[Prime]\[Prime])[x]]*)

I expect to obtain something like yr''[x] and yi''[x] for the real and imaginary parts.

Can anyone help with this?

$\endgroup$
4
  • 2
    $\begingroup$ First line is: "f with a real argument". But then 4th line shows f taking yr + I yi. Please elaborate. $\endgroup$ Jul 7, 2020 at 17:57
  • $\begingroup$ Note also that your first ComplexExpand expression accomplishes nothing: f[yr + I*yi] == ComplexExpand[f[yr + I*yi]]. $\endgroup$
    – MarcoB
    Jul 7, 2020 at 22:45
  • $\begingroup$ @PaulCommentary sorry, I was so careless. I meant y has a real argument x, and another function f takes derivative of y w.r.t. x. Please see my update. $\endgroup$
    – Nobody
    Jul 8, 2020 at 2:08
  • $\begingroup$ @MarcoB Ha... I just want to take the derivative of y[x]=yr[x]+i*yi[x] w.r.t. $x \in R$ and get y'[x]=yr'[x]+i*yi'[x] for example. $\endgroup$
    – Nobody
    Jul 8, 2020 at 2:13

1 Answer 1

3
$\begingroup$

You have to tell Mathematica what symbols are functions, by explicitly stating them with an argument. Say you have a "function" $f: \mathbb{R} \rightarrow \mathbb{R}$ and you try

D[f, x]
(* 0 *)

Since Mathematica does not know that f is a "function". However, the following gives the desired output

D[f[x], x]
(* f'[x] *)

For your problem my recommended way to go would be via pure functions, e.g.

ClearAll[f]
f[y_, x_] := y''[x]
f[Function[{x}, yr[x] + I yi[x]], x]
(* I (yi^\[Prime]\[Prime])[x] + (yr^\[Prime]\[Prime])[x] *)

instead of Function you could also use the lambda-style syntax where the arguments are denoted by Slots (#) and the function is finalized by a &, e.g.

#^2&[x] == Function[{x}, x^2][x]
(* True *)
$\endgroup$

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.