Fmincg

It's a OCTAVE function. It can be helped to calculate the gradient decent.

Example:

options = optimset('GradObj','on','MaxIter',number_of_iterations);

theta = fmincg((@t)cost_function_name(t,X,y),initial_theta, options);

return [ J_value , grad ] and its first parametre should be theta

About debuging

(1)When our algorithm's outcome is not feeling right. We can print the size of the transistion matrix.