LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matrix multiplication

Solved!
Go to solution

I have been set the challenge of multiplying 2 matrices (3x3) together without using the AxB block in linear algebra. I have transposed the second matrix to make it so i only have to multiply and add on rows. I am able to either get all the diagonals or the only the first row, and im struggling with understanding what im actually missing any help is appreciated.

Thank you in advanced

0 Kudos
Message 1 of 10
(4,588 Views)

If you would attach your attempt (VI with default data in the controls, not a picture), we could probably tell you what's wrong.

0 Kudos
Message 2 of 10
(4,586 Views)

here is one of them that only give diagonals i seem to have written over the one that only provieds the first line 

0 Kudos
Message 3 of 10
(4,556 Views)
Solution
Accepted by topic author interestedtolearn

Turning a 1D array into a matrix, does not really make is square. You need to autoindex on seperate stacked loops to get a 2D result.

 

See if this can give you some ideas. Make sure to fully understand it:

 

altenbach_0-1617902855120.png

 

 

Message 4 of 10
(4,553 Views)

oh ok that actually makes a lot of sense i was playing with the autoindexing to try and get it to work but i think i see what youre saying.

0 Kudos
Message 5 of 10
(4,545 Views)

@interestedtolearn wrote:

oh ok that actually makes a lot of sense i was playing with the autoindexing to try and get it to work but i think i see what youre saying.


Your inner code could be simplified significantly. For example if you initialize the shift register with zero, you don't need the case structure.

 

Here's how your code could look like after adding the outer loop. Mine is probably more efficient because it eliminates the inner loop and it can utilize SIMD instructions to multiply the two 1D arrays. If the matrices are very large, you could try to parallelize the outer FOR loop and test if it makes a difference.

 

altenbach_0-1617903937326.png

 

0 Kudos
Message 6 of 10
(4,533 Views)

I also strongly recommend to place the real AxB on the block diagram during development. It gives you the known good result to validate your own code! Try with non-square matrices, for example.

0 Kudos
Message 7 of 10
(4,528 Views)

So this sounds like a homework problem, and this technically solves your problem, but I bet it's not what you're looking for... but it works! 😉

 

matrix multiplication.png

0 Kudos
Message 8 of 10
(4,524 Views)

@BertMcMahan wrote:

So this sounds like a homework problem, and this technically solves your problem, but I bet it's not what you're looking for... but it works! 😉

 

 


Well, technically the multiply primitive turns into a subVI when wired with matrices, and, (surprise!) we still have the AxB from the linear algebra palette, just not on the toplevel. 😄

 

altenbach_0-1617905422134.png

 

(Not sure why it does the (partial) size validation, especially since AxB will later do that anyway....)

 

0 Kudos
Message 9 of 10
(4,514 Views)

@altenbach wrote:

@BertMcMahan wrote:

So this sounds like a homework problem, and this technically solves your problem, but I bet it's not what you're looking for... but it works! 😉

 

 


Well, technically the multiply primitive turns into a subVI when wired with matrices, and, (surprise!) we still have the AxB from the linear algebra palette, just not on the toplevel. 😄

 

 


Well now ain't that sneaky! I had no idea 😛

0 Kudos
Message 10 of 10
(4,510 Views)