MATLAB: Error: Undefined operator ‘+’ for input arguments of type ‘function_handle’

function_handleoperatorundefined

Here is my code;
function z = joy(t,z)
joymin = @(x) 150 - x;
joyadd = @(z) z;
z = integral2(@(x,y) normpdf(x,100,10).*normpdf(y,200,10),t,inf,joymin + joyadd,inf);
end
When I try to run joy(100,10), I get an error saying Undefined operator '+' for input arguments of type 'function_handle'.
The problem comes from joyadd because the code runs smoothly if I remove it.

Best Answer

You need to create a new anonymous function that adds the functions:
@(x)joymin(x) + joyadd(x)
so your full integral2 call becomes:
z = integral2(@(x,y) normpdf(x,100,10).*normpdf(y,200,10),t,inf,@(x)joymin(x) + joyadd(x),inf);
Your code will at least not throw that error.