;+ ; NAME: ; QRSOLV ; ; AUTHOR: ; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 ; craigm@lheamail.gsfc.nasa.gov ; ; PURPOSE: ; Solve a linear equation after performing QR factorization ; ; MAJOR TOPICS: ; Linear Systems ; ; CALLING SEQUENCE: ; X = QRSOLV(A, R, B, PIVOTS=IPVT) ; ; DESCRIPTION: ; ; The procedure QRSOLV completes the solution of a linear equation, ; ; A ## x = B ; ; after the MxN matrix has been factorized by QR decomposition. ; After being factorized once using QRFAC, the matrices can be used ; for multiple righthand sides (i.e., different B's). ; ; The solution technique is to first compute the factorization using ; QRFAC, which yields the orthogonal matrix Q and the upper ; triangular matrix R. [ Actually, Q is represented by its ; Householder reflectors. ] Then the solution vector, X, is computed ; using QRSOLV. ; ; If pivoting was performed in the factorization, the permutation ; vector IPVT returned by QRFAC must also be passed to QRSOLV. ; ; ; PARAMETERS: ; ; A - upon input, the factorized matrix A, returned by QRFAC. ; ; R - upon input, the upper diagonal matrix R, returned by QRFAC. ; ; B - upon input, the righthand vector B, which fits into the ; equation, A ## x = B ; ; X - upon ouptut, the solution vector X, to the above linear ; equation. For an overdetermined system, X is the least ; squares solution which minimizes TOTAL( (A ## X - B)^2 ). ; ; ; KEYWORD PARAMETERS: ; ; PIVOTS - upon input, the permutation matrix IPVT returned by ; QRFAC, if pivoting is to be performed. ; ; ; EXAMPLE: ; ; Solve the equation A ## X = B, in the least squares sense, where: ; ; A = [[1.0,1.0,1.0,1.0,1.0,1.0],$ ; [0.6,0.8,0.5,0.8,0.7,0.9],$ ; [0.2,0.3,0.1,0.4,0.3,0.4]] ; ; and B = [0.57E,0.69,0.5,0.7,0.6,0.8] ; ; qrfac, a, r, ipvt, /PIVOT ; x = qrsolv(a, r, b, PIVOTS=ipvt) ; ; print, x ; 0.0834092 0.852273 -0.179545 ; ; REFERENCES: ; ; More', Jorge J., "The Levenberg-Marquardt Algorithm: ; Implementation and Theory," in *Numerical Analysis*, ed. Watson, ; G. A., Lecture Notes in Mathematics 630, Springer-Verlag, 1977. ; ; MODIFICATION HISTORY: ; Written (taken from MPFIT), CM, Feb 2002 ; Usage message, error checking, CM, 15 Mar 2002 ; Error checking is fixed, CM, 10 May 2002 ; Found error in return of permuted results, CM, 21 May 2004 ; ; $Id: qrsolv.pro,v 1.4 2004/05/22 02:16:02 craigm Exp $ ; ;- ; Copyright (C) 2002, 2004, Craig Markwardt ; This software is provided as is without any warranty whatsoever. ; Permission to use, copy, modify, and distribute modified or ; unmodified copies is granted, provided this copyright and disclaimer ; are included unchanged. ;-