Find minimum Sum while keeping variable fix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Alan Weiss
le 10 Mar 2021
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 commentaire
Voir également
Catégories
En savoir plus sur Nonlinear Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!