Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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

generalized foldlist problem - part 2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69138] generalized foldlist problem - part 2
  • From: "Arkadiusz Majka" <Arkadiusz.Majka at telekomunikacja.pl>
  • Date: Thu, 31 Aug 2006 04:38:43 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear All,

Thank all of you for your help regarding my "generalized fold list
problem", that sounds

>> I have two list
>
> list1={a,b,c,d,e}
> list2={3,2,5,1,6}
>
> and I want to apply a modified version of FoldList to list1 in the
> following way: list2 indicates that element a appears only 3 times (if
> space enough) beginning from the beginning of the list , element b
> appears 2 times, c - 5 times , etc.
>
> So the output should be
>
> GeneralizedFoldList[list1,list2]={a,a+b,a+b+c,c+d,c+e}
>
>

Now, I still need your help. What I want to do now, and what I have
problem with, is to add a constraint to the algorithm, i.e every
element in my GeneralizedFoldList must be less than one.
The following example says what to do if it is not.

Lets take two lists

list1={0.9,0.8,0.7}
list2={3,3,3}

All your algorithms use PadRight (you pad 0's). So the following matrix
is built

{{0.9, 0.9, 0.9, 0, 0}, {0, 0.8, 0.8, 0.8, 0}, {0, 0, 0.7, 0.7, 0.7}}

and we add elements along colums and obtain {0.9, 1.7, 2.4, 1.5, 0.7}

The first element is less than 1 so it's ok. The second is > 1 what I
need to avoid. I want to avoid it by shifting the nonzero elements of
the second and third row of above matrix of two positions:
{0,0,0,0.8,0.8,0.8,0}, {0,0,0,0,0.7,0.7,0.7}.

I go on with suming along columns and discover that everything is fine
until I have to add 0.8 and 0.7 what is >1. So I repeat the procedure
by shfting hte third row of the number of position that is needed to
ensure that my sum is <1.

Finally I obtain {{0.9, 0.9, 0.9, 0, 0, 0, 0, 0,
0},{0,0,0,0.8,0.8,0.8,0,0,0},{0,0,0,0,0,0,0.7,0.7,0.7}}
and Plus@@% is what I desire.

Thanks in advance! I hope you will manage :)

Arek


  • Prev by Date: Re: generalized foldlist problem
  • Next by Date: Re: Removal of Temporary symbols
  • Previous by thread: Unexpected "Invalid comparison" error when plotting function defined with a Condition pattern
  • Next by thread: Problems with NMaximize.