I am trying to evaluate and find the minimum and maximum values of a function over a certain interval. I also want it to evaluate the endpoints to see if they are the maximum or the minimum values. I have the following code which is not giving me what I want. The minimum values should be -1 and 2 but I am getting -0.9999 and 1.9999. Any help would be much appreciated.
minVal1 = fminbnd(f,-1,0);
minVal2 = fminbnd(f,0,2);