I am trying to find out 5 parameters of objective function having 2 equality constraints & 2 inequality constraints with optimization solver "fmincon".
objective function & constraints
I wrote 4 functions to define constraints & 1 function for nonlcon. They are as follows:
Constraint (equation 3):
function [C1] = s_1(w)
x = sym('x', [1 5]);
GC = (x(1)+x(2)/(j*w)^x(3)+x(4)*(j*w)^x(5))*(0.55/(62*j*w+1));
C1 = rad2deg(angle(GC))+100;
end
Constraint (equation 4):
function [C2] = s_2(w)
x = sym('x', [1 5]);
GC = (x(1)+x(2)/(j*w)^x(3)+x(4)*(j*w)^x(5))*(0.55/(62*j*w+1));
GC1 = angle(GC);
C2 = diff(GC1,w);
end
Constraint (equation 5):
function [T1] = s_4(w)
x = sym('x', [1 5]);
GC = (x(1)+x(2)/(j*w)^x(3)+x(4)*(j*w)^x(5))*(0.55/(62*j*w+1));
T = GC/(1+GC);
T1 = 20*log10(abs(T)) + 20;
end
Constraint (equation 6)
function [S1] = s_5(w)
x = sym('x', [1 5]);
GC = (x(1)+x(2)/(j*w)^x(3)+x(4)*(j*w)^x(5))*(0.55/(62*j*w+1));
S = 1/(1+GC);
S1 = 20*log10(abs(S)) + 20;
end
'nonlcon' function
function [ c,ceq ] = cons_mo(x)
ceq(1) =(s_1(1));
ceq(2) =(s_2(1));
c(1) = (s_4(10));
c(2) = (s_5(0.01)) ;
end
Script for optimization:
f=@(x)20*log10(abs((x(1)+x(2)/(j*1)^x(3)+x(4)*(j*1)^x(5))*(0.55/(62*j*1+1))));
x = fmincon(f,[0.5,0.5,0.5,0.5,0.5],[],[],[],[],[],[],[],cons_mo)
After execution, I am getting Invalid indexing assignment error along with other errors. Any help will be much appreciated.