Output intermediate results during the runtime of a loop
Subject: Output intermediate results during the runtime of a loop
From: Paul Bowyer
Date: Thu, 29 Jul 2010 12:11:05 -0700
On 07/28/2010 02:52 PM, mok-kong shen wrote:
> If one has a for-loop consisting of, say, 10 steps and the computation
> of each step takes quite some time, is it possible to print out
> something at the end of each step during the runtime of the loop?
> (I tried 'print', but the 10 outputs came out all together at the end
> of procesing of the entire loop.)
>
> Thanks.
>
> M. K. Shen
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
With wxmaxima-0.8.4 and maxima-5.20.1 using gcl-2.6.8pre I've used code
like the following:
----------------------------------------------------------------------
kill(all);
/*Binomial coefficient
Variables n=exponent of term
k=term number */
define( C(n,k), (n!/(k!*(n-k)!)) );
/*Bernstein polynomial definition.
Variables: i=polynomial index,
n=degree of polynomial*/
define( b[i,n](u), expand( C(n,i)*(1-u)^(n-i)*u^i) );
n:3$
for i:1 thru n+1 step 1 do (
ldisp( b[i-1,n](u) )
);
----------------------------------------------------------------------
but everything happens so quickly I'm uncertain if it waits until
everything is complete before outputting the results of each loop.
Paul