Multiple linear regression nonlinear constraints with fmincon

1 次查看(过去 30 天)
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
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