MATLAB: How Can I put some numbers in a sym and sum its cells

integration

I have the matrix [A]= [ a*(x^2)+y , b(y^3)+x ; d*(x^2)*y , c*y ].
and I have the matrix [B]=[1 2;3 4] which the first column of [B] is x and the socond culomn Of [B] is y .
I want to put x=1 and y=2 then x=3 and y=4 and sum A11. then do it for other cells.

Best Answer

syms a b c d
B = [ 1 2 ; 3 4] ;
x = reshape(B(:,1),1,1,[]);
y = reshape(B(:,2),1,1,[]);
A = [ a*(x.^2)+y , b*(y.^3)+x ; d*(x.^2).*y , c*y ] ;
a = arrayfun(@(z) sum(sum(A(:,:,z))), 1:size(A,3),'un',0);
celldisp(a)