MathGroup Archive 2001

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

Search the Archive

Re: newbie: all possible sums of two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30688] Re: newbie: all possible sums of two lists
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 8 Sep 2001 02:22:33 -0400 (EDT)
  • References: <9n17po$24b$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Alan,
Welcome!

Here's a way:

L1=List[i1,i2,i3,i4];
L2=List[j1,j2,j3];


Outer[Plus,L1,L2]

{{i1+j1,i1+j2,i1+j3},{i2+j1,i2+j2,i2+j3},{i3+j1,i3+j2,i3+j3},{i4+j1,i4+j2,
    i4+j3}}

Flatten[%]

{i1+j1,i1+j2,i1+j3,i2+j1,i2+j2,i2+j3,i3+j1,i3+j2,i3+j3,i4+j1,i4+j2,i4+j3}

--
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

"Alan Tu" <alantu at students.uiuc.edu> wrote in message
news:9n17po$24b$1 at smc.vnet.net...
> Hello, I confess I am a newbie to Mathematica. I think I have a basic
> understanding of the syntax and concepts, but there are just so many
> functions. What is the most efficient way to find all the possible sums of
> two lists.
>
> List[i1, i2, ... i_n]
> List[j1, j2, ... j_m]
>
> I want
>
> List[i1+j1, i1+j2, i1+j3, ... i1+j_m, i2+j1, i2+j2, i2+j3, ... i2+j_m, ...
> i_n+j_m]
>
> Any ideas would be appreciated. Thanks.
>
> Regards,
>
> Alan Tu
>
>
>




  • Prev by Date: Engineer's Stunt
  • Next by Date: Re: plotting cadlag point process
  • Previous by thread: Re: newbie: all possible sums of two lists
  • Next by thread: How solve a system of ODE with periodic coeffs.