Elements of Mathematica Programs

Mathematica can be used in the same fashion as a traditional programming language, such a fortran or C.  For  frequently used programs or computationally intensive applications, Mathematica is not the best programming language choice, but it can be very effective as a way to test out ideas or generate a single numerical result.

Evaluating a sequence of instrutions (;;;)

"index_1.gif"

"index_2.gif"

"index_3.gif"

Note above that line breaks without ";" are points where the instructions get executed. This three-line sequence has five executions and produces two lines of output and the instructions get executed sequentially.

"index_4.gif"

Loops

"index_5.gif"

"index_6.gif"

"index_7.gif"

"index_8.gif"

"index_9.gif"

In this case, Do does not produce screen output. The following will and is a simple illustration of how formatted output can be programmed:

"index_10.gif"

"index_11.gif"

"index_12.gif"

"index_13.gif"

"index_14.gif"

"index_15.gif"

"index_16.gif"

"index_17.gif"

"index_18.gif"

"index_19.gif"

"index_20.gif"

"index_21.gif"

"index_22.gif"

"index_23.gif"

"index_24.gif"

"index_25.gif"

"index_26.gif"

"index_27.gif"

"index_28.gif"

"index_29.gif"

Note above that we have asked Mathematica to create a list of two-element lists...

"index_30.gif"

"index_31.gif"

"index_32.gif"

"index_33.gif"

"index_34.gif"

In the instruction above, note that the variable "datatable" is a list. In Mathematica, variables can be numbers, expressions, lists, plots, ...  We will see that this feature is very useful.


Created by Wolfram Mathematica 6.0  (06 September 2007) Valid XHTML 1.1!