If you need to calculate a matrix as
result of a complex expression or formula (several
combined together), you have several choices:
The last option is
usually the one
that requires the last of your time. The idea is to write the
expression as a text, to parse it and produce the
and final functions and result matrices from it.
- add the functions and the
intermediate and final result matrices one by one
to the project.
your own template (probably using a script
language) that calculates the complex formula and make a function from
- call an
external application through a special function, called adapter.
Adapters are not installed with Matrex, but can be installed
- use the Expression
There is only one
the expression parser can only parse formulas with functions that
return one and only one matrix
(most of the functions are like that).
Here is it
how it works.
We say that it is possible to write a
function as a text in the following way:
input_matrix2 .. input_matrixN, “parameter1”,
- template_name is the name
of the template on the base of the function.
- input_matrix1 ..
input_matrixN are the input matrices of the
function, in the correct order.
- parameter1 ..
parameterN are the parameters
of the function, in the correct order. To distinguish them from the
input matrices, they need to be written in quotes.
The matrices in the expression are assigned to the input matrices of the template following their order: the 1st matrix to the 1st template's matrix, the 2nd to the 2nd and so on.
The expression is valid if there are enough matrices to cover the number of the template's mandatory input matrices.
The parameters in the expression are assigned to the parameters of the template following their order: the 1st parameter to the 1st template's p the 2nd to the 2nd and so on.
in the template there are a set of parameters that are optional, they
are not needed in the expression if they are at the end of the
template's parameter set.
For example, if the template has 5
parameters and parameter 2, 4 and 5 are optional, the expression needs
values for the parameters 1, 2, 3 (in the same order) but not for
parameters 4 and 5, since they are the last 2.
Since the input matrix of a function
can be the result of another one, we can combine the functions in an
expression, for example:
Parsing this expression, the parser
produces the following items:
Here is an example of
matrices of the expression parser for the plus(log(matrix1),
- one function
that is the one producing the final result of the expression (plus in
matrix that is the final result of the expression
(the result of plus in this case)
- the intermediate
log and exp in a separate sub-package called im_<final function
name> (for example “im_plus”)
intermediate matrices of
the expression, for log and exp, in a separate sub-package called
im_<result matrix name> (for example
fact that the intermediate
functions and matrices are stored in separate sub-packages keeps the
project structure simple and efficient:
To start the
click with the mouse on the functions
tree and select the Expression
Parser menu, which shows the expression parser wizard.
- Of the whole expression
you are normally only interested in the final result; so it
that the intermediate matrices are in a sub-package that you can keep
it is good to be able to look at the intermediate matrices if you are
not sure about the final result or want to have some more information
about the process that produced it.
parser is organized as a wizard,
therefore is divided in steps.
you the current status of the parsing and/or tells you to enter or
choose some parameter.
Click on the Next
go to the
next step, Back to go to the previous.
Sometimes it is not possible to go to
the next step because some of the data entered in the current step or
in a previous step is wrong. In this case you can fix the wrong
data, then go again to the next steps.
When you open the wizard, you are on
the first step. The wizard has also step 2 (raw tree), step 3 (refined tree), step 4 (files), step 5 (summary).