Quickguide LLS Problem

From TomWiki
Revision as of 06:50, 17 January 2012 by Elias (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Notice.png

This page is part of the Quickguide Manual. See Quickguide.

The linear least squares (lls) problem is defined as


Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \begin{array}{ll} \min\limits_{x} & f(x) = \frac{1}{2} || C x - d || \\ & \\ s/t & \begin{array}{lcccl} x_{L} & \leq & x & \leq & x_{U}, \\ b_{L} & \leq & A x & \leq & b_{U} \\ \end{array} \end{array} }


where Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle x, x_L, x_U \in \mathbb{R}^n} , Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle d \in \mathbb{R}^M} , Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle C \in \mathbb{R}^{M \times n}} , Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A \in \mathbb{R}^{m_1 \times n}} and Failed to parse (SVG with PNG fallback (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle b_L,b_U \in \mathbb{R}^{m_1}} .

The following file defines and solves a problem in TOMLAB.

File: tomlab/quickguide/llsQG.m

Open the file for viewing, and execute llsQG in Matlab.

 % llsQG is a small example problem for defining and solving
 % linear least squares using the TOMLAB format.
 Name='LSSOL test example';           % Problem name, not required.
 n = 9;                              
 x_L = [-2 -2 -inf, -2*ones(1,6)]';   % Lower bounds on x
 x_U = 2*ones(9,1);                   % Upper bounds on x
 
 % Matrix defining linear constraints
 A   = [ ones(1,8) 4; 1:4,-2,1 1 1 1; 1 -1 1 -1, ones(1,5)]; 
 b_L = [2    -inf -4]';    % Lower bounds on the linear inequalities
 b_U = [inf    -2 -2]';    % Upper bounds on the linear inequalities
 
 % Vector m x 1 with observations in objective ||Cx -y(t)||
 y = ones(10,1);  
 
 % Matrix m x n in objective ||Cx -y(t)||
 C = [ ones(1,n); 1 2 1 1 1 1 2 0 0; 1 1 3 1 1 1 -1 -1 -3; ...
       1 1 1 4 1 1 1 1 1;1 1 1 3 1 1 1 1 1;1 1 2 1 1 0 0 0 -1; ...
       1 1 1 1 0 1 1 1 1;1 1 1 0 1 1 1 1 1;1 1 0 1 1 1 2 2 3; ...
       1 0 1 1 1 1 0 2 2];
 
 % Starting point.
 x_0 = 1./[1:n]';
 
 % x_min and x_max are only needed if doing plots.
 x_min = -ones(n,1);
 x_max =  ones(n,1);                          
 
 % x_opt estimate.
 x_opt = [2 1.57195927 -1.44540327 -0.03700275 0.54668583 0.17512363 ...
           -1.65670447 -0.39474418  0.31002899]; 
 f_opt = 0.1390587318; % Estimated optimum.
 
 
 % See 'help llsAssign' for more information.
 Prob = llsAssign(C, y, x_L, x_U, Name, x_0, ...
                             [], [], [], ...
                             A, b_L, b_U, ... 
                             x_min, x_max, f_opt, x_opt);
                         
 Result = tomRun('clsSolve', Prob, 1);
 %Result = tomRun('nlssol', Prob, 1);
 %Result = tomRun('snopt', Prob, 1);
 %Result = tomRun('lssol', Prob, 1);