Main features for writing expressions
At the beginning, it should be mentioned that Wolfram Mathematica has a very extensive reference system. You can access it by selecting in this menu: Support | Wolfram Documentation:
Let's get acquainted with some distinctions of Mathematica that will help us to understand the source code in the following chapters.
Let's create our first notebook. When Mathematica starts, you should choose New Document and then Notebook.
In order to compute any expression, press Shift + Enter after entering it. The input expression will be denoted by In
and the output by Out
:
In[1]:= 1 + 4 Out[1]= 5
Note
In this and other samples, all the formulas will start with In[Number]
; you shouldn't type this because it is the number of the input that Mathematica calculates automatically.
All built-in functions always start with a capital letter, as shown here:
No variables should start with a number, since it will automatically be treated as a multiplication operation. They cannot end with a $ symbol.
If the variable ends with _
, then it is a template expression and it can be substituted with anything, for example:
In Mathematica, there are four types of brackets:
- Square []: These are used to describe the function parameters
- Round (): These are used to group expressions and logical elements
- Curly {}: These are used to describe the elements of arrays, vectors, and data lists
- Double Square [[ ]]: These are used to allocate a specific item in a data list
In Mathematica, there are two types of assignments: absolute (=
) and delayed (:=
).
The difference is that in a delayed assignment, the right-hand side of the expression is always recomputed if the function is called. In an absolute assignment, the value that was in place during the assignment is stored.
In this example, we see that at the time of the second call of variables, x2
adopted the current time value. At the same time, x1
remained unchanged.
In order to use the result of the preceding expression, one can use the %
symbol:
The basis of the Mathematica language is the functional form of all the expressions. In order to see a complete expression, the FullForm
function should be used:
The variables that are not used should be cleared by the Clear
function. Otherwise, computation errors will occur: