フィルターのクリア

LINPROG requires the following inputs to be of data type double: 'f'.

9 ビュー (過去 30 日間)
Az.Sa
Az.Sa 2023 年 2 月 9 日
コメント済み: Az.Sa 2023 年 2 月 10 日
I am trying to run an LP optimization.
My objective function is to estimate that minimize
where,
,
;
please note , in the code my reg1 , ...etc
I wrote the following code :
y= readtable('y.crra.csv'); % 249 x 1
y=table2array(y);
reg1=readtable('fitted.reg1.csv');
reg1=table2array(reg1);
trareg1=reg1.'; % 1 x 249
reg2=readtable('u.fitted.reg2.csv');
reg2=table2array(reg2);
trareg2=reg2.'; % 1 x 249
reg3=readtable('u.fitted.reg3.csv');
reg3=table2array(reg3);
trareg3=reg3.'; % 1 x 249
reg4=readtable('u.fitted.reg4.csv');
reg4=table2array(reg4);
trareg4=reg4.'; % 1 x 249
tau=.05;
yp= @(x) x*trareg1 + x*trareg2+x*trareg3 + x* trareg4;
e= @ (x) y-yp;
loss= @ (x) max(tau*(e), ( tau-1 )*(e));
obj = @(x) sum(loss);
Aeq = [1, 1, 1, 1];
lb = [0, 0, 0, 0];
beq = [1];
x = linprog(obj, [], [], Aeq, beq, lb, []);
I received the following error :LINPROG requires the following inputs to be of data type double: 'f'.
do you have any idea how to solve it?
I searched about the error and I've seen other people mentioning this error but I don't get how could work in my case
Thanks in advance.

採用された回答

Torsten
Torsten 2023 年 2 月 9 日
編集済み: Torsten 2023 年 2 月 9 日
y= readtable('y.crra.csv'); % 249 x 1
y=table2array(y);
reg1=readtable('fitted.reg1.csv');
reg1=table2array(reg1);
trareg1=reg1.'; % 1 x 249
reg2=readtable('u.fitted.reg2.csv');
reg2=table2array(reg2);
trareg2=reg2.'; % 1 x 249
reg3=readtable('u.fitted.reg3.csv');
reg3=table2array(reg3);
trareg3=reg3.'; % 1 x 249
reg4=readtable('u.fitted.reg4.csv');
reg4=table2array(reg4);
trareg4=reg4.'; % 1 x 249
tau=.05;
loss = @(x) (x(1)*trareg1 + x(2)*trareg2+x(3)*trareg3 + x(4)* trareg4).' - y;
obj = @(x) sum(max([tau*loss(x),(1-tau)*loss(x)],[],2));
Aeq = [1 1 1 1];
beq = 1;
lb = [0 0 0 0];
ub = [1 1 1 1];
sol = fmincon(obj,0.25*ones(4,1),[],[],Aeq,beq,lb,ub)
  7 件のコメント
Torsten
Torsten 2023 年 2 月 10 日
Did you correct the error before you ran the code ?
Az.Sa
Az.Sa 2023 年 2 月 10 日
Great !! Thank you very much for your help !!

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2023 年 2 月 9 日
Apparently some or all of the arguments to LINPROG were not doubles. Which ones?
In your code, we see this:
yp= @(x) x*trareg1 + x*trareg2+x*trareg3 + x* trareg4;
e= @ (x) y-yp;
loss= @ (x) max(tau*(e), ( tau-1 )*(e));
obj = @(x) sum(loss);
So, is obj a double precision vector of numbers? (NO.) In fact, obj will return a SCALAR function of the argument vector.
obj is a function handle. While obj will return a number, if is NOT a vector of numbers. In fact, it is a NONLINEAR function of the argument, x. This is because of the max function inside the loss part of your objective.
Does LINPROG handle nonlinear objectives? (NO.)
Therefore, you cannot use LINPROG.
You may be able to use other tools like GA. But not FMINCON, because the max function inside the objective makes it not differentiable. And certainly not linprog.
  4 件のコメント
Az.Sa
Az.Sa 2023 年 2 月 9 日
編集済み: Az.Sa 2023 年 2 月 9 日
can you please help with GA function code I have tried to edit my code based on that but it gives me error evry time
John D'Errico
John D'Errico 2023 年 2 月 10 日
Are you saying you want to solve the problem using GA? You would need to show the code you tried. But Torsten has already shown how to solve it using fmincon.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by