Minimizing a function
Minimizing a function
(OP)
Hello,
If I have a function called Myfunc, and I want to minimize it.
I am trying: [X fval] = fminsearch(@Myfunc, X0)
It minimizes the result, but everytime I run it again it gives me a lower value. So im not reaching the local minimum.
I tried [X fval] = fminunc(@Myfunc, X0), but the problem is X has to be positive.
Finally I tried [X fval] = fmincon(@Myfunc, X0, [], [], [], [], LB, UB)
I set lower bound to 0 and upper bound to the desired value, but I still get errors that X is either negative or 0.
Where am I going wrong ? And is this the best way to minimize my function, or is there a better method ?
Thank you.
If I have a function called Myfunc, and I want to minimize it.
I am trying: [X fval] = fminsearch(@Myfunc, X0)
It minimizes the result, but everytime I run it again it gives me a lower value. So im not reaching the local minimum.
I tried [X fval] = fminunc(@Myfunc, X0), but the problem is X has to be positive.
Finally I tried [X fval] = fmincon(@Myfunc, X0, [], [], [], [], LB, UB)
I set lower bound to 0 and upper bound to the desired value, but I still get errors that X is either negative or 0.
Where am I going wrong ? And is this the best way to minimize my function, or is there a better method ?
Thank you.