TomSym is complete modeling environment in Matlab with support for most built-in mathematical operators in Matlab. It is a combined modeling, compilation and interface to the TOMLAB solvers. The matrixderivative of a matrix function is a fourth rank tensor - that is, a matrix each of whose entries is a matrix. Rather than using four-dimensional matrices to represent this, TomSym continues to work intwo dimensions. This makes it possible to take advantage of the very efficient handling of sparse matrices in Matlab, which is not available for higher-dimensional matrices. TomSym has a variety of functions, among them:
Ability to transform expressions and generate analytical first and second order derivatives, including sparsity patterns.
Interfaced and compatible with MAD, i.e. MAD can be used when symbolic modeling is not suitable.
* Addition/subtraction of 0 is eliminated: 0+A = A
* All-same matrices are reduced to scalars: +x = 3+x
* Scalars are moved to the left in addition/subtraction: A-y = -y+A
* Inverse operations cancel: sqrt^2 = x
Modeling
The TomSym symbolic source transformation makes it possible to define any the set of decision variables and any type of constraint as well as scalars and constant parameters.
Linear programming
An example linear programming problem would look like this: c = ; A = ; b_U = ; x_L = ; toms 2x1 x solution = ezsolve;
A MINLP problem is defined just like a linear programming problem. This example also shows how to convert the model into a general TOMLAB problem. Name='minlp1Demo - Kocis/Grossman.'; toms 2x1 x toms 3x1 integer y objective = *; constraints = ; guess = struct; options = struct; options.name = Name; Prob = sym2prob; Prob.DUNDEE.optPar = 1; Result = tomRun;
Multi-index modeling
tomSym makes it possible to build models with two or more variable indices in MATLAB. The following example creates a variable 'flow' with four indices. The variable is then used to create a constraint over two of the indices and to sum the multiplication with a two-dimensional matrix. % Create the indices used in model i = tomArrayIdx; j = tomArrayIdx; k = tomArrayIdx; l = tomArrayIdx; % Create an integer variable of full length flow = tom; % Convert the variable to a matrix with four indices. flow = tomArray; % Create a constraint valid for all i and j cons = ; % Create a scalar based on multi-index multiplications distance = tomArray; sumtotal = sum+distance+... distance.*flow));
For functions that cannot be interpreted by tomSym it is possible to use either automatic differentiation or numerical differentiation. In the following example a simple problem is solved using the two methods. toms x1 x2 alpha = 100; % USE MAD FOR ONE FUNCTION % Create a wrapper function. In this case we use sin, but it could be any % MAD supported function. y = wrap; f = alpha*^2 + ^2 + y; % Setup and solve the problem c = -x1^2 - x2; con = ; x0 = ; solution1 = ezsolve; % USE NUMERICAL DIFFERENTIATION FOR ONE FUNCTIONS % Create a new wrapper function. In this case we use sin, but it could be % any function since we use numerical derivatives. y = wrap; f = alpha*^2 + ^2 + y; solution2 = ezsolve;