From: =?ISO-8859-1?Q?Hans-Bernhard_Br=F6ker?= Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Function defined by a while loop Date: Mon, 27 Jun 2011 22:00:24 +0200 Lines: 25 Message-ID: <96s5qpFmfqU1@mid.dfncis.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de U/6r9sH1l5ad0odrOmOpsA5DDuTEW7Nhz8dtkgNHVkl4x9Mxy1b56rUpKo Cancel-Lock: sha1:3A5CpTRWcnn6OGRKnxohcYv+wT4= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.graphics.apps.gnuplot:410 On 27.06.2011 11:50, Antonio Lo Turco wrote: > Obviously I tried and it doesn't work! Of course it doesn't. while is a _command_, not an expression. You can't use it in the middle of an expression, like the one you use to define a function. > However I would like (and I'm not able) to implement such solution as > a user defined function. The only way there is recursion. But that will only work reasonably well for a _one_parameter_ loop. You loop over 'x' and 'i' simultaneously. That doesn't map cleanly to recursion over a single variable. Well, unless you make them the real and imaginary part of a complex number that is: iterate_f(x_i, x0, eps, maxiter) = \ ((abs(real(x_i) - x0) < eps) || (imag(x_i) > maxiter)) \ ? x_i \ : iterate(f(real(x_i)) + (imag(x_i)+1)*{0,1}, x0, eps, maxiter) print iterate(x0,x0,eps,maxiter)