3
$\begingroup$

I'm using Table[] to repeat computations for a range of parameter values and every single value takes about 10 minutes. Is there a way to have Mathematica output the result of single computations as soon as it finishes rather than waiting for the whole operation to complete before I'm any wiser?

Consider this simple example.

Table[Pause[n^2] n^2, {n, 3}]

Is there a way to see the results 1, 4 and 9 after 1, 4 and 9 seconds, respectively, rather than having to wait the full 14 seconds?

$\endgroup$
1
  • 1
    $\begingroup$ Would Table[Pause[n^2]; Print[n^2]; n^2, {n, 3}] work for you? $\endgroup$ Commented Oct 31, 2017 at 9:31

2 Answers 2

6
$\begingroup$

Why not use Dynamic? For example:

Dynamic[x]
Table[Pause[n^2];x=n^2,{n,3}]
$\endgroup$
1
  • $\begingroup$ Very useful to prevent a spam of outputs to be printed (if there are many to be done). $\endgroup$ Commented Oct 31, 2017 at 18:54
2
$\begingroup$

I would put a print statement inside the table. Like:

Table[Pause[n^2]; x = n^2; Print[x]; x, {n, 3}]

In the above code, only x, i.e., the value which is output (has no ; after it) goes to the table.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.