Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

how to set Fmincon function tolerance?

Asked by Maryamm Bodaghi on 16 Aug 2014
Latest activity Commented on by Matt J on 17 Aug 2014

excuse me, how can set a tolerance? because I want to solve this:( I mean finding "cc" which satisfies below)

* F(cc)<=min(F(c))+(0.5)^k * 

and k k is iteration number. in paper, writer said that tolerance should be set on "(0.5)^k". I've written a az below,but it doesn't work.

objfcn = @(cc) fmp_cmp(cc, Uu, Cc, mm, p);
options = optimset('TolFun', delta^k);
A = [ones(1,24)];
b =[1];


Maryamm Bodaghi


No products are associated with this question.

3 Answers

Answer by Matt J on 16 Aug 2014
Edited by Matt J on 16 Aug 2014
Accepted answer

Your 'options' should be the 10th input argument to fmincon. You have passed it as the 9th. If you have no nonlinear constraints, set that to [].


Matt J
Answer by Star Strider on 16 Aug 2014

Where did ‘F’ come from? It’s not in AA.m or fmp_cmp.m. It’s obviously a function, because ‘cc’ is a (1x24) double vector. Also, ‘c’ is new. Should it be ‘cc’? If they are different, how are ‘cc’ and ‘c’ related?

The fmincon function can do that (I’ve not done it myself), but we need to know what your F function is and what you want to do with it (please describe) so we can be sure we can write the constraint function correctly.


Star Strider on 16 Aug 2014

My pleasure!

NOTE I just discovered what I consider to be a typographical error in the paper. In the paragraph that follows Equation (14), a sentence defines l (lower-case ‘L’) and u as being ‘the lower and upper bounds formed by concatenating all the lower and upper bounds in (12).’ The definition of Ch(yh) then refers to the transpose of 1 (bolded number 1) that seems to be in error, because 1 is an alternative representation of the identity matrix ((eye) matrix in MATLAB), and it doesn’t make sense to transpose it. If it is instead a vector of lower bounds, it does make sense to transpose it. Consider that when you write your code. If I’m correct, this is a significant error. It appears that 1 (bolded number 1) should be l (bolded lower-case L) wherever it appears.

Equation (29) includes Equation (30). The yh vector is a parameter vector (defined in III A.), and they ambiguously define ‘p’ as ‘some regularization constant’ (just after Equation (30)), although they later calculate it in Step (6) and Equation (33). Equation (29) is actually a double summation, since it includes Equation (30). Step (4) updates the estimates for parameter vector y. It seems to me that Equation (29) calculates F[m,p] (for lack of markup ability here) from the updated y, so you would implicitly need to calculate it at the start of the first ‘if’ block (which likely translates to a while block in MATLAB) and continue calculating it with updated y values until the relevant conditions are met. It seems that you optimise for y there.

So in Algorithm 2 it seems to me that you optimise for c initially with an initial guess for y, optimise for y in the first ‘if’ (actually while) block (with fixed c), satisfy the second ‘if’ (actually while) block, then go back and start from Step (1) to optimise for c (with fixed y) ... etc., until the criteria in the ‘until’ condition at the end are satisfied. Call Algorithm 1 essentially as a function (subroutine) as necessary in Algorithm 2.

This is my impression on a relatively rapid scan of the article. I cannot claim that my outline of it is correct, so discuss this with others closer to the problem to be sure.

Maryamm Bodaghi on 17 Aug 2014

Dear Star, that's kind of you spending time on reading paper. thank you so much.

Star Strider on 17 Aug 2014

My pleasure!

Star Strider
Answer by Matt J on 16 Aug 2014
Edited by Matt J on 16 Aug 2014

There may be a typo in your post. The additive constant (0.5)^k doesn't affect the solution in any way. cc=argmin(F) is a solution for all k. Perhaps you really meant to write an equality,


If so, the first step is to minimize F() as I think you have done in other posts. If Fmin is this minimum, then the above reduces to

    Fmin+(0.5)^k -F(cc)=0

You could indeed use fminsearch to solve this nonlinear equality

   cc=fminsearch(@(cc) abs(Fmin+(0.5)^k -F(cc)) ,...)

However, it would be more direct to use fzero

    cc = fzero(@(cc) Fmin+(0.5)^k -F(cc) ,...)


Matt J on 16 Aug 2014

realy I don't have Fmin, because I'm trying to get it,

But why can't you find Fmin with fmincon? And what effect is 0.5^k supposed to have? It just adds a constant to F(c) without changing the location of its minima.

Maryamm Bodaghi on 17 Aug 2014

thanks Dear Matt;

I'me trying to do your advice, but it doesn't accepr vector.

   it=1;  mm=1;  
    p=1e-9;   delta=0.5;   eta=10^(-6);
function F_m_p_cmp=fmp_cmp(F_m_p_c,it,cc, Uu, Cc, mm, p)
for ii=1:mm
    for t=1:24
    for ii=1:mm
        for t=1:24
    objfcn = @(cc) fmp_cmp(F_m_p_c,it,cc, Uu, Cc, mm, p)
    cc = fzero(objfcn,[0 1])

cc should be a 1x24 vector

Matt J on 17 Aug 2014

I'me trying to do your advice

Not really sure what "my advice" was. I don't think you've finished explaining what the goal is.

Matt J

Contact us