However, fminsearch(), fgoalattain(), fmincon(). fminunc(), fseminf(), lsqcurvefit(), lsqnonlin(), fsolve() and fzero() donot accept expressing the function in terms of matrices.
You have rand() in your code. Of course you are going to get different answers each time you run it.
The work-around is to re-seed the random number generator to a constant value before running the code. The easiest method of reseeding the random number generator depends upon your MATLAB version.
Best Answer