Linprog optimisation with slack variable. How do I formulate the matices?

6 ビュー (過去 30 日間)
Manie Conradie
Manie Conradie 2015 年 7 月 7 日
回答済み: Torsten 2015 年 7 月 8 日
I am trying to do a basic linear fitting optimisation, but am not getting the results that I am expecting. I have generated data for x and y - x=linspace(0,1,50) and y = 4x-1. And need to use a slack variable.
My optimisation problem then becomes
min(a,b,s) s subject to -s <= a*x(i)+b-y(i) <= s
The code I am using to try and get a = 4 and b= -1 is:
% a b s
f = [0 ;0 ;1];
A1 = [ J ones(N,1)];
A2 = [-J ones(N,1)];
A = [A1 ;A2];
b1 = y;
b2 = -y;
b = [b1 ;b2];
[a b s] = linprog(f,A,b);
J has been defined as [x ones(50,1)]
Can anybody help me please?
Thanks in advance.

採用された回答

Torsten
Torsten 2015 年 7 月 8 日
A1 = [x,ones(N,1),-ones(N,1)];
A2 = [-x,-ones(N,1),-ones(N,1)];
A = [A1;A2];
b = [y;-y];
f = [0;0;1];
linprog(f,A,b)
Best wishes
Torsten.
  4 件のコメント
Manie Conradie
Manie Conradie 2015 年 7 月 8 日
編集済み: Manie Conradie 2015 年 7 月 8 日
Managed to solve the problem. Although I cannot say what the problem was.
As you mentioned it is indeed the L-inf norm. But what boggles me, is where is the square of the error calculated in this implementation?
I am also doing one for the L-1 norm, and again I don't see where I should implement the absolute value part of the definition. Or is this the -s<f<s part of it?
Could you perhaps explain this to me please?
Thanks very much.
Manie
Manie Conradie
Manie Conradie 2015 年 7 月 8 日
Sorry, mixing up the L-2 norm and the L-inf norm.

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

その他の回答 (1 件)

Torsten
Torsten 2015 年 7 月 8 日
l_1-norm:
The problem can be formulated as
min: sum_i s_i
|a*x(i)+b-y(i)| <= s_i
or equivalently
min: sum_i s_i
-s_i <= a*x(i)+b-y(i) <= s_i
l_infinity norm:
The problem can be formulated as
min: s
|a*x(i)+b-y(i)| <= s
or equivalently
min: s
-s <= a*x(i)+b-y(i) <= s
Best wishes
Torsten.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by