I need to perform a quadruple integration using integral2
function in matlab. The code is below:
Rb = @(rho_1,phi_1) rho_1.*cos(phi_1);
Sb = @(rho_2,phi_2) rho_2.*cos(phi_2);
Tb = @(rho_1,phi_1,rho_2,phi_2) rho_1.*cos(phi_1)-rho_2.*cos(phi_2);
InnerIntegrand = @(rho_1,phi_1,rho_2,phi_2) Rb(rho_1,phi_1).*Sb(rho_2,phi_2).*Tb(rho_1,phi_1,rho_2,phi_2);
InnerIntegral = @(rho_1,phi_1) integral2(@(rho_2,phi_2) InnerIntegrand(rho_1,phi_1,rho_2,phi_2),0,3,0,2*pi);
II = integral2(InnerIntegral,0,3,0,2*pi);
Where InnerIntegrand (rho_1,phi_1,rho_2,phi_2)
is the integrand. The InnerIntegral
evaluates over rho_2
and phi_2
, which is being called from an outer integral2
(integration over rho_1
and phi_1
).
I get an error:
Error using .* Matrix dimensions must agree. Error in @(rho_1,phi_1,rho_2,phi_2)Rb(rho_1,phi_1).*Sb(rho_2,phi_2).*Tb(rho_1,phi_1,rho_2,phi_2) Error in @(rho_2,phi_2)InnerIntegrand(rho_1,phi_1,rho_2,phi_2) Error in integral2Calc>integral2t/tensor (line 238) Z1 = FUN(X(VTSTIDX),Y(VTSTIDX)); NFE = NFE + 1;
Is the error coming due to different array sizes of two integral2
calls? What is the issue?