what changes i need to make for better answer (fmincon)
Show older comments
>> x0=[10;10;10;0.5;0.5];
>> options=optimset('Algorithm','interior-point');
>> [x,fval]=fmincon(@newfrac,x0,[],[],[],[],[0;0;0;0;0],[inf;inf;inf;0.9;0.9],@confun,options)
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
0.0000
0.7587
0.1891
0.7928
0.9000
fval =
-22.0702
i need to reduce my function value to zero.request u tell some changes in the commands i used.
[Information merged from duplicate question]
MAIN FUNCTION
function [f] = newfrac(x)
wcg=2.1; %gain cross over frequency
bb=4;
cc=60;
r = x(1) + (x(2)*(wcg^(-x(4)))*cos(90*x(4)*(pi/180)))+ (x(3)*(wcg^(x(5)))*cos(90*x(5)*(pi/180)));
s = - x(2)*wcg^(-x(4))*sin(90*x(4)*pi/180)+ x(3)*wcg^(x(5))*sin(90*x(5)*pi/180);
fun1=bb/sqrt((cc*wcg)^2 +1);
fun2=sqrt((r)^2 + (s)^2);
f = 10*log10(fun1*fun2);
end
CONSTRAINTS PROGRAM-TO BE SATISFIED BY ABOVE FUNCTION
function [c, ceq] = confun(x)
wcg=2.1;
wt=10;
ws=0.01;
aa=2;
bb=4;
cc=60;
dd=80;
ff=0;
fipm=80; %phase margin
r = x(1) + ( x(2)*(wcg^(-x(4)))*cos(90*x(4)*(pi/180)) )+(x(3)*(wcg^(x(5)))*cos(90*x(5)*(pi/180)));
% pi/180 give degree value in radians
s = - x(2)*(wcg^(-x(4)))*sin(90*x(4)*(pi/180))+ x(3)*(wcg^(x(5)))*sin(90*x(5)*(pi/180));
ru = -x(2)*x(4)*(wcg^(-x(4)-1))*cos(90*x(4)*(pi/180))+ x(3)*x(5)*(wcg^(x(5)-1))*cos(90*x(5)*(pi/180));
su = -x(2)*x(4)*(wcg^(-x(4)-1))*sin(90*x(4)*(pi/180))+ x(3)*x(5)*(wcg^(x(5)-1))*sin(90*x(5)*(pi/180));
rt = x(1) + x(2)*(wt^((-x(4))))*cos(90*x(4)*(pi/180))+ x(3)*(wt^x(5))*cos(90*x(5)*(pi/180));
st = -x(2)*(wt^(-x(4)))*sin(90*x(4)*(pi/180))+x(3)*(wt^x(5))*sin(90*x(5)*(pi/180));
rs = x(1) + x(2)*(ws^(-x(4)))*cos(90*x(4)*(pi/180))+ x(3)*(ws^x(5))*cos(90*x(5)*(pi/180));
ss = -x(2)*(ws^(-x(4)))*sin(90*x(4)*(pi/180))+ x(3)*(ws^x(5))*sin(90*x(5)*(pi/180));
%1 equation(41)
c1 = (atan(s/r)*180/pi)-(atan(dd*wcg)*180/pi)-(wcg*ff)+180-fipm;
% 180/pi give radian value in degrees
%2 equation(42)
c21 = 1/(1+(s/r)^2);
c22 = (su*r-s*ru)/(r)^2;
c23 = dd/(1+(dd*wcg)^2);
ceq = [c1;c21*c22-c23-ff];
%3 equation(43)
c31 = aa*sqrt((rt^2) + (st^2));
c32 = sqrt((1+aa*rt)^2 + (dd*wt+aa*st)^2);
c3 = (10*log10(c31/c32))+20;
%4 equation(44)
c41 = sqrt((cc*ws)^2 +1);
c42 = sqrt((1+bb*rs)^2+(cc*ws+bb*ss)^2);
c4 = (10*log10(c41/c42))+20;
c=[c3;c4];
end
SIR THESE TWO ARE PROGRAMS I HAVE WRITTEN IN MATLAB,THE COMMANDS I USED ARE
>> f_obj=@(x)newfrac(x)^2;
>> x0=[10;10;10;0.5;0.5];
>> options=optimset('Algorithm','interior-point');
>> [x,fval]=fmincon(f_obj,x0,[],[],[],[],[0;0;0;0;0],[inf;inf;inf;0.9;0.9],@confun,options)
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
1.2403
3.0557
0.4837
0.4822
0.9000
fval =
104.6186
>> [x,fval]=fmincon(@newfrac,x0,[],[],[],[],[0;0;0;0;0],[inf;inf;inf;0.9;0.9],@confun,options)
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
0.0000
0.7587
0.1891
0.7928
0.9000
fval =
-22.0702
Answers (2)
Sargondjani
on 17 May 2012
0 votes
-22 is better than 0, so the solution fmincon found is better than what you want... why would you want 0 if the optimum (lowest possible value) is -22???
if you dont want the minimum but find the zero of the funciton, than you should use 'fsolve'
16 Comments
kintali narendra
on 17 May 2012
Sargondjani
on 17 May 2012
you should first figure out what you want.... but youa re right that fsolve can not handle the constraints...
if you are looking for the x values such that the funciton value is 0, then you should make the objective: value^2 (not abs(value), because that is not differentiable)
kintali narendra
on 17 May 2012
Sargondjani
on 17 May 2012
i understand that you want to find the zero of a function. this is the same as trying to minimize y^2... because the optimal value is then y=0. the objective abs(y) would also have as the optimal solution y=0, BUT this objective is not differentiable at y=0. Fmincon assumes that the objective is differentiable, that's why your objective should be y^2
kintali narendra
on 18 May 2012
Sargondjani
on 18 May 2012
is your objective to set f=0?? then you should have f^2 as your objective in fmincon, because f=0 is the best possible solution...
if f=0 is your objective then you should do something like:
f_obj=@(x)newfrac(x)^2; %this should return f^2 as (first) output.
fmincon(f_obj,x0,......)
do you understand where i am going??
kintali narendra
on 18 May 2012
kintali narendra
on 18 May 2012
Sargondjani
on 18 May 2012
are your starting values close to the optimal where f=0 that the other research found??
it's hard for me to check but there could be a mistake a program... how certain are you that there is no mistake? did you check intermediate results??
kintali narendra
on 18 May 2012
kintali narendra
on 18 May 2012
kintali narendra
on 18 May 2012
Sargondjani
on 18 May 2012
yeah, lets hope some other ppl come to the rescue...
but my advice would also be to look a bit more in to the theory behind things, because i dont think you know what you are optimizing for... you just say: the other research found f=0, but you should KNOW if you want to find the minimum of 'f' or f=0
Sean de Wolski
on 18 May 2012
And if you aren't giving it a good initial guess it will find the first local minimum it encounters. What do you have for confun? Have you updated this to change for Sargondjani's comments?
If you can't make a good guess on an initial value and want a global minimum GA() might be a better approach.
kintali narendra
on 19 May 2012
Sargondjani
on 19 May 2012
this doesnt mean anything to me... all i know is that matlab seems to do the optimization properly, so first you need to find out what you want the optimizer to do, and maybe change the initial guess.
and do you know if the problem is well-behaved?? if it is not, you should try loads of initial guess...
Hello sir, I obtained what I assume to be the correct result for your program:
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
0.3348
2.5203
0.5623
0.5791
0.8251
fval =
1.5559e-013
I obtained this result my manipulating the logarithm function in you objective function. You can now write it as follows:
function [f] = newfrac(x)
wcg=2.1; %gain cross over frequency
bb=4;
cc=60;
r = x(1) + (x(2)*(wcg^(-x(4)))*cos(90*x(4)*(pi/180)))+ (x(3)*(wcg^(x(5)))*cos(90*x(5)*(pi/180)));
s = - x(2)*wcg^(-x(4))*sin(90*x(4)*pi/180)+ x(3)*wcg^(x(5))*sin(90*x(5)*pi/180);
fun1=bb/sqrt((cc*wcg)^2 +1);
fun2=sqrt((r)^2 + (s)^2);
fun_x=fun1*fun2;
origf=10*log10(fun_x);
f= 10^origf;
end
PROOF: ****************************************************************
===> For purposes of our discussion, Let:
x = fun_x = fun1*fun2
b = 10 (our base of the log)
k = 10 (the constant)
y= origf (the original expression for the objective function)
===> Therefore, the original function f that you had can be written as
y=k*logb(x) (EQ1)
===> By the properties of logarithmic functions, then
y= b^[klogb(x)]=x (EQ2)
===> Meanwhile, the following theorem must hold true
y=k*logb(x) if and only if b^y=x EQ(3)
===> Using EQs (1-3) and substitution, one can see--
y=k*logb(x)=b^[klogb(x)]
===> Or, in other words,
y=origf=10*log10(fun_x) EQ(4)
iff y=10^[10*log10(fun_x)=f (EQ5)
===> and so, we note EQ(4) is equivalent to EQ(5), but EQ(4) is ill-conditioned in comparison to EQ(5). ***************************************************** In conclusion, the only issue I think you need to correct is to rewrite your objective function in the form of EQ(5)
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!