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

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.

 Accepted 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.)

1 Comment

Thank you so much! I guess I need to find another way to get around the 'max' function now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!