Re: How do I create a parametric expression?

• To: mathgroup at smc.vnet.net
• Subject: [mg68581] Re: How do I create a parametric expression?
• From: gardyloo <gardyloo at mail.wsu.edu>
• Date: Wed, 9 Aug 2006 23:57:54 -0400 (EDT)
• References: <200608090819.EAA21141@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi, Alex,

I think this question comes up pretty often on the list; it seems to
be one of the harder things to do (or do well, and consistently) with
Mathematica. Usually, it seems that people have to delve into the
FullForm expressions, which can be a huge pain.

Here's a very preliminary attempt (and I don't know if it's "complete"):

In[3]:=

expr =

-((1 + 2*n)*((a^4*k^2 + a^2*(-1 + k^2*(q - z)^2) +

2*(q - z)^2)*Cos[k*Sqrt[a^2 + (q - z)^2]] -

k*(a^2 - 2*(q - z)^2)*Sqrt[a^2 + (q - z)^2]*

Sin[k*Sqrt[a^2 + (q - z)^2]])*

Sin[((1 + 2*n)*Pi*z)/L])/

(8*Pi*w*(a^2 + (q - z)^2)^(5/2));

In[9]:=

expr //. {(a^2 + (q - z)^2)^(n_) -> R^(2*n)}

Out[9]=

-((1/(8*Pi*R^5*w))*((1 + 2*n)*

((a^4*k^2 + a^2*(-1 + k^2*(q - z)^2) + 2*(q - z)^2)*

Cos[k*R] - k*R*(a^2 - 2*(q - z)^2)*Sin[k*R])*

Sin[((1 + 2*n)*Pi*z)/L]))

The replacement rule is just generalized a little bit for different
values of the exponent on R.

Hope that helps a bit,
Curtis O.

axlq wrote:
> I'm trying to figure out how to simplify a large expression so that it's
> expressed in terms of a sub-expression that's factored into the larger
> one.
>
> My expression looks like this:
>
> -((1 + 2*n)*((a^4*k^2 + a^2*(-1 + k^2*(q - z)^2) + 2*(q - z)^2)
>    *Cos[k*Sqrt[a^2 + (q - z)^2]] - k*(a^2 - 2*(q - z)^2)
>      *Sqrt[a^2 + (q - z)^2]*Sin[k*Sqrt[a^2 + (q - z)^2]])
>        *Sin[((1 + 2*n)*Pi*z)/L])/(8*Pi*w*(a^2 + (q - z)^2)^(5/2))
>
> Now, I *know* there are places in there were Sqrt[a^2+(q-z)^2] occurs,
> either by itself or raised to various powers.  If I want to define
>
> R:=Sqrt[a^2+(q-z)^2]
>
> ...then how can I make Mathematica re-state my expression in terms
> of R?  The ReplaceRepated[] function doesn't seem to do the job.
>
> I need to do this because I am translating the expressions into
> Visual Basic code for an Excel application, and it would be nice to
> find groupings of terms repeated throughout the expression that I
> need to calculate only once.
>
> -Alex
>
>
>

--
==========================================================
Curtis Osterhoudt
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================

```

• Prev by Date: Re: need mathematica's help for exploring a certain type of mapping
• Next by Date: Re: need mathematica's help for exploring a certain type of mapping
• Previous by thread: Re: How do I create a parametric expression?
• Next by thread: Re: How do I create a parametric expression?