The command window
We'll show you how it's done!
"Hello, World!" and simple expressions.
Ah yes, the classic. Your first program in any programming language is always "Hello, World!". We don't want to disappoint you, so we'll start with this simple example in the command window.
In case you are still unsure which one it is: at the bottom of the main window you will find a long section where you can read text (among other things the current version). If this section is not visible, press [F2] to show it again. In the last line you should see an arrow at the beginning of the line (|<-). This is the place to start.
without the leading arrow into the command window and confirm with [ENTER] (the arrow always indicates inputs and outputs in NumeRe). NumeRe will then reply with the following line:
Congratulations! You have just successfully completed your first interaction with NumeRe.
Now for a more advanced task. We want NumeRe to know your name and greet you with the current time. To do this, we define a variable that contains your name:
Furthermore we need your greeting. For this we use the function timeformat() together with time() as source for the current time. So we enter the following into the command window and confirm with [ENTER]:
Congratulations again! You have worked with variables and functions for the first time. You must have noticed a few things: the plus sign is (also) used to link strings. Also, strings, functions and operators appear in different colors in the command window. This makes your work easier, because you can distinguish the different types directly at first sight. If you want, you can execute the last line again. Use [ARROW UP] and then [ENTER]. You will see that the arrow keys allow to select the last commands and after the execution a new output with the updated time will appear accordingly.
Besides strings, NumeRe is particularly good at processing numeric expressions. We will make an example of this here as well. These can be very simple calculations or really complex expressions in which variables and functions are handled.
It is also possible to evaluate multiple expressions in one command, as in the following factorial example:
Calculated results can also be used as strings if you prepend the # character to convert them to a string:
Working with commands
Commands differ from functions in that only one command can be used per expression and that commands always define the end of the expression. In addition, not all commands return values. These cannot then be part of another expression, but must be used individually.
Let's start with an example: to integrate functions numerically, the command integrate can be used.
The result obviously has rounding errors. These are caused by the rather coarse default step size, which can however be increased. So this command returns a value and can also be the termination of an expression:
The print command, on the other hand, returns no value and is used to display strings without the enclosing quotes. It must be inserted at the beginning of the expression.
Likewise, the define command also does not return a value, but defines its own function, which can then be used in an expression like all other functions.
Note: Be aware that functions defined by define (and similar commands) are not the same as, for example, functions in MATLAB. Their functionality is provided by the so-called NumeRe procedures (to come in a later section). Functions defined by define especially improve readability and simplify parameterization of expressions.
The first plots
To visualize data, NumeRe knows many plotting commands, ranging from one-dimensional to three-dimensional. For our case, the 1D command plot is sufficient for now, which can be used to visualize simple functions or data series. We use it with your new function defined in the previous section:
As you can see on the right, a simple line plot from -10 to 10 was created using the function you defined. You will also notice that the y-axis is slightly larger than the function actually requires. This way, NumeRe ensures that the upper and lower edges of the plot are always clearly visible.
Even though we used a previously self-defined function here, you could also create the same plot by entering the expression directly. Only the legend of the plot would be different. Feel free to try it out:
With a few options, you can now make the last result even prettier and thus achieve the style that is most often used in publications:
Now a box is displayed around the plot, we have a nice title and a custom legend. There are many more options with which you can modify your plot. You can add an additional grid (option grid), give the axes their own labels, e.g. xlabel="Time t [s]", or easily switch to logarithmic scaling (options xlog and ylog).
A simplified LaTeX syntax is also supported for legends, titles and axis labels. Thus, Greek letters with the usual LaTeX syntax (e.g. \alpha or \delta) can also be used.
The command surf can be used to display a two-dimensional scalar field in three dimensions. We demonstrate this with a 2D cardinal sine, the so-called "sombrero function":
Here the surrounding box was automatically taken over from the previous plot. This behavior has the goal of always maintaining the style of the plots among themselves as much as possible. Thus, all settings that make sense for several plots in a row are adopted. Plot-specific settings, such as titles or axis labels, are of course not adopted for subsequent plots.
By the way, no legend is displayed here, because it is unusual to have one for such plots. Rather use a title above your plot. This looks more professional.