MATLAB: Gradient is zero yet exists

diff()gradientincorrect

Hello gradient (140,150), the answer is 0, but it exIhere is my error please? Also, is diff for calculating the derivative? GS.

Best Answer

Why would you expect
>> gradient(140,150)
ans = 0
to be non-zero? You are asking for the gradient at one point... to be honest I am surprised that it does not return NaN. Did you read the gradient documentation to know what the two arguments are for?
Perhaps you really wanted to do this:
>> gradient([140,150])
ans =
10 10
"Also, is diff for calculating the derivative?"
Did you read the diff documentation? It answers your question, right on the very first line.