d. Example
E
valuate , where is the region .
[If you want to try it, for r = 0.5, I = 0.57.]
This is equivalent to averaging the integrand over a circular area, thusly
.
Of course, often the shape of the region of integration isn’t a simple rectangle or circle.
e. Example script
% Script to carry out 2-dim integration via random sampling
f=inline('sin(sqrt(log(x+y+1)))')
n=100;
r=0.5;
r2=r*r;
sum=0;
ax=0.5-r;
ay=0.5-r;
bx=r+0.5;
by=r+0.5;
m=0
for i=1:n
ex=rand*(bx-ax)+ax;
why=rand*(by-ay)+ay;
are=(ex-0.5)^2+(why-0.5)^2;
if are<=r2
sum=sum+f(ex,why);
m=m+1;
end
end
sum=sum*(by-ay)*(bx-ax)/m;
fprintf('Integral of f(x,y) over the circle = %g',sum)
Share with your friends: |