Programming in lua
Budget: $30 – $250 USD
Programming language is lua, matrix problem
Matrix Multiplication
Matrices are two dimensional arrays of numbers. Matrix dimension are typically listed in row, column order as are their indices. An m × p matrix has m rows and p columns. Two matrices can be multiplied if their inner dimensions match. That is, if matrix A has dimensions m × p, and matrix B has dimensions p × q then the result of their multiplication will have dimension m × q. If the number of columns in A does not match the number of rows in B, the matrices cannot be multiplied.
The multiplication itself is a combination of multiplication and addition. The simplest way to accomplish this multiplication is via an O(n3
) algorithm as shown:
C = new matrix of size A.rows, B.columns Set all entries in C to zero For i = 1 to A.rows For j = 1 to B.columns For k = 1 to B.rows C[i,j] = C[i,j] + A[i,k] * B[k,j]
End For End For End For
Note that the above assumes that the for loops include both the beginning and end of their range, and that the arrays have an index beginning at 1 (as is standard mathematics notation). Also C[i,j] refers to the entry at row i column j in matrix C.
Your program should ask for the dimensions of A followed by the variables in A. It should then follow suit for B. If the two arrays are not compatible, your program should indicate that they cannot be multiplied. Otherwise it should carry out the multiplication.
The first example run is of two incompatible matrices: Matrix A ========Rows: 2
Cols: 2
Values:
1 2
3 4
Matrix B
========
Rows: 3
Cols: 1
Values:
1
2
3
Incompatible Dimensions
And here is a run with compatible matrices:
Matrix A
========
Rows: 2
Cols: 2
Values:1 2 3 4
Matrix B ======== Rows: 2 Cols: 3 Values: 1 2 0 0 3 4
A x B = 1 8 8 3 18 16
Note that for the final display, you can do something simple like put tabs in between the numbers. Make it look as neat as possible, but I will not be counting spaces in between for exactness. Note that your matrices should allow for floating point values.
Matrix Multiplication
Matrices are two dimensional arrays of numbers. Matrix dimension are typically listed in row, column order as are their indices. An m × p matrix has m rows and p columns. Two matrices can be multiplied if their inner dimensions match. That is, if matrix A has dimensions m × p, and matrix B has dimensions p × q then the result of their multiplication will have dimension m × q. If the number of columns in A does not match the number of rows in B, the matrices cannot be multiplied.
The multiplication itself is a combination of multiplication and addition. The simplest way to accomplish this multiplication is via an O(n3
) algorithm as shown:
C = new matrix of size A.rows, B.columns Set all entries in C to zero For i = 1 to A.rows For j = 1 to B.columns For k = 1 to B.rows C[i,j] = C[i,j] + A[i,k] * B[k,j]
End For End For End For
Note that the above assumes that the for loops include both the beginning and end of their range, and that the arrays have an index beginning at 1 (as is standard mathematics notation). Also C[i,j] refers to the entry at row i column j in matrix C.
Your program should ask for the dimensions of A followed by the variables in A. It should then follow suit for B. If the two arrays are not compatible, your program should indicate that they cannot be multiplied. Otherwise it should carry out the multiplication.
The first example run is of two incompatible matrices: Matrix A ========Rows: 2
Cols: 2
Values:
1 2
3 4
Matrix B
========
Rows: 3
Cols: 1
Values:
1
2
3
Incompatible Dimensions
And here is a run with compatible matrices:
Matrix A
========
Rows: 2
Cols: 2
Values:1 2 3 4
Matrix B ======== Rows: 2 Cols: 3 Values: 1 2 0 0 3 4
A x B = 1 8 8 3 18 16
Note that for the final display, you can do something simple like put tabs in between the numbers. Make it look as neat as possible, but I will not be counting spaces in between for exactness. Note that your matrices should allow for floating point values.
Related categories:
Business, Accounting, Human Resources & Legal
Algorithm
C++ Programming
Assembly
Lua