Calculating double integral of two variable

I am having some issues calculation a double integral with two variable. my function F= {{sinc^2(X)sinc^2(Y)} *{sin^2(phi)+cos^2(theta)cos^2(phi)}}(sin(theta)).
I define X=(pi/2).*sin(theta).*cos(phi) and Y=(pi/2).*sin(theta).*sin(phi); and theta=[0 pi/2]; phi=[0 2*pi].
So, I have started
syms X Y theta phi
theta=linspace(0,pi/2);
phi=linspace(0,2*pi);
X=(pi/2).*sin(theta).*cos(phi);
Y=(pi/2).*sin(theta).*sin(phi);
func1=(sinc(X/pi).*sinc(Y/pi)).^2;
func2={(sin(theta))^2}+{cos(theta)cos(phi)}^2;
func=func1*func2;
func3=sin(theta);
Function1=vpa(int(func,0,2*pi),5)*vpa(int(func3,0,pi/2),5)
But I have also tried to rewrite
syms X Y theta phi
X=(pi/2).*sin(theta).*cos(phi);
Y=(pi/2).*sin(theta).*sin(phi);
Function1=@(theta,phi) ((sinc(X/pi).*sinc(Y/pi))^2 *((sin(phi))^2+(cos(theta)*cos(phi))^2))*(sin(theta));
E=integral2(Function1,0,pi/2,0,2*pi)

Answers (1)

Hi Ismael,
To calculate the double integral of a two variable function, integral2 accepts only numeric variables. So, the entire function with two variable is defined as a single inline executable expression (anonymous function handles) as shown below.
Function1 = @(theta,phi) (((sinc((pi/2).*sin(theta).*cos(phi)).*sinc((pi/2).*sin(theta).*sin(phi))).^2).*((sin(phi)).^2+(cos(theta).*cos(phi)).^2)).*(sin(theta));
E = integral2(Function1,0,pi/2,0,2*pi)
For more information, refer the following link

2 Comments

The first statement contradicts the fact that int(...) with two calls exist if there’s an explicit solution.
int can accept both numeric and symbolic variables, whereas integral2 accepts only numeric variables as integral2 solves the integral numerically. Also, thanks for pointing that out, I can edit the answer specific to integral2.

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 19 Jun 2020

Edited:

on 22 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!