MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Replace and ReplaceAll -- simple application

  • To: mathgroup at
  • Subject: [mg106108] Re: [mg106038] Re: Replace and ReplaceAll -- simple application
  • From: DrMajorBob <btreat1 at>
  • Date: Fri, 1 Jan 2010 05:38:17 -0500 (EST)
  • References: <> <hh72dp$kud$>
  • Reply-to: drmajorbob at

All true... but I know about the Conjugate function without ever (as far  
as I recall) having a need for it. Mathematica users should expect such a  
function to exist, besides, and it's easy to find if you're looking for it.

One certainly might, of course, want to see a function's conjugate without  
a series of operations like:

expr = (R + I L) (R - I w L);

(-I L + R) (R + I L w)

...and that sequence won't work in general, anyway.

If we want to see that, we might have to make the I -> -I substitution  
manually. For instance,

expr /. {-I -> I, I -> -I}

(-I L + R) (R + I L w)

That works when the terms are symbolic, but not if the symbols are  
replaced with constants:

expr = (1 + 2 I) (1 - 3 I)
expr /. {-I -> I, I -> -I}

7 - I

7 - I

That is annoying... that a simple Replace (though not as simple as I ->  
-I) works for symbols, but not for numbers.

The following works for numbers AND for symbols, and it's no more  
complicated nor less intuitive, I suppose:

expr = (1 + 2 I) (1 - 3 I)
expr /. Complex[a_, b_] :> Complex[a, -b]

7 - I

7 + I

expr = (R + I L) (R - I w L);
expr /. Complex[a_, b_] :> Complex[a, -b]

(-I L + R) (R + I L w)

...but the right path isn't obvious until we've had this discussion (or  
something like it).


On Thu, 31 Dec 2009 02:14:13 -0600, AES <siegman at> wrote:

> In article <hhf5kg$go6$1 at>,
>  Murray Eisenberg <murray at> wrote:
> [Re the  I -> -I  problem in particular:]
>> On the other hand, not every possible issue can be addressed immediately
>> at the top of documentation just because this or that user happened to
>> experience some difficulty with it.
>> Only gathering usage statistics, or having a focus group of users trying
>> stuff, might suffice to escalate some issues to the point of requiring
>> more prominent warnings.
>> I wonder how many users in fact experience this issue.
> I'll give you one sizable group.
> Engineering and science students and practitioners, at all levels down
> to at least college sophomores and even advanced high school students,
> are taught to solve systems of coupled linear differential equations
> (e.g., the loop or node equations for linear electrical networks with
> current and/or voltage sources, or forcing functions) using the phasor
> approach.
> The first step in doing this is of course to replace d^n /dt^n by
> (I w)^n (w as shorthand for omega), thereby converting these to coupled
> algebraic equations.  The next step is then to solve these equations to
> obtain a matrix-valued transfer function or scattering matrix, whose
> elements contain only *real-valued* parameters (R's, L's and C's in the
> electrical circuit case) and I -- elements that look like R + I w L.
> In practice, the instructor and the students do a few problems of this
> type by hand, with just one or two variables; define and examine the
> poles and zeros of the transfer function; learn about concepts like
> resonance and impedance and admittance, and scattering matrices and
> input and output ports; and so on.  But the instant one goes to anything
> more realistic and interesting, with three or more variables, the
> algebra and the numerical calculations just become too tedious.
> But, hey, Mathematica is just beautiful for this task.  The Solve[ ]
> function is perfect for doing the algebra to find the transfer function
> -- simple, easy to understand, obvious; and all the elementary Plot
> functions (David Park's "set pieces") will give you all the plots you
> could ask for.  And since the output variables are phasors, e.g.
> voltages and currents, vc(t) and ic(t) (generally indexed and often
> written with superimposed tildes to indicate that they are complex
> variables), you can get numerical results for power flows and energy
> densities using notations like p([t_] = Re[vc(t)] Re[ic(t)].
> But at some point you may want to get analytical formulas as well, e.g.
> the modulus and argument of the transfer function from an input to an
> output port.  And, maybe move on to the ideas of "lossless", that is,
> unitary, and Hermitian scattering matrices.  At which point, the idea of
> the transfer function, call it tFunc, and its complex conjugate,
> tFunctStar, become significant.  EE students say "v" and "vStar" and "i"
> and "iStar" all the time!
> And at that point, if you're focusing on the system properties and not
> specific numerical calculations it's very tempting to note that these
> tFunc's contain nothing but purely real circuit elements (R's. L's and
> C's, or masses and spring constants, or whatever), and I.
> And a quick test confirms that the rule {a->-a} does what it's supposed
> to (whether or not a has a minus sign in front of it).  Or, a quick test
> confirms that I->-I properly converts R  + I w L  into R - I w L.  Why
> shouldn't it???  It just does what you'd expect a global find and
> replace to do, or what you'd do "by hand" -- right?
> Take a look at the Mathworld entries for "phasor" and "transfer
> function" and see how far down you'd have to dig to get an explicit
> warning that the previous paragraph is misleading.  (And note that the
> entry for "Phasor" does not contain a "SEE ALSO:" for the term "Complex
> Conjugation", and the link to that term within the text does not -- so
> far as I can see -- give any hint the the rule I->-I will fail for an
> expression containing -I.)

DrMajorBob at

  • Prev by Date: Re: Re: Re: Return in function
  • Next by Date: Re: Re: Replace and ReplaceAll -- simple application
  • Previous by thread: Re: Re: Replace and ReplaceAll -- simple application
  • Next by thread: Re: Re: Replace and ReplaceAll -- simple application