MATLAB: How to Double-integrate a Function with Three Variables Using quad2d

double integralintegral2quad2dsimplify

I have a question regarding double integration in MATLAB. I have three variables x, y, and z in the function I want to integrate, but want to integrate on x and y only. I am expecting the resulting equation to be a function of z, which may be more like a simplify function.
>> fun =@(x,y,z) 1/4.*max(x-(1+z)*y, 0); >> integral_fun = quad2d(fun,0,2,0,2) ??? Input argument "z" is undefined.
Error in ==> @(x,y,z)1/4.*max(x-(1+z)*y,0)
Error in ==> quad2d>tensor at 355 Z = FUN(X,Y); NFE = NFE + 1;
Error in ==> quad2d at 169 [Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Please help me out. Thank you.

Best Answer

You cannot use a numerical integration function like 'quad2d' to produce results which contain unspecified variables. That is the role played by the 'int' function of the Symbolic Toolbox. However, it should be understood that with 'int' you are not always assured of obtaining an answer; there are no known explicit answers to a great many integration problems. In the particular case you describe you would well have trouble with 'int' due to presence of the 'max' function. (My own version failed on it miserably, as I anticipated.)