Help in doing Matrix Multiplication

3 次查看(过去 30 天)
MAHESH
MAHESH 2013-10-9
回答: sixwwwwww 2013-10-9
Dear All, I am doing Matrix Multiplication of following 3 matrices .
( A of size 24x24, B of size 1*24 and C of 1 x 24 ]
(Matrix A contains digits while Matrix B & C contains 24 variables.
but I am not succeeding in getting the answer.
A = [93 65 41 47 31 30 37 30 31 31 34 32 30 68 2 68 -8 5 11 -1 15 20 13 52;
65 55 35 39 22 26 30 26 25 24 25 24 21 53 16 61 9 4 3 -3 11 18 11 28;
41 35 34 32 17 17 23 17 19 15 16 22 16 32 14 23 16 9 4 4 13 12 17 38;
47 39 32 50 27 30 29 18 21 21 15 27 24 38 20 39 33 5 4 2 12 10 19 33;
31 22 17 27 22 21 14 7 10 9 5 12 7 7 -4 23 1 -3 -1 0 3 3 11 25;
30 26 17 30 21 29 18 11 12 14 15 21 12 21 16 53 24 -1 -3 -3 4 4 8 12;
37 30 23 29 14 18 30 23 22 21 21 26 22 41 31 51 25 19 6 2 6 6 10 7;
30 26 17 18 7 11 23 32 22 24 22 23 20 55 27 22 19 6 -5 -4 2 -2 6 -2;
31 25 19 21 10 12 22 22 40 28 18 21 11 -15 35 24 19 34 13 17 19 11 9 8;
31 24 15 21 9 14 21 24 28 39 34 39 29 65 31 26 23 32 10 6 16 10 5 1;
34 25 16 15 5 15 21 22 18 34 55 60 45 12 48 73 44 41 19 10 25 15 9 25;
32 24 22 27 12 21 26 23 21 39 60 85 65 138 62 81 58 46 18 16 28 14 22 47;
30 21 16 24 7 12 22 20 11 29 45 65 74 138 54 67 55 28 17 4 17 11 17 45;
68 53 32 38 7 21 41 55 -15 65 111 138 138 573 30 73 15 -2 14 -19 15 21 32 96;
2 16 14 20 -4 16 31 27 35 31 48 62 54 30 152 151 152 58 23 20 34 19 19 9;
68 61 23 39 23 53 51 22 24 26 73 81 67 73 151 448 159 53 20 -10 18 44 11 53;
-8 9 16 33 1 24 25 19 19 23 44 58 55 15 152 159 220 55 25 18 34 11 22 16;
5 4 9 5 -3 -1 19 6 34 32 41 46 28 -2 58 53 55 191 91 82 76 35 16 35;
11 3 4 4 -1 -3 6 -5 13 10 19 18 17 14 23 20 25 91 81 62 63 37 21 58;
-1 -3 4 2 0 -3 2 -4 17 6 10 16 4 -19 20 -10 18 82 62 67 59 22 27 56;
15 11 13 12 3 4 6 2 19 16 25 28 17 15 34 18 34 76 63 59 76 42 31 79;
20 18 12 10 3 4 6 -2 11 10 15 14 11 21 19 44 11 35 37 22 42 47 17 52;
13 11 17 19 11 8 10 6 9 5 9 22 17 32 19 11 22 16 21 27 31 17 37 73;
52 28 38 33 25 12 7 -2 8 1 25 47 45 96 9 53 16 35 58 56 79 52 73 244]
B = [P(1) P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) P(10) P(11) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19) P(20) P(21) P(22) P(23) P(24)]
C = [P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) P(10) P(11) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19) P(20) P(21) P(22) P(23) P(24) P(1)]
I want to perform A*B*C Can any body please tell me the syntax as I am new to Matlab.
  1 个评论
Jan
Jan 2013-10-9
Hint:
B = [P(1) P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) P(10) P(11) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19) P(20) P(21) P(22) P(23) P(24)]
or:
B = P(1:24);
The 2nd method contains less chances to insert a bug.

请先登录,再进行评论。

回答(3 个)

ES
ES 2013-10-9
编辑:ES 2013-10-9
mathematically, to perform AXB for matrix A of dimensions m1,n1 and Matrix B of dimensions m2 and n2, n1 and m2 should be equal. In your case this condition is not satisfied.
But if you just need scalar multiplication, i.e., multiplying A(:,1) by B(1), A(:,2) by B(2) , A(:,3) by B(3) etc.. this can be done.

MAHESH
MAHESH 2013-10-9
Thank You very much sir for your kind help . But if I take C as column vector i.e if I take C', then if I try C' x B then it comes out to be (24 x 24) matrix. Later on if i multiply this product by A which is (24 x 24), then I should get the answer, but I am not getting. where I am wrong ????

sixwwwwww
sixwwwwww 2013-10-9
Mahesh you can do it using symbolic expression in MATLAB as following:
A = [93 65 41 47 31 30 37 30 31 31 34 32 30 68 2 68 -8 5 11 -1 15 20 13 52;
65 55 35 39 22 26 30 26 25 24 25 24 21 53 16 61 9 4 3 -3 11 18 11 28;
41 35 34 32 17 17 23 17 19 15 16 22 16 32 14 23 16 9 4 4 13 12 17 38;
47 39 32 50 27 30 29 18 21 21 15 27 24 38 20 39 33 5 4 2 12 10 19 33;
31 22 17 27 22 21 14 7 10 9 5 12 7 7 -4 23 1 -3 -1 0 3 3 11 25;
30 26 17 30 21 29 18 11 12 14 15 21 12 21 16 53 24 -1 -3 -3 4 4 8 12;
37 30 23 29 14 18 30 23 22 21 21 26 22 41 31 51 25 19 6 2 6 6 10 7;
30 26 17 18 7 11 23 32 22 24 22 23 20 55 27 22 19 6 -5 -4 2 -2 6 -2;
31 25 19 21 10 12 22 22 40 28 18 21 11 -15 35 24 19 34 13 17 19 11 9 8;
31 24 15 21 9 14 21 24 28 39 34 39 29 65 31 26 23 32 10 6 16 10 5 1;
34 25 16 15 5 15 21 22 18 34 55 60 45 12 48 73 44 41 19 10 25 15 9 25;
32 24 22 27 12 21 26 23 21 39 60 85 65 138 62 81 58 46 18 16 28 14 22 47;
30 21 16 24 7 12 22 20 11 29 45 65 74 138 54 67 55 28 17 4 17 11 17 45;
68 53 32 38 7 21 41 55 -15 65 111 138 138 573 30 73 15 -2 14 -19 15 21 32 96;
2 16 14 20 -4 16 31 27 35 31 48 62 54 30 152 151 152 58 23 20 34 19 19 9;
68 61 23 39 23 53 51 22 24 26 73 81 67 73 151 448 159 53 20 -10 18 44 11 53;
-8 9 16 33 1 24 25 19 19 23 44 58 55 15 152 159 220 55 25 18 34 11 22 16;
5 4 9 5 -3 -1 19 6 34 32 41 46 28 -2 58 53 55 191 91 82 76 35 16 35;
11 3 4 4 -1 -3 6 -5 13 10 19 18 17 14 23 20 25 91 81 62 63 37 21 58;
-1 -3 4 2 0 -3 2 -4 17 6 10 16 4 -19 20 -10 18 82 62 67 59 22 27 56;
15 11 13 12 3 4 6 2 19 16 25 28 17 15 34 18 34 76 63 59 76 42 31 79;
20 18 12 10 3 4 6 -2 11 10 15 14 11 21 19 44 11 35 37 22 42 47 17 52;
13 11 17 19 11 8 10 6 9 5 9 22 17 32 19 11 22 16 21 27 31 17 37 73;
52 28 38 33 25 12 7 -2 8 1 25 47 45 96 9 53 16 35 58 56 79 52 73 244];
A_sym = sym('A%d%d', [24 24]);
P = sym('P%d', [1, 24]);
B = [P(1) P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) P(10) P(11) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19) P(20) P(21) P(22) P(23) P(24)];
C = [P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) P(10) P(11) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19) P(20) P(21) P(22) P(23) P(24) P(1)]';
result = A_sym * (B * C);
result_new = subs(result, A_sym, A);
After this if you define a new B and C matrices then again use subs to replace symbols with their equivalent numeric values. Hope it will help you

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by