Multiplication of Array of Matrices with Array of scalars
3 views (last 30 days)
Show older comments
Hello, can anyone help me ? I did some operations with scalar matrix: Example:
A= [1 2 3 4 5];
C= [0.5 0.25 0 0 0.25; 0.25 0.5 0.25 0 0; 0 0.25 0.5 0.25 0; 0 0 0.25 0.5 0.25; 0.25 0 0 0.25 0.5];
A*C=[ 2.25 2 3 4 3.75]; % usual in matrix multiplication
Now my task is to change A elements into 2x2 matrices and then to do the same operation, for example, C is the same matrix:
AA= [ [1.75 4;-0.25 -0.25] [1.55 4;-0.25 -0.45] [1.75 4;-0.25 -0.25 ] [1.65 4;-0.25 -0.35] [1.15 4;-0.25 -0.85]];
% I construct this as a cell array AA is cell 1x5, where each variable is a 2x2 matrix
I want to multiply each variable in a cell array (which is a 2x2 matrix) coefficients in C, if to make clear, the multiplication should be performed like this;
AA*C = [ [1.75 4;-0.25 -0.25]*0.5+ [1.55 4;-0.25 -0.45] *0.25+0+0+[1.15 4;-0.25 -0.85]*0.25
[1.75 4;-0.25 -0.25]*0.25 +[1.55 4;-0.25 -0.45]*0.5+ [1.75 4;-0.25 -0.25 ]*0.25+0+0
0+[1.55 4;-0.25 -0.45] *0.25+[1.75 4;-0.25 -0.25 ]*0.5+[1.65 4;-0.25 -0.35]*0.25+0
0+0+[1.75 4;-0.25 -0.25 ]*0.25+[1.65 4;-0.25 -0.35]*0.5+[1.15 4;-0.25 -0.85]*0.25
[1.75 4;-0.25 -0.25] *0.25 +0+0+[1.65 4;-0.25 -0.35]*0.5+[1.15 4;-0.25 -0.85]*0.25 ];
How can I get this – to preserve usual matrix operation? Thank You.
2 Comments
Stephen23
on 10 Mar 2018
"I did some operations with scalar matrix"
A scalar matrix would have size 1x1x1x1x..., but I don't see any matrices in your code with that size. What are you referring to?
Answers (1)
Ahmet Cecen
on 10 Mar 2018
I believe you are over-complicating your problem by thinking as if you are working things out on a board. Your operation is separable and doesn't need you to store things in a cell array or represent them as matrices. From the exact assignment of AA in your question as an array:
AA = reshape(AA, 4,5);
Now each of your "matrices" is a column. Where:
AA*C(1,:)'
will give you first row of AA*C. If you have to return a matrix:
reshape(AA*C(1,:)',2,2);
Now you can loop over this to solve your problem. You can also store C as a cell instead and use cellfun, but shouldn't be necessary in your case.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!