Since a couple of versions icCube includes out of the box support for basic Matrix algebra in MDX. There is a support for two basic bricks : vectors and matrices.

In this short blog we’re going to use icCube to solve a simple linear equation. To make it self contained I’m going to write an MDX that does not rely on any specific schema :

Heavily inspired on this article we’re going to solve the following equation :

x + y + z = 60 + 2y + 5z = -42x + 5y – z = 27

In matrix syntax we could write it as A * X = B. Where A is a matrix, and both X and B are vectors.

What we need is to build a matrix. In icCube a matrix can be build with a set of vectors, so first we will create our three vectors :

Vector(1,0,2)Vector(1,2,5)Vector(1,5,-1)

Let’s put together the three vector to have our matrix.

Matrix( Vector(1,0,2),Vector(1,2,5),Vector(1,5,-1) )

You can check directly the output in icCube’s IDE with the following statement (Note that Vector and Matrices are like any other scalar entities – e.g. the number 2.0 )

WITHMEMBER A AS Matrix( Vector(1,0,2),Vector(1,2,5),Vector(1,5,-1) )SELECT A on 0FROM [Sales]

*X = A-1 * B*icCube version would be :

WITHMEMBER InvA AS Matrix( Vector(1,0,2),Vector(1,2,5),Vector(1,5,-1) )->inverse() * Vector(6,-4,27)SELECT InvA on 0FROM [Sales]

That gives a result pretty close to what we expect, this due to rounding issues. To solve this minor problem, instead of using the inverse matrix we can use directly the solve method available in icCube that uses an LUDecomposition :

WITHFunction Solve(a_) AS Matrix( Vector(1,0,2),Vector(1,2,5),Vector(1,5,-1) )->solve( a_ )MEMBER InvA AS Solve( Vector(6,-4,27) )SELECT InvA on 0FROM [Sales]

And here we got our result without rounding issue with the bonus of showing icCube’s support for functions.

Most probably, you will build your Vector and Matrix with data coming out of you model. For this you can use the same function with a slight difference syntax. Feel free to check the online documentation ( Vector doc, Matrix doc) and to experiment for your own.

That’s the end and it’s just a tiny intro on doing a bit of linear algebra with icCube and showing the object oriented support in icCube. If you’re wondering what’s the use of this, matrix calculations are a angular part of a lot of businesses as for example risk calculations and cost allocation.

If you are interested in learning more about MDX and MDX+, please take a look at our MDX Tutorial and MDX Documentation.

By David Alvarez