MathGroup Archive 2006

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

Search the Archive

Re: Ask Mathematica to sub for a long expression


aaronfude at gmail.com wrote:
> Hi,
>
> Is it possible to ask Mathematica to replace a long expression, such as
> Sqrt[a^2+b^2-2*a*b*Cos[theta]] with "c", whenever it encounters that
> long expression?
>
> Thanks!
>
> Aaron Fude
>

Use transformation rules [1]. For example,

f = 3*Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]];
f /. Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]] -> c

--> 3*c

f = 3*Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]] + 1/Sqrt[a^2 + b^2 -
2*a*b*Cos[\[Theta]]];
Together[f /. a^2 + b^2 - 2*a*b*Cos[\[Theta]] -> c]

--> (1 + 3*c)/Sqrt[c]

Regards,
Jean-Marc

1. _The Mathematica Book_, /Section 2.5: Transformation Rules and
Definitions/, http://documents.wolfram.com/mathematica/book/section-2.5


  • Prev by Date: Re: SubValues
  • Next by Date: When I Get[] a package - how can I tell where the error message came from?
  • Previous by thread: Re: Ask Mathematica to sub for a long expression
  • Next by thread: Re: Ask Mathematica to sub for a long expression