; From: Dat Thuc Nguyen
; Newsgroups: comp.protocols.kermit.misc
; Subject: Matrix Operations in Kermit 95
; Date: Mon, 22 Mar 1999 16:12:25 GMT
; URL: http://www.smalltickle.com
;
; THE MATRIX IS AN ESSENTIAL ELEMENT OF MANY COMPUTING AREAS.
; KERMIT 95 CAN DO MATRIX OPERATIONS EASILY.
; THE FOLLOWING SCRIPT CREATES TWO MATRICES A AND B,
; THEN COMPUTES THEIR SUM: MATRIX C.
; THE USER-DEFINED FUNCTION display_matrix REQUIRES ONLY
; THE NAME OF THE MATRIX. THE SAME IS WITH undefine_matrix.

assign row 4
assign col 9

; CREATE MATRIX A AND MATRIX B
for \%r 1 \m(row) 1 {
    for \%c 1 \m(col) 1 {
        _assign A[\%r][\%c] \feval(\%r + \%c)
        _assign B[\%r][\%c] \feval(\%r * \%c)
    }
}

; CREATE MATRIX C = SUM OF MATRIX A AND MATRIX B
for \%r 1 \m(row) 1 {
    for \%c 1 \m(col) 1 {
        _assign C[\%r][\%c]-
        \feval(\m(A[\%r][\%c]) + \m(B[\%r][\%c]))
    }
}

; GIVEN THE NAME OF A MATRIX, DISPLAY IT IN ROWS & COLUMNS
; NO NEED FOR THE DIMENSION OF THE MATRIX
define display_matrix {
    local \%r \%c \%z
    assign \%r 1
    assign \%c 1
    while define \m(\%1[\%r][\%c]) {
        while define \m(\%1[\%r][\%c]) {
            assign \%z \%z \m(\%1[\%r][\%c])
            increment \%c
        }
        echo \%z
        undefine \%z
        increment \%r
        assign \%c 1
    }
}

echo Matrix A
display_matrix A

echo Matrix B
display_matrix B

echo Matrix A + Matrix B
display_matrix C

; GIVEN THE NAME OF A MATRIX, UNDEFINE IT.
; NO NEED FOR THE DIMENSION OF THE MATRIX
define undefine_matrix {
    local \%r \%c \%z
    assign \%r 1
    assign \%c 1
    while define \m(\%1[\%r][\%c]) {
        while define \m(\%1[\%r][\%c]) {
            _define \%1[\%r][\%c]
            increment \%c
        }
        increment \%r
        assign \%c 1
    }
}

undefine_matrix A
undefine_matrix B
undefine_matrix C

end
