Multiple linear regression nonlinear constraints with fmincon

조회 수: 1 (최근 30일)
Aurélien
Aurélien 2014년 5월 28일
댓글: Aurélien 2014년 6월 2일
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 !

채택된 답변

George Papazafeiropoulos
George Papazafeiropoulos 2014년 5월 28일
편집: George Papazafeiropoulos 2014년 5월 28일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by