       Re: Abs and derivative problems

• To: mathgroup at smc.vnet.net
• Subject: [mg14657] Re: Abs and derivative problems
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Sat, 7 Nov 1998 02:10:05 -0500
• Organization: University of Western Australia
• References: <71q9qu\$j25@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```sylvan wrote:

> I could not calculate the modulus of  a complex expression containing
> imaginary parts in both denominator and numerator with Mathematica. An
> Example:
>
> (a + I b) / (c + I d)
>
> a,b,c,d (real) symbolic variables.
>
> In pratice, this should be absolutely trivial. ComplexExpand is not
> effective.
> How do you "tell" mathematica that your variables are real ??

Actually, in the trivial example above, you can use

ComplexExpand[(a + I b) / (c + I d), TargetFunctions->{Re,Im}]

to get what you want.

> I included an example below (cell format, you can cut and paste).

In the Notebook fragment below, I show a simple trick for computing the
complex conjugate of complex expressions with real variables.  The
basic idea is to compute the conjugate using the replacement

Complex[a_, b_] :> Complex[a, -b]

actually implemented using the built-in SuperStar function (so that you
can compute conjugates by raising them to the power *):

SuperStar[x_] := x /. Complex[a_, b_] :> Complex[a, -b]

The point then is that Abs[z]^2 = SuperStar[z] z which enables you to
quickly and efficiently compute the type of expression you want.

Notebook[{
Cell[BoxData[
\`\(exp =
\(b0\ \[CapitalDelta]z\
\((Es - \[ImaginaryI]\ \[Eta]\ \[Omega])\)\)\/\(\(-m\)\
\[Omega]\^2 + m\ \[Omega] -
\[ImaginaryI]\ m\ \[Gamma]\ \[Omega] +
b0\ \((Es - \[ImaginaryI]\ \[Eta]\ \[Omega])\)\); \)\)],
"Input"],

Cell[BoxData[
\`\(x_\^*\) := x /. Complex(a_, b_) \[RuleDelayed] Complex(a,
\(-b\))\)],
"Input"],

Cell[CellGroupData[{

Cell[BoxData[
\(TraditionalForm\`\(\(exp\^*\) exp // ExpandAll\) // Simplify\)],
"Input"],

Cell[BoxData[
\`\(b0\^2\ \[CapitalDelta]z\^2\
\((Es\^2 + \[Eta]\^2\ \[Omega]\^2)
\)\)\/\(\((Es\^2 + \[Eta]\^2\ \[Omega]\^2)\)\ b0\^2 +
2\ m\ \[Omega]\
\((\(-\[Omega]\)\ Es + Es + \[Gamma]\ \[Eta]\ \[Omega])\)\ b0
+
m\^2\ \((\[Gamma]\^2 + \((\[Omega] - 1)\)\^2)\)\
\[Omega]\^2\)\)],
"Output"]
}, Open  ]]
}
]

> Also,  replacement rules like  //. z[t_] -> t^2 do not work well on
> expressions like  z'[t] + b z[t]. the result  is  z'[t] + b t^2... I
> could not force it to Evaluate z'[t] or D[z[t], t].

One simple, general, and reasonably elegant way is to use pure
functions, e.g.,

z'[t] + b z[t] /. z -> Function[{t}, t^2]

Another is to explicitly compute all derivatives:

rule = z[t] -> t^2;

z'[t] + b z[t] /. {rule, D[rule,t]}

Cheers,
Paul

____________________________________________________________________
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907
mailto:paul at physics.uwa.edu.au  AUSTRALIA
http://www.physics.uwa.edu.au/~paul

God IS a weakly left-handed dice player
____________________________________________________________________

```

• Prev by Date: Strange behaviour of Solve[] for equation with numerical coeeficients
• Next by Date: Re: I have A Problem
• Previous by thread: Re: Abs and derivative problems
• Next by thread: Re: Abs and derivative problems