Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: how to sum lists of unequal length?

  • To: mathgroup at
  • Subject: [mg70421] Re: how to sum lists of unequal length?
  • From: Peter Pein <petsie at>
  • Date: Mon, 16 Oct 2006 02:34:15 -0400 (EDT)
  • References: <egq2th$84h$>

Arkadiusz.Majka at schrieb:
> Hi all,
> I have lists of unknown and unequal lengths. I want to sum them, e.g
> {a1,a2,a3}+{b1,b2,b3,b4,b5} and obtain result
> {a1+b1,a2+b2,a3+b3,b4,b5}. Simply filling by zeros of the shorter list
> is impossible because I have no idea how many zeros I have to pad.
> Please, help
> Arek

Hi Arek,

 you don't need to have an idea, because Mathematica can easily estimate the
maximal length of the lists to sum:

In[1]:= (* generate 3 Lists of length 3, 7 and 5 resp. *)


and this determines the maximal length, pads an appropriate number of zeros to
the shorter lists and adds them:



Easy, isn't it? :-)


  • Prev by Date: Re: a fault in the Factor[] function for polynomials?
  • Next by Date: Re: Convert expression to polynomial
  • Previous by thread: Re: how to sum lists of unequal length?
  • Next by thread: How to solve this system of equations in Mathematica