MathGroup Archive 2006

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

Search the Archive

Problem dealing with Cases and MemberQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68152] Problem dealing with Cases and MemberQ
  • From: "Charlie Brummitt" <cbrummitt at wisc.edu>
  • Date: Wed, 26 Jul 2006 02:26:16 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

I am trying to write code to detect whether a given (partial
differential) equation is dissipative, i.e. whether it contains
-u[x,t] or +D[u[x,t],{x,2}] or -D[u[x,t],{x,4}] or +D[u[x,t],{x,6}].

In other words, given an expression (for example,  -0.1 u[x,t] +
u[x,t]^2 + u[x,t] D[u[x,t],{x,2}] )   I would like to determine
whether the expression contains any of the following: -U, +Uxx,
-Uxxxx, +Uxxxxxx --- with the specified signs. (Note that here I used
the shorthand U = u[x,t], Uxx = D[u[x,t],{x,2}], etc.)

I am having trouble determining whether a given variable (say U) has a
negative sign in front of it. It does not matter whether that U is
also multiplied by a real number (say 0.1) or by another variable (say
Ux). Could anyone please help me write the code to do this?


Here is a method I have tried, to moderate success:

This method successfully determines whether a particular term has a
plus or minus sign on it when the term has a real coefficient, but it
fails when the term in the equation is multiplied by another variable
(e.g., Ux).

Here is essentially what the code does: I do Cases[equation, term] to
find the cases of the term I'm looking for, then I divide the
resulting list by the term to just get the coefficient that's in front
of each case. Then I map the appropriate sign function (Positive or
Negative, depending on which term I'm searching for -- e.g. Negative
for -U, Positive for +Uxx, etc.). Then I use MemberQ on the result to
find out whether any of the values of the resulting list is True.

However, this method fails when the term in the equation is multiplied
by a different variable. This is because when I divide the list
generated by Cases by the term I'm searching for, I am still left with
any other variables that were multiplied by the term. For example, if
- U*Ux is in the equation, after dividing by U I am left with -Ux, and
when I apply Negative to this quantity it does not evaluate to True
(even though I want it to!) because it doesn't know whether Ux is
positive or negative. How might I fix this?

Here is the actual code:

containsDissipative[eq_, term_, sign_] := MemberQ[Map[sign, Cases[eq,
_*term]/term], True];


If you are so inclined, here is a good equation to use as a test equation:
Plus[Times[-0.001`, u[x, t]], Times[10, Power[u[x, t], 2]], Times[-1,
u[x, t], Derivative[1, 0][u][x, t]]]
Then flipping the signs on the leading U term and the U*Ux term is a
good way to test the code.

Might there be another way using Select?


Thank you very much in advance for any help or guidance that you may
be able to provide.


  • Prev by Date: Re: Wolfram Workbench
  • Next by Date: Re: General--FindRoot::nlnum error (Updated)
  • Previous by thread: Re: Graphics export quality-methods and defaults
  • Next by thread: Re: Problem dealing with Cases and MemberQ