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.

Now enter

<- "Hello, World!"

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:

-> ans = "Hello, World!"

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:

<- my_name = "Erik"

-> ans = "Erik"

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]:

<- "Hello " + my_name + "! The current time is " + timeformat("hh:mm", time()) + "."

-> ans = "Hello Erik! The current time is 10:21."

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.

<- 1+2+3

-> ans = 6

<- my_var = 3*_pi / 2

-> ans = 4.712389

<- cos(my_var) + sin(my_var)

-> ans = -1

<- 3i+15+7+21i

-> ans = 22+24i

It is also possible to evaluate multiple expressions in one command, as in the following factorial example:

<- 1!, 2!, 3!

-> ans = { 1, 2, 6}

Calculated results can also be used as strings if you prepend the # character to convert them to a string:

<- meaning_of_life = 5! / 4 + 2 * 3!

-> ans = 42

<- "The answer to life, the universe and all the rest is: " + #meaning_of_life

-> ans = "The answer to life, the universe and all the rest is: 42"

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.

<- integrate x^2 -set [0:2]

-> ans = 2.666668

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:

<- int_res = 2 * integrate x^2 -set [0:2] steps=10000

-> ans = 5.333333

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.

<- print "The answer to life, the universe and all the rest is: " + #meaning_of_life

-> The answer to life, the universe and all the rest is: 42

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.

<- define my_func(x) := cos(x) + sin(x)

-> [...]

<- my_func(my_var)

-> ans = -1

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:

<- plot my_func(x)

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:

<- plot cos(x) + sin(x)

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:

<- plot cos(x) + sin(x) "My function" -set box title="My first plot"

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":

<- surf sinc(norm(x, y)) -set light

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.