accessing matrix value

Moderators: Frank, paul, Hiwot, Chris, peter

hgpillai
Posts: 7
Joined: Wed Jan 11, 2006 6:08 pm

accessing matrix value

Postby hgpillai » Sun Feb 05, 2006 7:24 pm

Hi, One of the input of my submodel is a 3*3 matrix, How do I access the elements individually ( say for example 2nd row, 2nd column value) in the code?
Thanks in advance

Johan
Posts: 19
Joined: Mon Sep 19, 2005 2:34 pm
Contact:

Re: accessing matrix value

Postby Johan » Fri Feb 10, 2006 5:06 pm

hgpillai wrote:Hi, One of the input of my submodel is a 3*3 matrix, How do I access the elements individually ( say for example 2nd row, 2nd column value) in the code?
Thanks in advance


This can be done as follows:

See also the help file: chapter "language reference" and sub chapter "Matrices and vectors".


Code: Select all

L[4] = time; // Make element 4 of columned L equal to time.

D[2,5] = A[2,2]*B[1,1]; // Declare one element


Multiple elements (ranges)
To prevent multiple equations for assigning matrix elements, ranges can be assigned using a colon. E.g. 1:5 means element 1 to 5, 7:8 means element 7 and 8. Backward counting ranges (like 10:1) are not allowed!


Code: Select all

D[2,1:5] = A[1,1:5]; // D[2,1] = A[1,1], ... , D[2,5] = A[1,5]


Code: Select all

variables

real v[3],p[6,6];

equations

v = p[4:6,6]; // v[1] = p[4,6], ... , v[3] = p[6,6]
member 20-sim development team


Return to “Languages”

Who is online

Users browsing this forum: No registered users and 1 guest