## how to set Fmincon function tolerance?

### Maryamm Bodaghi (view profile)

on 16 Aug 2014
Latest activity Commented on by Matt J

on 17 Aug 2014

### Matt J (view profile)

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];
cc0=rand(1,24);
cc0=cc0/sum(cc0);
[cc,fval]=fmincon(objfcn,cc0,[],[],A,b,zeros(1,24),ones(1,24),options);
```

on 16 Aug 2014
Edited by Matt J

### Matt J (view profile)

on 16 Aug 2014

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 [].

on 16 Aug 2014
Edited by Matt J

### Matt J (view profile)

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,

`    F(cc)=min(F)+(0.5)^k`

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) ,...)`

Show 1 older comment
Matt J

### Matt J (view profile)

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

### Maryamm Bodaghi (view profile)

on 17 Aug 2014

thanks Dear Matt;

```   it=1;  mm=1;
p=1e-9;   delta=0.5;   eta=10^(-6);```
```    c=sdpvar(1,24)
const=[0<=c<=1,sum(c)==1];```
```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
ex(ii,t)=1*(cc(t)*((log(1-(1./(Uu(1,t,mm)+Cc(1,t,mm)))))+(log(1-(1./(Uu(2,t,mm)+Cc(2,t,mm)))))+...
(log(1-(1./(Uu(2,t,mm)+Cc(2,t,mm)))))));
end
end
expp=p*ex;
eexp=exp(-1*expp);
F_m_p_cmp=(1/p)*log10(sum(sum(eexp)));
fmp_cmp=F_m_p_c+(0.5)^it-F_m_p_cmp
end
```
```    for ii=1:mm
for t=1:24
ex(ii,t)=-1*(c(t)*((log(1-(1./(Uu(1,t,mm)+Cc(1,t,mm)))))+(log(1-(1./(Uu(2,t,mm)+Cc(2,t,mm)))))+...
(log(1-(1./(Uu(2,t,mm)+Cc(2,t,mm)))))));
end
end
expp=p*ex;
eexp=exp(expp);
F_m_p_c=(1/p)*log(sum(sum(eexp)));```
`    solvesdp(const,-F_m_p_c)`
```    double(F_m_p_c)
c=double(c)
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

### Matt J (view profile)

on 17 Aug 2014

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

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