MatrixMult() Function , Handle MN x NP

18 views
Skip to first unread message

Bert Mariani

unread,
Mar 10, 2023, 10:32:46 PM3/10/23
to The Ring Programming Language
Hello Mahmoud

Func MatrixMulti()

See attached:  Ring-Matrix-Func-2.ring
I modified the Function to handle other than square arrays. Ex 3x3
In Linear Algebra the following are valid
   MN x NP  => MP   as long as both N's are equal
   2x3  3x2  => 3x3
   3x1  1x3  => 3x3
   2x3   2x3 =>  Invalid

=======================
Output

Test MatrixMulti( MN x NP)
Matrix A 2x3
 1 0 3
 2 -1 -2
Matrix B 3x3
 -2 4 2
 1 0 0
 -1 1 -1
Matrix multiply AxB = C 2x3
 -5 7 -1
 -3 6 6
Matrix Check: C
 -5 7 -1
 -3 6 6
------------------------------

Matrix D 3x1
 2
 -1
 1
Matrix E 1x3
 1 -2 -3
Matrix multiply DxE = F 3x3
 2 -4 -6
 -1 2 3
 1 -2 -3
Matrix Check: F
 2 -4 -6
 -1 2 3
 1 -2 -3
---------------------------

Matrix G 2x3
 5 4 4
 -3 1 2
Matrix H 2x3
 1 2 -7
 0 -5 1

Matrix multiply GxH = K  Invalid
Error: Matrix Dimension: MxN NxP : N:3 MUST EQUAL N:2
Matrix Check return: 1 : K is Invalid:  MN x NP , N<>N
--------------------------

Ring-Matrix-Func-2.ring

Mahmoud Fayed

unread,
Mar 11, 2023, 8:29:43 AM3/11/23
to The Ring Programming Language
Hello Bert

Thank you very much for sharing :D

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Mar 11, 2023, 9:20:18 AM3/11/23
to The Ring Programming Language
Hello Bert


Greetings,
Mahmoud

On Saturday, March 11, 2023 at 6:32:46 AM UTC+3 Bert Mariani wrote:
Reply all
Reply to author
Forward
0 new messages