Hello all,
I have a 2-dim cube with equivalent dimensions (an NxN matrix) and need to calculate it's determinant. Did anybody do this using only rules, without processes?
Matrix determinant
-
- MVP
- Posts: 733
- Joined: Wed May 14, 2008 11:06 pm
Re: Matrix determinant
If N was only going to be 2, or 3, then you could do something like this with the inclusion of a measures dimension:Elessar wrote:I have a 2-dim cube with equivalent dimensions (an NxN matrix) and need to calculate it's determinant.
Code: Select all
SKIPCHECK;
['Measure':'Input'] = N: STET;
# 2x2 grid
['Row':'a', 'Column':'a', 'Measure':'Output'] = N:
IF ( DB ( 'Calc Control', 'Grid Size', 'Number' ) = 2,
( ['Row':'a','Column':'a','Measure':'Input'] * ['Row':'b','Column':'b','Measure':'Input'] )
-
( ['Row':'a','Column':'b','Measure':'Input'] * ['Row':'b','Column':'a','Measure':'Input'] ),
CONTINUE
);
# 3x3 grid
['Row':'a', 'Column':'a', 'Measure':'Output'] = N:
IF ( DB ( 'Calc Control', 'Grid Size', 'Number' ) = 3,
( ['Row':'a','Column':'a','Measure':'Input']
*
( ['Row':'b','Column':'b','Measure':'Input'] * ['Row':'c','Column':'c','Measure':'Input'] )
-
( ['Row':'b','Column':'c','Measure':'Input'] * ['Row':'c','Column':'b','Measure':'Input'] ) )
-
( ['Row':'a','Column':'b','Measure':'Input']
*
( ['Row':'b','Column':'a','Measure':'Input'] * ['Row':'b','Column':'c','Measure':'Input'] )
-
( ['Row':'b','Column':'c','Measure':'Input'] * ['Row':'c','Column':'a','Measure':'Input'] ) )
+
( ['Row':'a','Column':'c','Measure':'Input']
*
( ['Row':'b','Column':'a','Measure':'Input'] * ['Row':'c','Column':'b','Measure':'Input'] )
-
( ['Row':'b','Column':'b','Measure':'Input'] * ['Row':'c','Column':'a','Measure':'Input'] ) ),
CONTINUE
);
# no calcs where grid size is > 3 % non-a and non-a combos
['Measure':'Output'] = N: STET;
FEEDERS;
['Measure':'Input'] => ['a', 'a', 'Output'];
Why don't you know N?
Robin Mackenzie
- Elessar
- Community Contributor
- Posts: 413
- Joined: Mon Nov 21, 2011 12:33 pm
- OLAP Product: PA 2
- Version: 2.0.9
- Excel Version: 2016
- Contact:
Re: Matrix determinant
Hi and thanks for reply
I'm going to do the Reciprocal Method of cost allocation from one Dep. to another: http://classes.bus.oregonstate.edu/Spri ... r%2012.htm
The most difficult there is to solve the system of linear equations.
N is not fixed: "Department" a dinamically updated dimension
I'm going to do the Reciprocal Method of cost allocation from one Dep. to another: http://classes.bus.oregonstate.edu/Spri ... r%2012.htm
The most difficult there is to solve the system of linear equations.
N is not fixed: "Department" a dinamically updated dimension
-
- MVP
- Posts: 733
- Joined: Wed May 14, 2008 11:06 pm
Re: Matrix determinant
Right, I see - so the number of departments is going to be unknown.
There's a bit of VB here that solves an NxN matrix determinant problem in 39 lines of code. It looks possible to rewrite in TI, at a glance. So, why not leverage that and hook it to an Action Button and get your users to use that?
There's a bit of VB here that solves an NxN matrix determinant problem in 39 lines of code. It looks possible to rewrite in TI, at a glance. So, why not leverage that and hook it to an Action Button and get your users to use that?
Code: Select all
Function determinant(Matrix() As Single, Norder As Integer, deter As Single)
Dim k, k1, i, j As Integer
Dim save As Single
Dim check As Boolean
deter = 1
For k = 1 To Norder
If Matrix(k, k) = 0 Then
j = k
Do
check = True
If Matrix(k, j) = 0 Then
If j = Norder Then
deter = 0
Exit Function
End If
check = False
j = j + 1
End If
If Matrix(k, j) <> 0 Then
For i = k To Norder
save = Matrix(i, j)
Matrix(i, j) = Matrix(i, k)
Matrix(i, k) = save
Next i
deter = -deter
End If
Loop While check = False
End If
deter = deter * Matrix(k, k)
If k - Norder < 0 Then
k1 = k + 1
For i = k1 To Norder
For j = k1 To Norder
Matrix(i, j) = Matrix(i, j) - (Matrix(i, k) * Matrix(k, j) / Matrix(k, k))
Next j
Next i
End If
Next k
End Function
Robin Mackenzie