MATLAB: Different result by hand-differentiaion vs MATLAB diff() function.

different result by hand-differentiaion vs matlab diff() function.

I differentiated the equation, ( K=(y^2 + 2*y + 2)/(y + 1)^2 ), by hand-differentiation and got result, ( -2/(y+1) ) while the result with MATLAB function, ( diff(K, y) ) was, (2*y + 2)/(y + 1)^2 – (2*(y^2 + 2*y + 2))/(y + 1)^3
I don't know why was it and what was the wrong I did.
Please help. Thank you.

Best Answer

Your "hand-differentiation" is not correct! The 'diff' answer is correct but can be simplified to an equivalent -2/(y+1)^3. (Perhaps the latter is what you meant to write?)