Matrix multiplication simplified to Vector multiplication

Click For Summary
SUMMARY

The discussion focuses on optimizing matrix multiplication by avoiding unnecessary conversions from vectors to matrices. A user presents a problem involving a vector (V1) and its matrix form (M1), seeking a more computationally efficient method to calculate the sum of elements resulting from matrix multiplication. A solution is provided, demonstrating that algebraic manipulation can yield the same result directly from the vector, significantly improving performance. The derived formula for the sum is Σ = (a+d)(a+b+c+d) - 2(ad-bc), which can be implemented in a subroutine for efficiency.

PREREQUISITES
  • Understanding of vector and matrix operations
  • Familiarity with algebraic manipulation techniques
  • Basic programming skills for implementing mathematical routines
  • Knowledge of computational efficiency concepts
NEXT STEPS
  • Implement a subroutine for vector-based calculations in Python or MATLAB
  • Explore advanced algebraic techniques for optimizing matrix operations
  • Study computational complexity in matrix multiplication algorithms
  • Learn about libraries that optimize matrix operations, such as NumPy for Python
USEFUL FOR

Mathematicians, data scientists, software developers, and researchers in remote sensing looking to enhance computational efficiency in matrix operations.

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.
 
Physics 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.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K