MathGroup Archive 2008

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

Search the Archive

Re: simple iteration question

On Jun 20, 5:16 am, Francisco Gutierrez <fgutiers2... at>
> Dear Friends:
> I have a list of the form list={{3,2,1},{5,6,1},{10,5,1}}, of any lengt=
> 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 (=
> y 50). If the result is bigger or equal than zero, stop and return the ve=
> or. If it is less than zero, then change the vector in the followig way: =
> ctor+list[[2]], and repeat the test.
> Iterate until the result is equal or bigger than zero, or until the list =
> 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

  • Prev by Date: Mathematica SIG (Washington DC Area)
  • Next by Date: Re: Export lists
  • Previous by thread: Re: simple iteration question
  • Next by thread: Re: Re: simple iteration question