-1

I wanted to create a matrix of 5 rows and 2 columns.

For that i have written the code

pascal A_matrix: ARRAY [1..2, 1..5] OF REAL := [fei, fei, fei, fei, fei, 0, fei_predicted, fei_predicted, fei_predicted, fei_predicted]; // (NxN_u matrix i.e 5*2

Will the code generate in the form of 5*2 matrix?

  • Please read the [FAQ](https://meta.stackoverflow.com/questions/251225/faq-index-for-stack-overflow) or the answer to [this question](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) dirrectly. Please avoid giving code as image screenshots and use code blocks instead, it's against the code of conduct! – Guiorgy Aug 08 '22 at 09:39
  • @Guiorgy sure will keep this in mind and would not upload from next time – Nehal Trivedi Aug 08 '22 at 10:11
  • Or you could edit now and replace the image with:```pascal A_matrix: ARRAY [1..2, 1..5] OF REAL := [fei, fei, fei, fei, fei, 0, fei_predicted, fei_predicted, fei_predicted, fei_predicted]; // (N*N_u matrix i.e 5*2 ``` – Guiorgy Aug 08 '22 at 11:08

1 Answers1

0

You can read the CODESYS documentation for more information.

Your code will generate the following matrix:

index 1 2 3 4 5
1 fei fei fei fei fei
2 0 fei_predicted fei_predicted fei_predicted fei_predicted

To be more accurate, this will actually create a one dimensional array in memory and allow you to access it's elements with 2 indexes:

indexes 1, 1 1, 2 1, 3 1, 4 1, 5 2, 1 2, 2 2, 3 2, 4 2, 5
value fei fei fei fei fei 0 fei_predicted fei_predicted fei_predicted fei_predicted
Guiorgy
  • 1,405
  • 9
  • 26
  • thanks for the clarification. I wanted to multiply this matrix with its transpose so should i create another matrix ex. A_transpose and then multiply it? – Nehal Trivedi Aug 08 '22 at 10:22
  • Unless you are using some special library, there's no built in way to "multiply" matrixes in CODESYS, since they aren't mathematical matrixes, but multi-dimensional arrays. You'd have to manually implement the matrix multiplication logic. – Guiorgy Aug 08 '22 at 11:10