1

Is it possible to calculate the inverse of a matrix in CODEYS?

I am trying to write the code for the following equation.

Equation

Roald
  • 2,459
  • 16
  • 43
  • CODESYS, though basic and with limitations, is a turing complete language with general programming concepts, so with enough code you could do any kind of calculation if absolutely needed. Here's an example in [C++](https://www.tutorialspoint.com/cplusplus-program-to-find-inverse-of-a-graph-matrix), you just have to translate that to codesys. Having said that, CODESYS isn't a language built for math analysis, but for automation control on PLC. Do you really need something like matrix inversion in CODESYS? – Guiorgy Aug 03 '22 at 20:09
  • @Guiorgy I am working with a real-time system which is connected with plc. So the only option which i have is to work with codesys. The above formula has a matrix inversion so i guess it is required. – Nehal Trivedi Aug 04 '22 at 09:50

2 Answers2

2

For Codesys there is a paid matrix library. For TwinCAT there is the free and open source TcMatrix.

Roald
  • 2,459
  • 16
  • 43
1

This is a case where you don't need to calculate the inverse explicitly and indeed are better not to, both for performance and accuracy.

Changing notation, so that it's easier to type here, you want

V = inv( I + A'*A) *A'*B

This can be calculated like this:

compute

b = A'*B
C = I + A'*A

solve

C = L*L'  for lower triangular L

This is cholesky decomposition, which can be done in place, and you should read up on

solve

L*x = b for x 
L'*v = x for v

Note that because L is lower triangular (and so L' upper triangular) each of the above solutions can be done in O(dim*dim) and can be done in place if desired.

V is what you wanted.

dmuir
  • 4,211
  • 2
  • 14
  • 12