Linprog optimisation with slack variable. How do I formulate the matices?
Show older comments
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.
Accepted Answer
More Answers (1)
Torsten
on 8 Jul 2015
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.
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!