MathGL library supports (from version 1.3) the simplest scripts for data handling and plotting. These scripts can be used independently (with the help of mgl2png, mgl2eps, mgl2svg programs and others) or in the frame of the library using.
MGL script language is rather simple. Each string is a command. First word of string is the name of command. Other words are command arguments. Command may have up to 1000 arguments (at least for now). Words are separated from each other by space or tabulation symbol. The upper or lower case of words is suficient, i.e. variables a and A are different variables. Symbol # starts the comment (all characters after # will be ignored). The exception is situation when # is a part of some string. Also options can be specified at the end of string (after symbol ';', see Sec. Command options).
If string contain references to external parameters (substrings "$0", "$1" ... "$9") then before execution the values of parameter will be substituted instaed of reference. It allows to use the same MGL script for different parameters (filenames, paths, condition and so on).
Argument can be a string, a variable name or a number.
').') started from a letter and with length less than 64. It is possible to use subarrays (like in subdata command) as command argument. For example, a(1) or a(1,:) or a(1,:,:) t so tin general case. The problem is that rotation and aspect change lead to different looks for titles of different subplots. So, the resulting look is not so good as it could be. The solution is simple – to print titles exactly after subplot call and before any rotation, aspect change and so on! Analogously, the title for the whole picture looks better if it is printed first (before any subplot calls).
By default (for the user comfort), the color range is set equal to z-range of the plot. However, there are different ranges. So, one can obtain an amusing plot by the change of color range manually. For example, there are plots with one-color bottom (or top) or practically bi-color picture and so on. For example, compare 2 surfaces:
Sometimes an experimental or numerical surface has outstanding points. Visualization of such surface will lead to the hole(s) in place of such points. The standard method of "fighting" – tochange data values – is not always good and is not so convenient. MathGL library has another method – to set cut off. As a consequence, all outstanding point will be projected on the bounding box.
Such method is good not only for outstanding points but also for the case when one need to plane the bottom or the top of the plot. Exactly such case is demonstrated in the code:
It is an interesting result, is not it? Note that the same result can be achieved by options cut:
Vector field visualization (especially in 3d case vect or vectc) may look tangly – there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change meshnum the number of hachures for decreasing. The second way is to use the flow thread chart flow. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MatGL.
In contrast to the most of the other programs, MathGL supports several (up to 10) light sources. Moreover, the color each of them can be different: white (this is usual), yellow, red, cyan, green and so on. The use of several light sources may be interesting for the highlighting of some peculiarities of the plot or just to make an amusing picture. Note, each light source can be switched on/off individually.
MathGL library has a feature for cutting of points in some region cut. Such an excision can be used to improve the look of the graphics. Moreover, this cutting may help to show an internal structure of an object (like isocaps plot in Matlab). For example, let us use the standard data array and show its interior:
Sometime ago I worked with mapping and have a question about its visualization. Let me remind you that mapping is some transformation rule for one set of number to another one. The 1d mapping is just an ordinary command – it takes a number and transforms it to another one. The 2d mapping (which I have used) is a pair of commands which take 2 numbers and transform them to another 2 ones. Except general plots (like surfc, surfa) there is a special plot – Arnold diagram. It shows the area which is the result of mapping of someinitial area (usually square).
I tried to make such plot in map. It shows the set of points or set of faces, which final position is the result of mapping. At this, the color gives information about their initial position and the height describes Jacobian value of the transformation. Unfortunately, it looks good only for the simplest mapping but for the real multivalent quasi-chaotic mapping it produces a confusion. So, use it if you like :).
[contents]
Nonlinear fitting is rather simple. All that you need is the data to fit, the approxiamtion formula and the list of coefficients to fit (better with its initial guess values). Let me demonstrate it on the following simple example. First, let us use sin function with some random noise:
and plot it
The next step is the fitting itself. For that let me specify an initial values ini for coefficients 'abc' and do the fitting for approximation formula 'a+b*sin(c*x)'
NOTE! the fitting results may have strong dependence on initial values for coefficients due to algorithm features. The problem is that in general case there are several local "optimums" for coefficients and the program returns only first found one! There are no guaranties that it will be the best. Try for example to set list ini 0 0 0 in the code above.
[contents]
Solving of Partial Differential Equations (PDE, including beam tracing) and ray tracing (or finding particle trajectory) are more or less common task. So, MathGL have several commands for that. There are ray for ray tracing, pde for PDE solving, qo2d for beam tracing in 2D case. These functions take "Hamiltonian" or equations as string values.
The ray tracing can be done by ray command. Really ray tracing equation is Hamiltonian equation for 3D space. So, the function can be also used for finding a particle trajectory (i.e. solve Hamiltonian ODE) for 1D, 2D or 3D cases. The function have a set of arguments. First of all, it is Hamiltonian which defined the media (or the equation) you are planning to use. The Hamiltonian is defined by string which may depend on coordinates 'x', 'y', 'z', time 't' (for particle dynamics) and momentums 'p'=px, 'q'=py, 'v'=pz. Next, you have to define the initial conditions for coordinates and momentums at 't'=0 and set the integrations step (default is 0.1) and its duration (default is 10). The Runge-Kutta method of 4-th order is used for integration.
This example calculate the reflection from linear layer (media with Hamiltonian 'p^2+q^2-x-1'=p_x^2+p_y^2-x-1). This is parabolic curve. The resulting array have 7 columns which contain data for {x,y,z,p,q,v,t}.
The solution of PDE is a bit more complicated. As previous you have to specify the equation as pseudo-differential operator H(x, ∇) which is called sometime as "Hamiltonian" (for example, in beam tracing). As previously, it is defined by string which may depend on coordinates 'x', 'y', 'z' (but not time!), mo