MathGroup Archive 2004

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

Search the Archive

Re: Algebraic simplification and speed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52681] Re: [mg52665] Algebraic simplification and speed
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 9 Dec 2004 20:22:34 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

x=(x1^2+2 y1^2+3 Z1^2)/Sqrt[x1^2+y1^2+z1^2];

x = x /.
    t_/Sqrt[x1^2+y1^2+z1^2]->t/r

(x1^2 + 2*y1^2 + 3*Z1^2)/r


Bob Hanlon

> 
> From: Steve Gray <stevebg at adelphia.net>
To: mathgroup at smc.vnet.net
> Date: 2004/12/07 Tue AM 04:10:09 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg52681] [mg52665] Algebraic simplification and speed
> 
> 1. I'm not sure how to do manually aided simplification. Suppose Mathematica solves a set of equations and
> comes up with something like
> x=(x1^2 + 2 y1^2+3 Z1^2)/Sqrt[x1^2+y1^2+z1^2] and similarly for y and z. I want to manually tell it
> to use r=Sqrt[x1^2+y1^2+z1^2] for the denominator from here on in all expressions and further work.
> How do I do that? (The actual expressions are much more complex.) I could manually substitute "r"
> for the Sqrt by copying/pasting etc. in the further expressions, but doing this in the actual
> equations is very error-prone, so I need Mathematica's help in subsequent stages.
> 	Unless Mathematica does a great job of removing redundant calculations, my manually defined
> temporary variables will also speed up the calculations.
> 
> 2. I had a Solve inside a loop. It was taking too long for the millions of numerical executions I
> need. Then I changed the code, executing a Solve once outside the loop, using symbols instead of
> numbers. Then I copied the resulting symbolic expressions into the loop, leaving Mathematica to do only
> numeric multiplies etc. in the loop, there now being no Solve in the loop. This made it about 30
> times faster. This seems like an obvious thing to do, but is there a more standard way? I almost
> didn't think of that trick, obvious as is may be to experienced users.
> 
>  
> 	Thanks for any help.
> 
> Steve Gray
> 
> 


  • Prev by Date: problem getting the area under a parmetric curve
  • Next by Date: Re: Re: Solve given that a variable is between 0 and 1
  • Previous by thread: Re: Algebraic simplification and speed
  • Next by thread: Re: Re: Redefining the minus operator