MathGroup Archive 2007

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

Search the Archive

Re: slot argument weirdness

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83957] Re: slot argument weirdness
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Wed, 5 Dec 2007 07:17:03 -0500 (EST)

On 12/4/07 at 4:29 AM, JLK2941 at yahoo.com (Jerry) wrote:

>I have to produce some bulky matrices which are described by two
>parameters and it seems the easiest way to produce them is as
>follows (I took out all the complexity and just left in the slots to
>illustrate my problem). v is the parameter array.

>v = {2, 5};
>myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v]

>giving     {{2, 5}, {5, 2}}    and all is well.

>But since the actual form in the first argument in Apply is really a
>large messy thing, I thought I'd produce it just once in the
>notebook and represent it with:

>m = {{#1, #2}, {#2, #1}};

>But geez, this doesn't work at all:

>MyMatrix2= Apply[m &, v]

>gives      {{#1, #2}, {#2, #1}}

Are you using version 6 of Mathematica? If yes, did you notice
the color of the slots was not the color Mathematica assigns by
default to function arguements but instead was the color
Mathematica uses to indicate a syntax error with your definition
for m?

Changing things to match the syntax Mathematca expects works, i.e.,

m = {{#1, #2}, {#2, #1}}&;

makes m a function and

In[4]:= Apply[m, v]

Out[4]= {{2, 5}, {5, 2}}

yields the desired result
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: slot argument weirdness
  • Next by Date: Re: Partition a list into sublists of unequal size
  • Previous by thread: Re: slot argument weirdness
  • Next by thread: Re: slot argument weirdness