18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Programming</strong> <strong>Language</strong> Concepts<br />

2.27.3 A Matrix Multiplication Program<br />

Two matrices (double-subscripted variables) are to be read from data records. Matrix A is input row<br />

by row. That is, the values appear in the order A(1,1), A(1,2), ..., A(1,M), A(2,1),<br />

..., A(2,M), A(3,1), ..., A(N,M). Matrix B appears column by column in the order<br />

B(1,1), B(2,1) ..., B(S,1), B(1,2), ..., B(S,2), B(1,3), ..., B(R,S).<br />

The values of the matrix dimensions N, M, R, and S precede the element data. This program reads<br />

the data, checks that multiplication is possible and, if so, multiplies the matrices A and B together<br />

placing the values in matrix C.<br />

For matrix multiplication to be possible, M must equal R. The rules for computation are:<br />

if A has dimensions N, M and<br />

B has dimensions M, S then<br />

C has dimensions N, S and the elements of C are computed as:<br />

M<br />

C(I,K) = Σ A(I,J) * B(J,K)<br />

j = 1<br />

The program below illustrates the use of the reserve statement with variable dimensions executed<br />

in the body of a program, two forms of read statement formats for inputting subscripted variables,<br />

nested for loops, and the use of the list statement.<br />

91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!