Adding symbolic matrices along 3rd dimension

1 view (last 30 days)
Hi,
I have a symbolic 3-by-3-by-3 matrix as:
Q(:,:,1) =
[ a, b, c]
[ d, e, f]
[ g, h, i]
Q(:,:,2) =
[ a, d, g]
[ b, e, h]
[ c, f, i]
I added by sum command and I need to do it along 3rd dimension; so I did:
W = sum(Q,3)
But it returns me the error:
Error using mupadmex
Error in MuPAD command: Unable to define matrix over Dom::ExpressionField().
[(Dom::Matrix(Dom::ExpressionField()))::new]
Error in sym/privUnaryOp (line 1700)
Csym = mupadmex(op,args{1}.s,varargin{:});
Error in sym/sum (line 502)
s = privUnaryOp(A, 'symobj::prodsumdim', num2str(dim), '_plus');
I tried it with numeric matrices and it works. How Can I do it with symbolic matrices ?

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 17 Dec 2012
clear Q
syms a b c d e f g h i
Q(:,:,1) = [ a b c;d e f;g h i]
Q(:,:,2) = [ a, d, g;b, e, h; c, f, i]
[n1,n2,n3]=size(Q);
out=0;
for k=1:n3
out=out+Q(:,:,k)
end

More Answers (0)

Categories

Find more on Symbolic Math Toolbox 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!