linear program with multiple vector norms in one function

4 views (last 30 days)
n the previous few modules you studied the problem of minimizing ∥Ax−b∥2 by choice of x. So far you've done this in Matlab using either the backslash operator or the command pinv. Now that you've been exposed to linear programming, you have the tools to solve two variations on this problem, namely minimizing 1. ∥Ax−b∥1 2. ∥Ax−b∥∞ Recall that the 1-norm of a vector v with components (v1,…,vN) is defined to be
∥v∥1=∑i=1N|vi|,
and the 1-norm of the same vector is defined to be
∥v∥∞=maxi|vi|
and minimization of either of these norms can be represented as a linear program. We have provided partial code for the function
x = regressionNorms(A,b,nFlag)
with inputs
1. A: the evaluated ''basis" matrix in the regression problem 2. b: the ''measurements" in the regression problem 3. nFlag: a number that is either 1, 2, or Inf, specifying which norm p to use when minimizing ∥Ax−b∥p
and output 1. x: minimizer of ∥Ax−b∥p
In particular, we have provided partial-code to set up and solve the case where p=1 by transforming it into a linear program in standard form. You will complete the function using the backslash operator to solve the case where p=2, and using the tools you learned in this module to solve the case where p=∞ by transforming it into a linear program in standard form. For this latter case (p=∞), your code will include a call to lpsolver.
This is the function given to us to modify
function x = regressionNorms(A,b,nFlag)
% You can assume that b is a column vector (no need to do error-checking) and
% that A and b have the same number of rows. In principle, you would normally
% check those (and other conditions) and use ERROR if any necessary conditions
% are not met.
%
switch nFlag
% finish code to solve the 1-norm problem
case 1
nr = size(A,1); nc = size(A,2);
c = [zeros(nc,1); ones(nr,1) ];
Aineq = [
bineq = [
[xT,~,~,~] = lpsolver(c,Aineq,bineq);
x = xT(1:nc);
% solves the least-squares problem
case 2
% Insert code here
% solves the infinity-norm problem
case Inf
% Insert code here
otherwise
error('Unrecognized norm')
end
I just tried to make Aineq and bineq of the right size. But this problem is so vague that I don't really understand what to do with it. lpsolver is a script that was given to us that will solve the linear program with the inputs A, b, and c (c is the vector that we are trying to either maximize or minimize), and A and b are components of the inequality Ax≤b
Since the infinity norm is the largest norn in the vector, which vector would it be in this case? Is that the c vector or the b vector?
I'm only attempting case 1 as of right now, once I got that I will try case 2
% finish code to solve the 1-norm problem
case 1
nr = size(A,1); nc = size(A,2);
c = [zeros(nc,1); ones(nr,1) ];
Aineq = [zeros(nr,nr+nc)]
bineq = [zeros(nr,1)]
[xT,~,~,~] = lpsolver(c,Aineq,bineq);
x = xT(1:nc);

Answers (0)

Categories

Find more on Descriptive Statistics 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!