Given a set of trial input parameters in a vector, use the known x values to project y values. Subtract the known y values in each case, and square those individually, and sum() the vector. The result will be a sum-of-squared-errors scalar for those input parameters. You want to minimize that: if there were a perfect fit, the residue would be 0. (The residue cannot be negative as you are adding values that are strictlly non-negative).
You can construct a function handle that given the trial parameters, calculates the residue scalar.
Now pass the function handle to your Nelder-Mead function for it to minimize.
function [c,ceq] = mycon(x, y,mu, psi,sig20, Vgam,gam0, lam0,Vlam )
c= exp(x(2))+exp(x(3))-0.99;
ceq=[];
end
Even if the extra known variables aren't actually used in the computations of the constraints, they have to be there if you use additional arguments to fmincon to pass them in.
Incidentally, passing extra known parameters this way is antiquated. You should use anonymous or nested functions as describedhere. If you use these alternatives, you will not have to have to pass variables to functions that don't need them.
I believe that if you get this message, then you have made an error. You gave a start point that is infeasible with respect to the bounds, and this is a mistake. fmincon does the best it can to try to continue despite the error. If I got that message, I would examine my code carefully and eliminate the cause of the error, rather than trying to figure out exactly how fmincon works around my error.
Best Answer