MATLAB: Is it possible to numerically solve the following nested integral e.g. with a different syntax in MATLAB: nintegrate​(f(y)/(nin​tegrate(g(​x,y), x, a, b)), y, c, d)

MATLABnestednintegrate

Is it possible to do a nested numerical integration in MATLAB. Using "nintegrate(f(y)/(nintegrate(g(x,y), x, a, b)), y, c, d)" does not work. Is there a different syntax that will work?

Best Answer

Try
function main
g=@(x,y) ...;
f=@(y) ...;
a=...;
b=...;
c=...;
d=...;
sol=integral(@(y)fun_y(y,g,f,a,b),c,d);
function Iy = fun_y(y,g,f,a,b)
for i = 1:numel(y)
y_actual = y(i);
fun_x = @(x) g(x,y_actual);
denominator = integral(fun_x,a,b);
Iy(i) = f(y_actual)/denominator;
end
end
Best wishes
Torsten.