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 !
0 件のコメント
採用された回答
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 Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!