![]() The Timing command that we used gives an elapsed time together with the result of evaluation for a given expression. The reasons why this is so, as well as when the procedural programming style (based on loops, conditionals, etc) is and is not appropriate, we will discuss at length in the next chapters. We will first do this with a loop, and then show a program written in a functional programming style. We will compute a sum of the first 100000 natural numbers. Let me illustrate this on a simple example. This is not so much due to loops themselves being slow in Mathematica, as to the fact that certain common programming practices associated with loops are efficient in other languages but not in Mathematica. It turns out that programs that use loops are often inefficient in Mathematica. 2.8.7 Programs using loops are often inefficient in Mathematica
0 Comments
Leave a Reply. |