Closed ashokrajab closed 1 year ago
Actually the method matrix.power(n)
works properly. What you are looking for is a function which applies an exponent to each element.
What matrix.power(n)
is doing:
http://mathonline.wikidot.com/powers-of-a-matrix#toc0
I have to see through all the functions and conceps where such element-wise power function would fit into or if it already exists. This is called Hadamard product.
Reference: https://en.wikipedia.org/wiki/Hadamard_product_(matrices)
There is now a new method Matrix.hadamardPower(int n)
which technically does what was asked for. Please try out.
This function uses the Hadmard product in order to produce Matrices with powers of n for each element. This function does not modify the origin matrix, a new matrix is created. When n=1
a copy of the source matrix is returned. As ⊚ is used to symbolize the Hadamard product operator, the operation looks like:
(A⊚B)ij = (A)ij⊚(B)ij
There are also test cases included for demonstration.
Thank you, Oliver.
Glad to See that there is still some life in LA4j.
matrix.power(2); This should square every element in my matrix and return the resultant matrix. But what it is actually doing is... it is multiplying itself and thrown error - java.lang.IllegalArgumentException: The number of rows in the left-hand matrix should be equal to the number of columns in the right-hand matrix.