[Date Index]
[Thread Index]
[Author Index]
Re: Pattern matching problem
*To*: mathgroup at smc.vnet.net
*Subject*: [mg88593] Re: [mg88516] Pattern matching problem
*From*: DrMajorBob <drmajorbob at att.net>
*Date*: Fri, 9 May 2008 03:25:34 -0400 (EDT)
*References*: <29931163.1210271316984.JavaMail.root@m08>
*Reply-to*: drmajorbob at longhorns.com
If you don't want to multiply by the power, then don't:
f[equation_] := Sum[j*Count[equation, D[u[x, t], {x, j}]^k, {0,
Infinity}], {j, 1, 50}, {k, 1, 50}]
eg = D[u[x, t], {x, 2}]^2;
f[eg]
4
Bobby
On Wed, 07 May 2008 06:07:52 -0500, Charlie Brummitt <cbrummitt at wisc.edu
>
wrote:
> Hi all,
> Here is my problem: Given a polynomial in the variables u[x,t] and its
> spatial derivatives (for example, the polynomial could be 1 + u +
> u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity.
> That is, after writing the above polynomial as
>
>
> 1 + u + u_xx * u_xxx * u_xxx
>
> the output should be 2 + 3 + 3 (basically, you count the number of x's).
>
> I have tried implementing this using a pattern matching approach. Here is
> what I tried:
>
> f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^
> k ,
> {0, \infinity} ], {j, 1, 50}, {k, 1, 50}]
>
> This fails to work on, for example, the input u_xx^2, because it outputs
> 6
> when it should output 4. This is because the u_xx is counted (+2 to th e
> sum), and the u_xx^2 is counted (+4 to the sum). This is because the
> u_xx is
> nested inside the Power[ , 2] in its representation in Mathematica
> and so
> it gets counted too many times in my formula. I can't seem to figure out
> a
> way to use the "provided that" operator /; to make this formula work.
>
> I've also tried doing some replacement methods, but to no success.
>
> Thanks for any help you may be able to provide.
>
> -Charlie
>
>
>
--
DrMajorBob at longhorns.com
Prev by Date:
**Re: A bug in Show[]?**
Next by Date:
**Re: Re: Question on the Limiting Value of Ratios of Consecuative Primes...**
Previous by thread:
**Re: Pattern matching problem**
Next by thread:
**Trouble computing conjugates**
| |