please tell me right command(fmincon) to get output for this problem

THIS IS THE MAIN FUNCTION
function [f] = myfun(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
ANOTHER PROGRAM FOR CONSTRAINTS
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
PLEASE TELL ME THE RIGHT COMMAND TO BE WRITTEN IN COMMAND WINDOW,THE COMMAND I HAVE GIVEN IS UNABLE TO FIND THE RIGHT SOLUTION
>> x0=[6.7441;27.7461;0.0063;0.1461;0.7874];
>> options=optimset('Algorithm','active-set');
>> [x,fval,exitflag,output,lambda,grad,hessian]=fmincon(@myfun,x0,[],[],[],[],[],[],@confun,options)
BY GOING THROUGH DIFFERENT EXAMPLES IN MATLAB HELP ,I GAVE THESE COMMAND BUT I AM UNABLE TO GETHT SOLUTION ............PLEASE HELP.

9 Comments

i think you have to leave out the @, so just;
fmincon(myfun,x0,[],[],[],[],[],[],confun,options)
(that's what i always do)
but pls provide the error message if this doesnt work...
SIR AS U MENTIONED I REMOVED @-SYMBOL THE ERROR MESSAGE IS AS FOLLOWS
>> x0=[6.7441;27.7461;0.0063;0.1461;0.7874];
>> options=optimset('Algorithm','interior-point');
>> [x,fval,exitflag]=fmincon(newfrac,x0,[],[],[],[],[],[],confun,options)
??? Input argument "x" is undefined.
Error in ==> newfrac at 5
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)));
SIR WHEN I KEPT @-SYMBOL
>> x0=[6.7441;27.7461;0.0063;0.1461;0.7874];
>> options=optimset('Algorithm','interior-point');
>> [x,fval,exitflag]=fmincon(@newfrac,x0,[],[],[],[],[],[],@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 =
-40.0427
57.8994
0.3050
0.0375
1.6646
fval =
-3.0751
exitflag =
1
so, your problem is solved, right?
no sir it is not solved,all values should be positive.
in the above programming i have used the values of a solved example.
and according to the example the right answer is 6.7441,27.7461,0.0063,0.1460,0.7874(i have given these values as input for simplicity ) last two values should be less than 1
so you should add them as constraints:
lb=[0,0,0,0,0];
and if you want to have higher bound on the last two: hb=[inf,inf,inf,1,1];
THANK YOU SIR.......
sir a small doubt,my function value should be near to 'zero' but it is not,if i give the above mentioned values(6.7441,27.7461,0.0063,.....)i am getting a better value than the output shown from my program......what to do for it.
you mean the objective function has a better value at your initial guess than the final result???
the only logical explanation seems to be that the initial guess does not satisfy the constraints... You should check this. If it doesnt, than there is probably a typo in your constraints (easily possible witht his long code)
If you are certain this is not the case (which would surprise me), than maybe you can show the exit message, and the function/objective value at the initial guess? That would probably be helpfull in finding the problem....
[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
sir i need to reduce the value of function zero,please tell some more changes.

Sign in to comment.

Answers (0)

Asked:

on 11 May 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!