Multiple linear regression nonlinear constraints with fmincon

1 vue (au cours des 30 derniers jours)
Aurélien
Aurélien le 28 Mai 2014
Commenté : Aurélien le 2 Juin 2014
Hi,
I need some help to implement a code. I need to run a multiple linear regression for 4 variables (x1, x2, x3, x4) : y = a x1 + b x2 + c x3 + d x4 with the following constraint a/c = b/d. I am not a mathematician and i don't understand how to implement it with the fmincon function.
Thanks for your help !

Réponse acceptée

George Papazafeiropoulos
George Papazafeiropoulos le 28 Mai 2014
Modifié(e) : George Papazafeiropoulos le 28 Mai 2014
As an example for doing this, I give you an example. Define a function as follows:
function er = objfun(a)
global y x
z=a;
z(4)=z(2)*z(3)/z(1);
er=sum((y-x*z).^2);
end
then type in the command window the following:
global y x
% input data:
% y=sort(rand(5,1));
% x1=sort(rand(5,1));
% x2=sort(10*rand(5,1));
% x3=sort(100*rand(5,1));
% x4=sort(1000*rand(5,1));
% ainit=[0.5;0.8;0.1];
x=[x1 x2 x3 x4];
fmincon(@objfun,ainit,ones(1,3),Inf)
  1 commentaire
Aurélien
Aurélien le 2 Juin 2014
Thanks a lot. This is exactly what i was looking for.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Linear and Nonlinear Regression 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!

Translated by