Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Help Providing a Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39709] Re: [mg39696] Help Providing a Module
  • From: BobHanlon at aol.com
  • Date: Mon, 3 Mar 2003 04:25:47 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 3/2/03 6:04:27 PM, flip at safebunch.com writes:


> let me try to give some examples.
>
> Example 1.
>
> b = {-1, 2}
> q = {{{-1, 1}, {3, 2}}}
>
> so we look at the "one" submatrix of q starting with  {-1, 1}.
>
> Since the first value is -1 and that also belongs to b, we take the second
> value of {-1, 1} which is 1 and take Mod[1, 2] = 1
>
> So, the first value of the return vector is 1.
>
> Next we look at {3, 2}.  But 3 is not an element of b, so we make that
> element equal 0.
>
> Thus the return value is vects = {1, 0}
>
> Notice that the length of the return value is equal to the number of
> submatrices in q (that is, one return vector) and that the number of
> elements in the return vector is equal to the length of b (which is two).
>
> Example 2.
>
> Now, lets say
>
> b = {-1, 2, 3}
> q = {{{-1, 1}, {3, 2}},{{-1, 2}, {2, 1}, {3, 4}}}
>
> So, we have two submatrices in q which means two return vectors from our
> module.  The length of each of these will be equal to the length of b = 3. 
> Thus, our return vector will be of the form {{x, x, x}, {x, x, x}}
>
> So we look at {{-1, 1}, {3, 2}}, starting with {-1, 1}.
>
> So, we look at -1 and it exists in b, so we take Mod[1, 2] = 1.  The first
> value is 1
>
> Then, there is no 2  as a first element in {{-1, 1}, {3, 2}},  so we make
> the second value is 0.
>
> Then we look at {3, 2}.  3 exists in b, so we take Mod[2, 2] = 0, thus the
> third value is 0.
>
> Now we have {{1, 0 , 0}, {x, x, x}} and we move on to the next submatrix.
>
> So, for {{-1, 2}, {2, 1}, {3, 5}}}
>
> For {-1, 2}, the -1 is in b, so we take Mod[2, 2] = 0.
> For {2, 1}, the 2 is in b so we take Mod[1, 2] = 1.
> For {3, 2}, the 3 is in b so we take Mod[5, 2] = 1.
>
> So, we now have as {{x, x, x}, {x, x, x}} = {{1, 0 , 0}, {0 , 1, 1}}.
>
> Example 3.
>
> b = {-1, 2, 3, 61}
> q = {{{-1, 1}, {3, 2}}, {{-1, 1}, {3, 7}, {61, 1}}, {{2, 2}, {61, 1}}}
>
> We start with length[q] = 3, length[b] = 4.  Thus our return vector will
> have the form {{x, x, x, x}, {x, x, x, x}, {x, x, x, x}}.
>
> We now look at: {{-1, 1}, {3, 2}}
>
> {-1, 1}: -1 is in b, so we have Mod[1, 2] = 1
> There is not 2 in the q submatrix so the second value is = 0
> {3, 2}: 3 is in b, so we have Mod[2, 2] = 0, so the third value = 0
> There is no 61, so the fourth value = 0.
>
> Thus far we have: {{1, 0, 0, 0}, {x, x, x, x}, {x, x, x, x}}.
>
> We now look at: {{-1, 1}, {3, 7}, {61, 1}}
>
> {-1, 1}: -1 is in b, so we have Mod[1, 2] = 1
> No 2: so the value = 0
> {3, 7}: 3 is in b, so we take Mod[7, 2] = 1
> {61, 1}: 61 is in b, so we take Mod[1, 2] = 1
>
> Thus far we have: {{1, 0, 0, 0}, {1, 0 1, 1}, {x, x, x, x}}. On to the last
> submatrix.
>
> We know look at: {{2, 2}, {61, 1}}
>
> No 1: so the value = 0
> {2, 2}: 2 exists in b, so we take Mod[2, 2] = 0
> No 3: so the value = 0
> {61, 1}: 61 is in b, so we take Mod[1, 2] = 1
>
> Therefore, the return vector is:
>
> {{1, 0, 0, 0}, {1, 0 1, 1}, {0, 0, 0, 1}}.
>
>

I believe this is what you described:

vect[b_?VectorQ, q_List] :=

     Outer[If[MemberQ[First /@ #1, #2],

           First[Cases[#1, {#2, x_}:>

                 Mod[x, 2]]], 0]&, q, b,

       1, 1];



b = {-1, 2};

q ={ {{-1, 1}, {3, 2}}};



vect[b, q]



{{1,0}}



b = {-1, 2, 3};

q = {{{-1, 1}, {3, 2}},{{-1, 2}, {2, 1}, {3, 4}}};



vect[b, q]



{{1,0,0},{0,1,0}}



b = {-1, 2, 3, 61};

q = {{{-1, 1}, {3, 2}}, {{-1, 1}, {3, 7}, {61, 1}}, {{2, 2}, {61, 1}}};



vect[b, q]



{{1,0,0,0},{1,0,1,1},{0,0,0,1}}



Bob Hanlon



  • Prev by Date: Re: how use NDSolve with an ODE having parameters
  • Next by Date: Re: how use NDSolve with an ODE having parameters
  • Previous by thread: Re: Help Providing a Module
  • Next by thread: RE: Help Providing a Module