MHB Matrix multiplication simplified to Vector multiplication

AI Thread Summary
The discussion focuses on optimizing matrix multiplication by avoiding unnecessary conversions from vectors to matrices in computational tasks. A user illustrates their problem using a vector and its matrix form, seeking a more efficient way to achieve the same result without conversion. Another participant provides an algebraic approach to calculate the sum of elements directly from the vector, suggesting a formula that can be implemented in code. This method could significantly speed up computations compared to traditional matrix multiplication. The conversation highlights the importance of mathematical manipulation for efficiency in programming tasks.
CyanBC
Messages
2
Reaction score
0
Hello, I'm not sure where to put this. I have spent the last week (14+ hour days) editing some code I have for selecting representative spectra for a remote sensing masters thesis I'm working on. The program is very-very slow, and I've been trying to speed it up as much as possible by NOT performing any conversions that are unnecessary. Which leads me to the problem I've been struggling with for the last 10 hours.

I'll use a simple example:

I have a vector (V1)
[0,1,2,3]
Which I reform into a matrix (M1)
[0,1
2,3]

and perform matrix multiplication on itself, M1*M1
which returns a matrix
[2,3
6,11]
from which I take the sum total of all items in the matrix. So the desired answer is = 22

Is there any way I can do this directly with the original vector (V1), without having to convert the original vector to a matrix? I know conversion is the easiest way - but not the most computationally efficient. And I'm nor so good at the maths.
 
Mathematics news on Phys.org
CyanBC said:
Hello, I'm not sure where to put this. I have spent the last week (14+ hour days) editing some code I have for selecting representative spectra for a remote sensing masters thesis I'm working on. The program is very-very slow, and I've been trying to speed it up as much as possible by NOT performing any conversions that are unnecessary. Which leads me to the problem I've been struggling with for the last 10 hours.

I'll use a simple example:

I have a vector (V1)
[0,1,2,3]
Which I reform into a matrix (M1)
[0,1
2,3]

and perform matrix multiplication on itself, M1*M1
which returns a matrix
[2,3
6,11]
from which I take the sum total of all items in the matrix. So the desired answer is = 22

Is there any way I can do this directly with the original vector (V1), without having to convert the original vector to a matrix? I know conversion is the easiest way - but not the most computationally efficient. And I'm nor so good at the maths.
Hi Cyan and welcome to MHB! Suppose you do that same sequence of calculations algebraically, starting with a vector $[a,b,c,d].$ Then the matrix is $\begin{bmatrix} a&b \\c&d \end{bmatrix}.$ When you square it you get $\begin{bmatrix} a^2 + bc&b(a+d) \\c(a+d)&bc +d^2 \end{bmatrix}.$ The sum of the elements is $\Sigma = a^2 + 2bc + d^2 + (b+c)(a+d).$ With a little bit of algebraic manipulation you can write that as $\Sigma = (a+d)(a+b+c+d) - 2(ad-bc).$

Presumably you can write a little subroutine to input $[a,b,c,d]$ and get out $\Sigma.$ That ought to be a bit faster than going via a matrix computation.
 
Thanks for illuminating that for me. Now that I see it, I think the original method may be more efficient.
 
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Thread 'Unit Circle Double Angle Derivations'
Here I made a terrible mistake of assuming this to be an equilateral triangle and set 2sinx=1 => x=pi/6. Although this did derive the double angle formulas it also led into a terrible mess trying to find all the combinations of sides. I must have been tired and just assumed 6x=180 and 2sinx=1. By that time, I was so mindset that I nearly scolded a person for even saying 90-x. I wonder if this is a case of biased observation that seeks to dis credit me like Jesus of Nazareth since in reality...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Back
Top