Find minimum Sum while keeping variable fix

3 次查看(过去 30 天)
Hi guys,
I need a little help with my optimization problem.
I need to find the values of Parameters a and b, such that sum of squared residuals is minimized but while the average of the transformed vector is equal to a given value.
I try to run it with fmincon but this doesn't seem to work for the equality constraint.
function [SSE]=logit3(Par,x)
if nargin<5;
ir=0; %default ir=0
end;
if rows(Par)<cols(Par); % put parameters in column
Par=Par';
end;
if rows(Par)~=3; % check for the the right number of parameters as inputs
error('Dimension of Par not compatible');
end;
%% Assign the Parameters to the Elements in the Vector
a=Par(1);
b=Par(end-1);
meanpd=Par(end);
%%
T=rows(x);
y=zeros(T,1);
res=zeros(T,1);
for i=1:T
y(i)= (1/(1+exp(-(a+b*x(i)))));
res(i)=(y(i)-1).^2;
end
meanpd=mean(y);
SSE=sum(res);
end

回答(1 个)

Alan Weiss
Alan Weiss 2021-3-10
I don't see your equality constraint. If the equality constraint is a nonlinear constraint, you need to pass it in the fmincon nonlcon argument. If it is a linear constraint, pass it as Aeq-beq arguments.
If you need more info or I have misunderstood you, please show us your fmincon call as well as your objective function call.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 个评论
Andrea D'Amato
Andrea D'Amato 2021-3-10
Indeed I didn't put the constraint since I use this code as a fucntion to transform my variable x in a logit.
In my "main" code I used this code:
% x is variable
Par=[1;1;0.05];
Aeq=[0 0 1];
beq=0.05;
options=optimset('Display','iter','Algorithm','interior-point','TolFun',0.000001,'TolX',0.000000001,'MaxFunEvals',1000);
[theta]=fmincon('logit3',Par,[],[],Aeq,beq,[],[],[],options,x);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by