Cancel
Showing results for 
Search instead for 
Did you mean: 

API - Matrix Operations: Multiplication, Adition, Transpose and Inverse

Experimenter
Experimenter

I am making an API in which I need to make matrix operations between multi dimensional arrays.

Multiplication, Adition, Transpose and Inverse.

 

How is it done on Femap API.

 

The example I found for VBA is: (Is it the same on Femap API?)

 

Dim aMatrix As Variant
Dim bMatrix As Variant
Dim cMatrix As Variant
' get aMatrix and bMatrix

cMatrix = Application.MMult(aMatrix, bMatrix)

3 REPLIES

Re: API - Matrix Operations: Multiplication, Adition, Transpose and Inverse

Phenom
Phenom

Hi,

There are no matrix manipulation functions that I am aware of in FEMAP.

 

The MMult you speak of seems related to MS Excel. FEMAP can easily "plug into" Excel, there are many FEMAP Symposium presentation which deal with this, for ex P. Kriengsiri's excellent 2014 presentation (which even goes further):

http://community.plm.automation.siemens.com/t5/Femap-Knowledge-Base/FS14-09-Using-the-Femap-COM-OLE-...

 

So the overall way you have to solve your problem is to use third party libraries/software. This can be done either from inside FEMAP (i.e. using VB6 in the API window) or outside (from Visual Studio or Excel, using VBA). This choice is yours. Of course you can also always write these functions...

 

From inside FEMAP you can plug into Excel, or use a 3rd party library such as ALGLIB which is extremely usfeul and outstandingly written, granted not obvious how to use at first. If you need to get into real fierce maths, I recommend this. If you need to invert small matrices and are under Excel limitations (don't know wether they still exist in the later versions actually) stick with Excel.

APavageau

Re: API - Matrix Operations: Multiplication, Adition, Transpose and Inverse

Experimenter
Experimenter

If you want to do this in Femap API without using 3rd party software you can do it by using loop algorithms. 
Just have a look on google for matrix multiply algorithm.
Same thing for transpose / inverse. 


Re: API - Matrix Operations: Multiplication, Adition, Transpose and Inverse

Experimenter
Experimenter

Dear Felipe,

 

In principle you can quite easily write the functions for the multiplication, addition, and transpose yourself using a double loop, but taking the inverse is somewhat more of a challenge. For myself, I am using a Gauss-Jordan scheme that works quite nice for not too large matrices (I keep under 5x5):

 

Public Function MatrixInverse(a() As Double) As Double()
    Dim c#(), x#, y#
    Dim m&, u#, i&, j&, rv&()
    Dim q&, w&

    m = UBound(a, 1)
    ReDim c(0 To m, 0 To m), rv(0 To m, 0 To 1)
    For i = 0 To m: c(i, i) = 1: Next i
    For q = 0 To m 'for each column
        u = 10 ^ 15
        For i = 0 To m 'for each row
            If rv(i, 0) = 0 Then
                If a(i, q) <> 0 Then
                    If (Log(a(i, q) ^ 2)) ^ 2 < u Then
                        u = (Log(a(i, q) ^ 2)) ^ 2 'function of entry value
                        w = i 'highest row where function of entry value is smaller than previous
                    End If
                End If
            End If
        Next i

        rv(w, 0) = w + 1: rv(q, 1) = w: x = a(w, q)
        For j = 0 To m
            a(w, j) = a(w, j) / x
            c(w, j) = c(w, j) / x
        Next j
        For i = 0 To m
            If rv(i, 0) = 0 Then
                y = a(i, q)
                For j = 0 To m
                    a(i, j) = a(i, j) - y * a(w, j)
                    c(i, j) = c(i, j) - y * c(w, j)
                Next j
            End If
    Next i, q
            
    'BACK SOLUTION
    For q = m To 1 Step -1: For w = q - 1 To 0 Step -1
        x = a(rv(w, 1), q)
        a(rv(w, 1), q) = a(rv(w, 1), q) - x * a(rv(q, 1), q)
        For j = 0 To m
            c(rv(w, 1), j) = c(rv(w, 1), j) - x * c(rv(q, 1), j)
        Next j
    Next w, q
    For q = 0 To m: For j = 0 To m
        a(q, j) = c(rv(q, 1), j)
    Next j, q
    
    MatrixInverse = a
End Function

 

Hope this helps! Have fun!

 

Best wishes,

Cor