MathGroup Archive 1994

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

Search the Archive

Re: Question about Cases command.

  • To: mathgroup at yoda.physics.unc.edu (Mathgroup)
  • Subject: Re: Question about Cases command.
  • From: leszek (Leszek Sczaniecki)
  • Date: Tue, 28 Jun 1994 14:30:47 -0500

> From: Scott Herod <sherod at gauss.colorado.edu>
> Subject: Question about Cases command.
> To: mathgroup at yoda.physics.unc.edu (Mathgroup)
> Date: Mon, 27 Jun 1994 14:58:29 -0600 (MDT)
> 

> I am trying to grab a list of the derivatives of functions that
> appears in a large list of differential equations.  I have been using
> the Cases command to do this and have a question about some curious
> behavior.
> 

> 	Consider the list of two derivatives:
> 

> In[1]:= {Derivative[1,2][a][x,y], Derivative[1,1][b][x,y]}
> 

>            3       2
>           d a     d b
> Out[1]= {------, ------}
>            1  2    1  1
>          dx dy   dx dy
> 

> 

> 	I would like to select the derivatives of "a" .  First let's
> 	check the Head of the terms:
> 

> In[2]:= myterms = %;
> 

> In[3]:= Map[Head, myterms]
> 

>           (1,2)   (1,1)
> Out[3]= {a     , b     }
> 

> 	Now try to uses Cases:
> 

> In[4]:= Cases[myterms,_Derivative[__][a]]
> 

> Out[4]= {}
> 

> 	Why didn't it select the "a" term out?  Try:
> 

> In[5]:= Cases[myterms, _Derivative[__][_]]
> 

> Out[5]= {}
> 

> In[6]:= Cases[myterms, _Derivative[__][__]]
> 

>            3       2
>           d a     d b
> Out[6]= {------, ------}
>            1  2    1  1
>          dx dy   dx dy
> 

> 	Ok, now why must I use two underscores in this form?  ( In[6] )
> 	The "a" and the "b" are single elements.
> 

> 	BTW. Here is something which works.
> 

> In[7]:= derivdepfn[deriv_] := Head[deriv][[1]];
> 

> In[9]:= Select[myterms, (derivdepfn[#1] === a) &]
> 

>            3
>           d a
> Out[9]= {------}
>            1  2
>          dx dy
> 

> 

> 

> Scott A. Herod
> Program in Applied Mathematics
> University of Colorado, Boulder
> (sherod at newton.colorado.edu)
> 


In[5]:= expr = {Derivative[1,2][a][x,y], Derivative[1,1][b][x,y]}

Out[5]=
  (1,2)         (1,1)
{a     [x, y], b     [x, y]}

In[25]:= Cases[expr, Derivative[__][a][__]] 


Out[25]=
  (1,2)
{a     [x, y]}

You may consider to use Select

In[41]:= expr1 = {Sqrt[Derivative[1,2][a][x,y]], Derivative[1,1][b][x,y]}

Out[41]=
       (1,2)          (1,1)
{Sqrt[a     [x, y]], b     [x, y]}

In[42]:= Select[expr1, !FreeQ[#, Derivative[__][a]]&]

Out[42]=
       (1,2)
{Sqrt[a     [x, y]]}

I hope it helps,

Leszek





  • Prev by Date: Compile
  • Next by Date: Re: help number instruction
  • Previous by thread: Re: Question about Cases command.
  • Next by thread: Re: Question about Cases command.