Matrix and matrix multiplication (C++)

preview_player
Показать описание
This video explains firstly some basics of matrix multiplication, then we turn the theory into a C++ code.
Рекомендации по теме
Комментарии
Автор

Your code only works because you used a square mat1 matrix.
The head of the inner for-loop should be either k<mat1[0].size() or k<mat2.size() instead of k<dimM!

mvogt
Автор

Thank you Marek. You clarified the situation for me.

autobahn
Автор

Haven't tested it.  But, after reviewing the mathematics, mvogt seems absolutely correct!  The code doesn't work in general.  Needs to be tested where both matrices are non-square.  It's disappointing that mvogt's excellent observation was simply ignored!

paulepstein
Автор

I agree, this is definitely not a state-of-the art approach. But it works.

xkolm
Автор

28:00 for the index part, that's what you came for

Hankextreme
Автор

After trying this code out, it did not work as you had it. The user "mvogt" solved the problem with his comment below. After trying mvogt's fix, it is working just fine.

tharealminipunch
Автор

this is very bad practice. you're basically writing proceduraly in C++ rather than using object oriented programming. I would created a class matrix (maybe even templated) that the constructor will force the user to enter M and N, and overload operator* instead of creating a mmult outside of class. I will not comment on the writing style and syntax errors, as there are many (some you don't see because you don't have compiler flags to notify upon them).
I appreciate that you uploaded a tutorial video, but title c++ is very misleading, it would be better to write it in pseudo code.

ofiragranat
Автор

This isn't very efficient. it would be better if the program asked the user for number of matrix columns and rows for both and also asked the values. Having to edit the code every time if you want to change it just doesn't seem very efficient

miguelangelbarragan