function [comp,compliance,dcdx] = COMP(U,ke_all,ke_dx,nx,ny,nz) comp =zeros(nz,ny,nx); compliance = 0.; dcdx=zeros(nz,ny,nx); for elz = 1:nz % z = nz*h - (elz-1)*h; for ely = 1:ny % y = (ely-1)*h + 0.5*h; for elx = 1:nx % x = (elx-1)*h + 0.5*h; n2 = (nz+1)*(ny+1)*elx + (nz+1)*(ely-1) + elz; n1 = n2-(nz+1)*(ny+1); n3 = n1 + (nz+1); n4 = n2 + (nz+1); n5 = n1 + 1; n6 = n2 + 1; n7 = n3 + 1; n8 = n4 + 1; Ue = U([3*n1-2; 3*n1-1; 3*n1; 3*n2-2; 3*n2-1; 3*n2; 3*n3-2; 3*n3-1; 3*n3; 3*n4-2; 3*n4-1; 3*n4; 3*n5-2; 3*n5-1; 3*n5; 3*n6-2; 3*n6-1; 3*n6; 3*n7-2; 3*n7-1; 3*n7; 3*n8-2; 3*n8-1; 3*n8]); comp(elz,ely,elx) = Ue'* ke_all(:,:,elz,ely,elx)*Ue; compliance = compliance + comp(elz,ely,elx); dcdx(elz,ely,elx) =-Ue'*ke_dx(:,:,elz,ely,elx)*Ue; end end end end