I’m not convinced either:
![](/matlabcentral/answers/uploaded_files/30275/Mismatch%20between%20'formula'%20and%20graphed%20'surface'%20-%202015%2005%2003.png)
The problem is here:
ModY = @(y) [20*(y<20) + 80*(y>80) + y.*((y>=20)&(y<=80))]; ^ NEED ARRAY MULTIPLICATION HERE
You need to do array multiplication of ‘y’ and the logical array created by the ‘((y>=20)&(y<=80))’ inequality. (I recognised this because I’ve seen something like this code quite recently!)
With that, it works:
![](/matlabcentral/answers/uploaded_files/30277/Mismatch%20between%20'formula'%20and%20graphed%20'surface'%20(2)%20-%202015%2005%2003.png)
The reason it produced one value with the scalars and another with the matrices was due to the omitted element-wise array operator multiplication (.*).