Re: simple iteration question

*To*: mathgroup at smc.vnet.net*Subject*: [mg89928] Re: simple iteration question*From*: sashap <pavlyk at gmail.com>*Date*: Tue, 24 Jun 2008 06:17:15 -0400 (EDT)*References*: <g3g017$l06$1@smc.vnet.net>

On Jun 20, 5:16 am, Francisco Gutierrez <fgutiers2... at yahoo.com> wrote: > Dear Friends: > I have a list of the form list={{3,2,1},{5,6,1},{10,5,1}}, of any lengt= h > I have a vector, say vector={1,2,3} > I want to make the following iteration. Take the first component of th= e = > list, make the dot product of it and the vector, and substract a number (= sa= > y 50). If the result is bigger or equal than zero, stop and return the ve= ct= > or. If it is less than zero, then change the vector in the followig way: = ve= > ctor+list[[2]], and repeat the test. > Iterate until the result is equal or bigger than zero, or until the list = en= > ds. > I haven't found a neat way of doing this. Any help is welcome > Francisco > Hey Francisco, here is a short way of doing it: In[59]:= mat = {{3, 2, 1}, {5, 6, 1}, {10, 5, 1}}; vec = {1, 2, 3}; In[61]:= Catch[ Fold[If[#1.#2 > 50, Throw[#1], #1 + mat[[2]]] &, vec, mat]] Out[61]= {6, 8, 4} Oleksandr Pavlyk