Sum of elements of a multidimensional symbolic array

I have a multidimensional array whose entries are polynomials. I would like to obtain the sum of all elements in the array. I know that is it is a vector is just need to use sum, if it is a matrix I would use sum twice, if it is a 3 array I would use sum three times and so on. In MATLAB, it worked fine up to a matrix, but when I tried the command sum for a 3 array it gave me the message:
Error using mupadmex Error in MuPAD command: Input arguments must be 2-D.
Error in sym/privUnaryOp (line 826) Csym = mupadmex(op,args{1}.s,varargin{:});
Error in sym/sum (line 59) s = privUnaryOp(A, 'symobj::prodsum', '_plus');
Is there any way around this?

 Accepted Answer

syms x
a(1,1,1)=x
a(1,1,2)=x^2
a(1,1,3)=x^3
out=sum(a(:))

More Answers (0)

Categories

Find more on Mathematics 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!