Multiple linear regression nonlinear constraints with fmincon
1 view (last 30 days)
Show older comments
Aurélien
on 28 May 2014
Commented: Aurélien
on 2 Jun 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 !
0 Comments
Accepted Answer
George Papazafeiropoulos
on 28 May 2014
Edited: George Papazafeiropoulos
on 28 May 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)
More Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!