Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Multiplying a vector over multiple vectors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91199] Re: Multiplying a vector over multiple vectors
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sat, 9 Aug 2008 07:45:34 -0400 (EDT)
  • References: <g7ed6u$2pm$1@smc.vnet.net>

In[1]:= m = Table[Random[Integer,{-100,100}],{10^5},{2}];
First@Timing[p = Transpose[{a,b} Transpose@m];]
First@Timing[q = Transpose[{a m[[All,1]], b m[[All,2]]}];]
First@Timing[r = Inner[Times,m,{a,b},List];]
SameQ[p,q,r]

Out[2]= 0.7 Second
Out[3]= 0.71 Second
Out[4]= 0.55 Second
Out[5]= True

On Aug 7, 1:53 am, Donald DuBois <don... at comcast.net> wrote:
> How does one get a vector to distribute over
> a list of vectors  under multiplication?
>
> For example:
>
> {{1,2}, {3,4}, {5,6}} times {a,b} should
> equal  (under this operation)
>
> {{a, 2b}, {3a, 4b}, {5a, 6b}}
>
> If {a,b} is duplicated three times one can
> use MapThread as in:
>
> MapThread[Times, {{{1,2}, {3,4}, {5,6}}, {{a,b}, {a,b}, {a,b}}}]
>
> but duplicating {a,b} using Table is very slow
> when the vectors are large (consisting of thousands
> of elemets).
>
> Thanks in advance for any help you can give me.
>
> Don


  • Prev by Date: Re: Solving complex equations
  • Next by Date: Re: Solving complex equations
  • Previous by thread: Re: Re: Multiplying a vector over multiple vectors
  • Next by thread: User-Supplied Jacobian in NDSolve