04-08-2021 11:51 AM
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
Solved! Go to Solution.
04-08-2021 11:54 AM
If you would attach your attempt (VI with default data in the controls, not a picture), we could probably tell you what's wrong.
04-08-2021 12:14 PM - edited 04-08-2021 12:15 PM
here is one of them that only give diagonals i seem to have written over the one that only provieds the first line
04-08-2021 12:18 PM - edited 04-08-2021 12:47 PM
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:
04-08-2021 12:34 PM
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.
04-08-2021 12:46 PM
@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.
04-08-2021 12:50 PM - edited 04-08-2021 12:52 PM
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.
04-08-2021 12:54 PM
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! 😉
04-08-2021 01:12 PM
@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. 😄
(Not sure why it does the (partial) size validation, especially since AxB will later do that anyway....)
04-08-2021 01:20 PM
@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 😛