Your code will fail at the diff() if y is not symbolic, unless y happens to be 1.
If y is symbolic, then you need to use solve() with g instead of using fsolve() .
Remember to assign a value to g before calling the solving routine. See http://www.mathworks.com/matlabcentral/answers/281617-i-am-having-some-issues-calling-a-function-in-a-script-file#answer_219973