MATLAB: How to evaluate triple integral of function of four variables, with a variable integration limit

MATLABnumerical integration

I am trying to evaluate a triple integral of a function with respect to 3 of its 4 variables. Something like:
However, I get the error "Too many input arguments." That the limits of one integration are variable appears to be the issue (changing these limits to constants, I no longer get the error message). I have looked through examples in MATLAB Answers that were similar to my case, but can't seem to spot where I am going wrong here. Any help would be greatly appreciated! And, my thanks in advance for your time 🙂
*In the below example code I am using a simple function because my actual function is awkwardly long. I realize for this example the integrals are separable but this is not the case for my actual function.
f = @(r,g,x,y) r + g + x + y;
y_min = @(x) -(x.^0.5);
y_max = @(x) x.^0.5;
x_min = 0;
x_max = 1;
g_min = 0;
g_max = pi;
Q = @(r) integral3( @(g,x,y) f(r,g,x,y), g_min, g_max, x_min, x_max, y_min, y_max)
Q(0.4) %just for example, gives the error

Best Answer

Each min/max function is a function of all previous variables. So x is not permitted a function, ymin/max are a function of x, and zmin/max are a function of x and y.
Related Question