MATLAB: Numeric Integration of Matrix Product

matricesnumerical integration

I'm working on a plate deformation problem and need to perform the integral:
k = int(B'*D*B)
where D is a 3×3 matrix of constant value, and B is a 3×5 matrix of functions in x and y.
I've used quad2d in the past to do the numeric integration over x and y, but I'm trying to figure out if there is a faster way to get the result than to use the quad2d function 25 times (each entry consists of 3 long terms).
If not, I'd have 25 lines of:
k11 = quad2d(@(x,y) (-pi^2/L1^2*sin(pi/L1*x).*sin(pi/L2*y)*D(1:1) + -pi^2/L2^2*sin(pi/L1*x).*sin(pi/L2*y)*D(2:1))*-pi^2/L1^2*sin(pi/L1*x).*sin(pi/L2*y) + (-pi^2/L1^2*sin(pi/L1*x).*sin(pi/L2*y)*D(1:2) + -pi^2/L2^2*sin(pi/L1*x).*sin(pi/L2*y)*D(2:2))*-pi^2/L2^2*sin(pi/L1*x).*sin(pi/L2*y) + 4*D(3:3)*(pi^2/(L1*L2)*cos(pi/L1*x).*cos(pi/L2*y))^2,xmin,xmax,ymin,max);
…and that's just plain ugly and has plenty of room for typos. I keep thinking there has to be a faster, more efficient way.
Thanks for any input!

Best Answer

Thanks to Walter Roberson for pointing out the symbolic toolbox. I wasn't aware I had it or what its capabilities were. Made the code ridiculously simple:
syms x y
k = int(int(B'*D*B,x,0,L1),y,0,L2)
Related Question