Re: generalized foldlist problem - part 2
- To: mathgroup at smc.vnet.net
- Subject: [mg69173] Re: generalized foldlist problem - part 2
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 1 Sep 2006 06:40:19 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <ed678a$j5c$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Arkadiusz Majka wrote: > 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}} lst = {{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} Total[lst] --> {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}. PadRight[lst[[1]], Length[lst[[1]]] + 2] --> {0.9, 0.9, 0.9, 0, 0, 0, 0} PadLeft[lst[[2]], Length[lst[[2]]] + 2] --> {0, 0, 0, 0.8, 0.8, 0.8, 0} adLeft[lst[[3]], Length[lst[[3]]] + 2] --> {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. I am sure that by now you are able to figure out what to do. HTH, Jean-Marc