5.0

5.0 | 3 ratings Rate this file 46 downloads (last 30 days) File Size: 4.55 KB File ID: #13835

LSE

by John D'Errico

 

01 Feb 2007 (Updated 19 Sep 2007)

Code covered by the BSD License  

A linear least squares solver, subject to linear equality constraints

Download Now | Watch this File

File Information
Description

This submission was written by request - as a tool to handle linear least squares problems, subject to linear equality constraints that may potentially be rank deficient. (It handles problems with full rank constraints of course too.) In the event of a rank deficient constraint system, it tests for consistency of the constraints.

I added a few other features to LSE:

- It allows multiple right hand sides to the least squares problem, fully vectorized of course.
- Weights may be supplied.
- You are offered a choice of least squares solvers, either backslash or pinv.

LSE solves the problem (for an unknown vector x)

   argmin norm(A*x - b)

subject to the constraints

   C*x = d

As an example, consider the random system
A = rand(10,3);
b = rand(10,1);

With a rank deficient constraint set
C = [1 1 1;1 1 1];
d = [1;1];

X = lse(A,b,C,d)
X =
       0.5107
       0.57451
     -0.085212

Verify that the constraints are satisfied

C*X
ans =
          1
          1

Column pivoting is used to eliminate variables from the constraint system when \ is specified, and when pinv is specified, an svd is used for the final solution.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Basic Matlab code - this should be accessible to most older releases.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
19 Mar 2007 Lukas Malec

Thank you. It's a very good work!

18 Sep 2007 Matt Ferrara

Great code! Do you have any references on the approach you have implemented? (maybe you could put them in the documentation for release 3?)

23 Jan 2009 Greg

Great piece of code! I do have a question? Is there a way to bound the results to be positive (i.e. x>0)?

24 Jan 2009 John D'Errico

Greg - If you want to apply inequality or bound constraints, the simplest way is to use lsqlin from the optimization toolbox. That tool implements all forms of linear constraints.

Please login to add a comment or rating.
Updates
02 Feb 2007

Version 2.0 - Used a better solution for when pinv was specified. Also allowed the code to work when no constraints at all are supplied.

19 Sep 2007

Version 3.0: As requested, comments on the methodology used are now included in the help.

Tag Activity for this File
Tag Applied By Date/Time
linear algebra John D'Errico 22 Oct 2008 08:59:09
linear John D'Errico 22 Oct 2008 08:59:09
least John D'Errico 22 Oct 2008 08:59:09
squares John D'Errico 22 Oct 2008 08:59:09
equality John D'Errico 22 Oct 2008 08:59:09
constraints John D'Errico 22 Oct 2008 08:59:09
regression John D'Errico 22 Oct 2008 08:59:09
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com