Matrix multiplication simplified to Vector multiplication

In summary: If I convert the vector to a matrix, I can do the multiplication in a single step, whereas the algebraic method requires multiple calculations. However, I will test both methods and see which is faster.
  • #1
CyanBC
2
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
  • #2
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.
 
  • #3
Thanks for illuminating that for me. Now that I see it, I think the original method may be more efficient.
 

FAQ: Matrix multiplication simplified to Vector multiplication

What is matrix multiplication?

Matrix multiplication is a mathematical operation that involves multiplying two matrices to create a new matrix. It is commonly used in various fields, including physics, engineering, and computer science.

How is matrix multiplication simplified to vector multiplication?

Matrix multiplication can be simplified to vector multiplication when one of the matrices is a vector or a 1xN or Nx1 matrix. In this case, the resulting matrix will have the same dimensions as the other matrix and will be equal to the scalar product of the vector and each element of the other matrix.

What are the benefits of using vector multiplication over matrix multiplication?

Vector multiplication is often faster and more efficient than matrix multiplication, especially when dealing with large matrices. It can also simplify calculations and reduce the complexity of algorithms.

Can vector multiplication be performed on non-numeric matrices?

No, vector multiplication can only be performed on matrices that contain numerical values. Non-numeric matrices, such as those containing strings or characters, cannot be multiplied using this method.

Are there any limitations to using vector multiplication instead of matrix multiplication?

While vector multiplication can be faster and more efficient, it is not suitable for all types of calculations. It is limited to specific cases where one of the matrices is a vector or a 1xN or Nx1 matrix. In other cases, matrix multiplication will still be necessary.

Similar threads

Back
Top