' Multiplication of matrix by vector using MAT.

'

' Potentially useful in neural networks to increase speed.

'

------------------

[This message has been edited by Erik Christensen (edited June 10, 2004).]

'

' Potentially useful in neural networks to increase speed.

'

Code:

#COMPILE EXE #REGISTER NONE #DIM ALL ' FUNCTION PBMAIN LOCAL i&,j&,k& LOCAL t$ DIM B(1 TO 3) AS LOCAL SINGLE ' Input vector DIM C(1 TO 4, 1 TO 3) AS LOCAL SINGLE ' Transformation matrix DIM A(1 TO 4) AS LOCAL SINGLE ' Resulting output vector ' DATA 4,0,1 : ' vector B ' DATA 1,-3,0,2 : ' matrix C - row 1 DATA 2,5,3,-1 : ' matrix C - row 2 DATA 4,6,1,8 : ' matrix C - row 3 ' ' Read arrays ' t = "vector B() = " + $CRLF FOR i = 1 TO 3 INCR k B(i) = VAL(READ$(k)) t = t + STR$(B(i))+" " NEXT t= t +$CRLF+$CRLF + "Matrix C() = " + $CRLF FOR i = 1 TO 3 FOR j = 1 TO 4 INCR k C(j,i) = VAL(READ$(k)) t=t+STR$(C(j,i))+" " NEXT t=t+$CRLF NEXT ' ' Do direct calculation ' FOR j = 1 TO 4 ' Column A(j) = 0! FOR k = 1 TO 3 ' Row A(j) = A(j) + B(k) * C(j,k) NEXT k NEXT j t= t +$CRLF+$CRLF t = t + "A() = C() * B() by direct calculation:" +$CRLF FOR j = 1 TO 4 t=t+STR$(A(j))+" " NEXT t=t+$CRLF +$CRLF ' ' Do calculation using MAT ' RESET A() MAT A() = C() * B() t = t + "A() = C() * B() by MAT calculation:" +$CRLF FOR j = 1 TO 4 t=t+STR$(A(j))+" " NEXT ' MSGBOX t,,"Matrix times Vector using MAT" ' END FUNCTION

[This message has been edited by Erik Christensen (edited June 10, 2004).]

## Comment