MathGroup Archive 2008

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

Search the Archive

Re: Re: simple iteration question-thanks

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89989] Re: [mg89928] Re: simple iteration question-thanks
  • From: Francisco Gutierrez <fgutiers2002 at yahoo.com>
  • Date: Thu, 26 Jun 2008 04:39:28 -0400 (EDT)
  • Reply-to: fgutiers2002 at yahoo.com

Many thanks to Don, Jean Marc, and Oleksandr. Their ideas were very useful 
to solve my problem. Indeed, it implied using Fors and Ifs. I wonder if it 
is possible to express all this functionally and not procedurally; I couldn't find a way to do it.
Best,
Fg

--- On Tue, 6/24/08, sashap <pavlyk at gmail.com> wrote:

From: sashap <pavlyk at gmail.com>
Subject: [mg89989] [mg89928] Re: simple iteration question
To: mathgroup at smc.vnet.net
Date: Tuesday, June 24, 2008, 5:17 AM

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 length
> I have a vector, say vector={1,2,3}
> I want to make the following iteration.  Take the first component of the 
> 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 vect
 > 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=0A=0A=0A      


  • Prev by Date: Re: Symbolic complex conjugation?
  • Next by Date: Re: Ploting integral curves
  • Previous by thread: Re: Export PDF plot or Save Selection As -- big troubles with
  • Next by thread: Re: simple iteration question-thanks