MATLAB: Numerical Integration with functions as borders

function bordernumerical integration

Hi. I am new to this Forum and I have a question to which I did yet not find an appropriate answer. Maybe someone can help.
I would like to solve an triple integral which has a function as border (I am not sure if this is the right word for the boundaries of an integral, but let's assume it is). The border-function itself depends on the variable which will be integrated with the 2nd integral.
For instance, look at this integral:
My problem is not analyticly solvable (using symbolic variables ans int()-function), so I need a numeric solution. Working with quad() and function-handles as borders doesn't work either. So how to integrate?
Thank you for your help,
Manu

Best Answer

QUAD2D accepts function handles for limits. Take care that you make them "vectorized" (usually just use .*, .+, and ./ instead of *, +, and /).
>> h1 = @(phi)-2 + sin(phi); % or whatever

>> h2 = @(phi)2 - cos(phi); % or whatever
>> B = @(xi,b)quad2d(@(phi,x)(1./(h1(phi) - h2(phi))).*(1./(b-(xi-x).^2).^(3/2)),-pi,pi,h1,h2);
>> B(5,100)
ans =
-0.010761692235804
-- Mike
function q = quad3d(f,x1,x2,y1x,y2x,z1xy,z2xy)
q = quadgk(@inner,x1,x2);
function q = inner(x)
q = arrayfun( ...
@(xs,y1s,y2s) ...
quad2d(@(y,z)f(xs*ones(size(y)),y,z),y1s,y2s, ...
@(y)z1xy(xs*ones(size(y)),y), ...
@(y)z2xy(xs*ones(size(y)),y)), ...
x,y1x(x),y2x(x));
end
end