Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Replacement

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4458] Re: Replacement
  • From: wagner at motel6.cs.colorado.edu (Dave Wagner)
  • Date: Mon, 29 Jul 1996 02:37:15 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4shud7$g7n at ralph.vnet.net>,
Sergej Gerassimov <ges at vsnhdd.cern.ch> wrote:
>
>x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y //. Sqrt[a^2+b^2]->r
>gives:
>
>      x         r
>------------- + -
>Sqrt[a^2+b^2]   y
>
>(replace one only in the numerator)
>How to replace Sqrt[a^2+b^2] by r everywhere in the expression?

The reason what you're doing doesn't work is that the Sqrt in the denominator
is represented internally as Power[a^2+b^2, -1/2], which doesn't match the
pattern.

As somebody in this forum once said, "Pattern matching is relentlessly
syntactic."  (Please take credit for this, whoever said it.)

A general solution to this type of problem is to introduce a dummy
variable and use Solve:

    In[15]:=
    Solve[{dummy==x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y, r==Sqrt[a^2+b^2]},
	  {dummy},{a,b}]

    Out[15]=
	  x         r
    ------------- + -
	  2    2    y
    Sqrt[a  + b ]

The arguments to Solve tell it to solve for dummy and to attempt to eliminate
a and b.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: ListPlot the output of Print
  • Next by Date: Re: Replacement
  • Previous by thread: Re: Replacement
  • Next by thread: Re: Replacement