Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Science, Health & Environment
Mathematics, Physics & Chemistry
How do I solve this matrix?
oom17
Hi, I was just wondering if anybody could help me solve these questions? I have been working on them for hours and haven't found any help online. Any part of the script would be much appreciated -Thanks
Matrix A is given as
A=[1 3 5; 7 9 11; 13 15 17]
Matrix B is given as
B=[2 4 6; 8 10 12; 14 16 18]
(i) use nested “for” loops to determine a matrix C from the matrix product (*) of A and B
(Note: Here you need to use the “for” loops to sum the products of the elements of A and B,
Where cij is the (i,j) element of matrix C, etc..
(ii) In your script you must use an “if” statement to check that each element of C is identical
to the answer given by the matlab command (A*B). Your script should write a warning in
the command window if any elements are found to be different from the matlab solution.
Find more posts tagged with
technology
matrix
math
matlab
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Yakuza
Some pseudocode for you (using a c++/ c# / java format) :
for( i = 1; i <= 3; i++) { for( j = 1; j <= 3; j++) { c(i,j) = ...... } }
I'm not going to do the thing for you, but I'll give you a hint.
When you multiply two 3*3 matrices like the following:
a11 a12 a13
a21 a22 a23
a31 a32 a33
and
b11 b12 b13
b21 b22 b23
b31 b32 b33
the entries for c11,c21 and c22 are:
c11 = a11b11+a12b21+a13b31
c21 = a21b11+a22b21+a23b31
c22 = a21b22+a22b22+a23b32
If you write out the others, you'll see a pattern (some index values will correspond to i, others to j and others will be constant).
Come up with a formula that fits this pattern and that's what'll go in the inner loop above.
I've never used matlab so I can't help with the second part, but I'd imagine you'd want some nested loops like the above to compare c(i,j) against the ith row and jth column of the matlab result.