i want my fun value to be zero and also should satisfy the constraints,i uesd fmincon command

2 views (last 30 days)
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.
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.
x =
0.0000
0.7587
0.1891
0.7928
0.9000
fval =
-22.0702

Answers (2)

Matt Kindig
Matt Kindig on 18 May 2012
Perhaps your optimization is getting stuck in a local minimum. Try a different set of initial guesses (x0)-- does this help?
Also, in your second optimization (the one with just @newfrac) there is nothing forcing the optimizer to stop once fval=0. You can try to use the absolute value instead, i.e.
f _obj = @(x) abs(x)
[x,fval]=fmincon(f_obj,x0,[],[],[],[],[0;0;0;0;0],[inf;inf;inf;0.9;0.9],@confun,options)
  2 Comments
kintali narendra
kintali narendra on 18 May 2012
sir,i already used ^2,i have posted results also..............
sir ,in the above question i wrote my whole program and the output i am getting ,please do suggest some changes so that i can get better output

Sign in to comment.


Elizabeth
Elizabeth on 30 Jul 2012
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, if you agree with my adjustments:
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). ****************************************************************************8
  • 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 Get Started with Optimization Toolbox 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!