Path: news.mathworks.com!not-for-mail
From: "Tim Davis" <davis@cise.ufl.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: nonnegative Ax=b lsq for large, sparse A.
Date: Fri, 26 Jun 2009 15:05:04 +0000 (UTC)
Organization: University of Florida
Lines: 48
Message-ID: <h22o30$gi5$1@fred.mathworks.com>
References: <h22iil$a5s$1@fred.mathworks.com>
Reply-To: "Tim Davis" <davis@cise.ufl.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246028704 16965 172.30.248.38 (26 Jun 2009 15:05:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 26 Jun 2009 15:05:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:550911


"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <h22iil$a5s$1@fred.mathworks.com>...
> Hello all,
> 
> I have a large, sparse, rectangular (overdetermined) matrix A.
> 
> I'm solving Ax = b, where all elements of A, x and b are nonnegative.
> 
> I thought at first that lsqnonneg would be my ideal function, however, I hadn't realised that it is not useful for large sparse matrices (creates a full matrix the same size as A).
> 
> Does anyone know of an alternative for lsqnonneg which may be used with a large, sparse coefficients matrix?
> 
> A sample of the problem (.mat file containing A and b) can be found in:
> http://www2.eng.cam.ac.uk/~thc29/lsqnonneg_sparse/
> 
> Tim Davis, if you happen across this, you may enjoy the sparsity pattern (it's for a tomographic reconstruction of a particle field in fluid flow).
> 
> Thanks all, and kind regards
> 
> Tom Clark

Gee, how did you know I'd be interested in large sparse matrices ... ?  :-)

I did download it, but it didn't load properly.  I got very bizarre error messages:
HDF5-DIAG: Error detected in HDF5 (1.8.1) thread 0:
  #000: H5Gdeprec.c line 1063 in H5Gget_objname_by_idx(): not a location ID
    major: Invalid arguments to routine
    minor: Inappropriate type
  #001: H5Gloc.c line 241 in H5G_loc(): invalid object ID
    major: Invalid arguments to routine
    minor: Bad value

And I get a blizzard of those errors (living in Florida, I guess I should say "hurricane" not "blizzard", but I grew up in Indiana...).

Can you do this instead?

[i j x] = find (A) ;
f=fopen('A.txt','w') ;
fprintf (f,'%d %d %32.17g\n', [i j x]') ;
fclose (f) ;
f=fopen('b.txt','w') ;
fprintf (f,'%32.17g\n',b) ;
fclose (f)

assuming b is a dense column vector, and post these txt files instead?

And may I add it to my collection?

John ... which version MATLAB are you using?  I tried your example on a Pentium 4 running MATLAB 7.8 (R2009a) and sparse backslash took just 4.2 seconds.  lsqlin took 0.9 seconds (with no "opts" argument since you didn't say what it was).  SPQR_SOLVE took 0.6 seconds, but of course A\b and spqr_solve return x with negative values, whereas lsqlin respects the lower bound lb.