4
$\begingroup$

I have some problem with the derivative of the 'conjugate' expression: Here I define the functions:

f[x_, y_] := x + I y;
g[x_, y_] := x + 3 I y y;
h[x_, y_] := Derivative[0, 1][f[#, #2]\[Conjugate]/g[#, #2] &][x, y]

When I try to evaluate one of the expression, for example

h[1, 1]

I got something like

Derivative[1][Conjugate][1 + I]

which is not true. If I try the code suggested in Derivative of conjugate multivariate function

 excluded = 
 "ExcludedFunctions" /. ("DifferentiationOptions" /. 
    SystemOptions["DifferentiationOptions"])
SetSystemOptions[
 "DifferentiationOptions" -> 
  "ExcludedFunctions" -> Union[excluded, {Conjugate}]]

I got the error

  General::ivar: 1 is not a valid variable.
$\endgroup$
  • 1
    $\begingroup$ I usually DIY my own "conjugate" by an explicit replacement rule. $\endgroup$ – Αλέξανδρος Ζεγγ Dec 12 '18 at 7:32
  • $\begingroup$ Could you please show this on the example written above $\endgroup$ – Chipa-Chipa Dec 12 '18 at 7:41
  • $\begingroup$ I decided so because I think it not good enough to be posted. $\endgroup$ – Αλέξανδρος Ζεγγ Dec 12 '18 at 8:50
  • $\begingroup$ Well, I hope it helps. $\endgroup$ – Αλέξανδρος Ζεγγ Dec 12 '18 at 8:55
1
$\begingroup$

Update

I am sorry, the old answer does not work, but it seems that the rule cannot be applied to pure functions.

A working way is, provided that all symbols are deemed real, which is what ComplexExpand does:

f[x_, y_] = ComplexExpand[ (*Expressions containing Conjugate*) ];
h[x_, y_] := Derivative[0, 1][f[#, #2]/g[#, #2] &][x, y]

h[x, y]
h[1, 1]
-((6 I (x - I y) y)/(x + 3 I y^2)^2) - I/(x + 3 I y^2)

-(9/50) + (37 I)/50

Old

It is long since I made the observation that Mathematica seems not to know what to do when Conjugate meets D.

$\endgroup$
  • $\begingroup$ thx. I have already noticed that your first suggested example gives the wrong answer. Will your second example decrease the calculation rate? I have a very large amount of functions and need to do rather complex calculations. Is it possible not to replace all the functions like 'f[x,y][Conjugate]' by 'Evaluate[ComplexExpand[f[x, y][Conjugate]]]'? $\endgroup$ – Chipa-Chipa Dec 12 '18 at 8:24
  • $\begingroup$ @Chipa-Chipa Then I suggest that you do not use a pure function in the middle of Derivative, but use the explicit form of the function you want to go further. $\endgroup$ – Αλέξανδρος Ζεγγ Dec 12 '18 at 8:27
  • $\begingroup$ Do you mean that I should make the replacement only when I define the derivative? $\endgroup$ – Chipa-Chipa Dec 12 '18 at 8:31
  • $\begingroup$ @Chipa-Chipa I mean to obtain the explicit expression of the function, before you put it into its derivative calculation. $\endgroup$ – Αλέξανδρος Ζεγγ Dec 12 '18 at 8:33
  • 1
    $\begingroup$ I think the problem with your original way was a misplaced Evaluate. Try myConjugate = # /. {I -> -I, -I -> I} &; h[x_, y_] := Derivative[0, 1][Evaluate[myConjugate[f[#, #2]]/g[#, #2]] &][x, y] $\endgroup$ – Michael E2 Jan 11 at 19:54
0
$\begingroup$

Another workaround. Looks like the Derivative format doesn't like conjugate, but this seems to work:

f[x_, y_] := x + I y;
g[x_, y_] := x + 3 I y y;

h[x_, y_] := D[Conjugate[f[x, yy]]/g[x, yy], yy] /. yy -> y

h[1, 1] // ComplexExpand
(*-(9/50) + (37 I)/50*)
$\endgroup$
0
$\begingroup$

Here are three similar ways. The first seems best (simplest) to me:

ClearAll[h];
Block[{x, y},
 h[x_, y_] = D[ComplexExpand[f[x, y]\[Conjugate]/g[x, y]], y];
 ]

h[x, y] // Simplify
(*  -((I (x + 6 x y - 3 I y^2))/(x + 3 I y^2)^2)  *)

The following one generates message every time h[x, y] is evaluated, but it seems to give the correct answer. The reason for the messages is interesting, because it implies a potential pitfall in using ComplexExpand: It appears the internal code for ComplexExpand[] creates a function with & using its arguments. The Slot[] expressions in f[#, #2] and g[#, #2] get caught up in this and lead to error messages; but the internal code seems to recover in this case. (Perhaps it should be considered a bug?)

ClearAll[h];
h[x_, y_] := Derivative[0, 1][Evaluate@ComplexExpand[f[#, #2]\[Conjugate]/g[#, #2]] &][x, y]

One could also do something like this:

ClearAll[h];
h[x_, y_] := 
 Derivative[0, 1][
   Block[{xx, yy}, 
    Function[{xx, yy}, 
     Evaluate@ComplexExpand[f[xx, yy]\[Conjugate]/g[xx, yy]]]]][x, y];
$\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.