MathGroup Archive 2001

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

Search the Archive

Re: strange behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27175] Re: strange behavior
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 9 Feb 2001 03:10:22 -0500 (EST)
  • References: <95tqdq$m93@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Otto,
The problem seems to be that myF is evaluating before you want it to.
I suggest

Block[{myF},
  Map[ Thread[#, List, -2] &,
    MapThread[myF[xList, #1, #2, #3] &, {yList, cList, lList}]] ]

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Otto Linsuain" <linsuain+ at andrew.cmu.edu> wrote in message
news:95tqdq$m93 at smc.vnet.net...
>
> Hi all. I have a little problem using Thread and MapThread, and although
> I have found a way around it, I am still unhappy with it being there in
> the first place.
>
> I have a function (call it myF ) that takes as arguments FOUR vectors of
> equal length (doesn't matter what length) -by vector I mean a List of
> numbers with the simplest structure possible {x1, x2, ..... xN}- and
> gives out a number. The only operations involved in getting the number
> are addition, subtraction, multiplication and division. So I do
> convolutions of one list with another, and things like that (although I
> don't use ListConvolve).
>
> I want to map this function over a bunch of lists in the following way:
>
> For argument #1 I always want the same list xList={x1, x2, .....xN}
>
> For argument #2 I have the list: yList={{a1,a2,...aN}, {b1,b2,...bN}}
> and I want to apply the function first to the x's as argument #1 with
> the a's as argument #2, and then to the x's as argument #1, with the b's
> as argument #2. So far so good, and only need to map over the second
> argument.
>
> For argument #3 I have many lists. More exactly, I have a list
> consisting of two NxN matrices:
>
> cList={  { {Ca11,Ca12, ...Ca1N},{Ca21,Ca22, ...Ca2N},...{CaN1,Ca12,
> ...CaNN} },
>     { {Cb11,Cb12, ...Cb1N},{Cb21,Cb22, ...Cb2N},...{CbN1,Cb12,
..CbNN} }  }
>
> similarly for argument #4
>
> lList={  { {La11,La12, ...La1N},{La21,La22, ...La2N},...{LaN1,La12,
> ...LaNN} },
>     { {Lb11,Lb12, ...Lb1N},{Lb21,Lb22, ...Lb2N},...{LbN1,Lb12,
..LbNN} }  }
>
>
> when I use the a's for argument #2 I want to go through and use the
> first row in the Ca's for argument #3, and the first row in the La's for
> argument #4, then the second row of each, etc Notice that I don't want
> all the combination between the cList and the lList. When I am done with
> that I go to the b's for argument #2, then I want to use the first rows
> of Cb and Lb for arguments #3 and #4, then their second rows, etc.
>
> This is what I do:
>
> MapThread[ myF[xList,#1,#2,#3]&, {yList, cList, lList} ] this uses first
> the first Parts of yList, cList and lList, and then their second Parts.
>
> This produces { myF[ xList, {a1,a2,....aN}, matrix of Ca's, matrix of
> La's], myF[xlIst, {b1,b2,..bN}, matrix of Cb's, matrix of Lb's]}
>
> So far so good. Now I just need to Thread over the last two arguments:
>
> Map[ Thread[#, List,-2]&, MapThread[ myF[xList,#1,#2,#3]&, {yList,
> cList, lList} ] ] This threads the function myF over those arguments
> just the way I wanted AS LONG AS the function myF has not been defined.
> The minute I define the function myF to do what I want it to do (to
> combine the four vectors in a certain way and produce a number) it
> threads in a different way. Namely it threads as if using the Transpose
> of the lists cList and lList. One solution is to use the Transpose in
> the first place, so when they get Transposed again it would be just
> fine, but this is still puzzling. Any ideas on what is going on and
> suggestions on how to fix it (Transposing big matrices is a little slow)
> would be appreciated. Otto Linsuain.
>




  • Prev by Date: RE: strange behavior
  • Next by Date: (long) Re: Speed Challenge
  • Previous by thread: RE: strange behavior
  • Next by thread: BCH