solving linear system with decomposition(A,'qr') and qr(A) produce ... (2024)

29 views (last 30 days)

Show older comments

Qiang Li on 24 Jul 2024 at 11:35

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results

Commented: Christine Tobler on 24 Jul 2024 at 16:41

Accepted Answer: Christine Tobler

  • post.mat

Open in MATLAB Online

load post.mat

x1 = decomposition(CA,'qr')\b_f;

Warning: Rank deficient, rank = 44, tol = 1.470347e-01.

[qq2,rr2,pp2] = qr(CA);

x2= pp2 * (rr2\(qq2'*b_f));

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.100607e-25.

[qq3,rr3,pp3] = qr(CA,"econ","vector");

x3(pp3,:) = rr3\(qq3'*b_f);

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.100607e-25.

any(x1-x2~=0)

ans = 1x3 logical array

1 1 1

I know that the CA matrix is ill-conditioned. But that doesn't explain the difference in solution, right?

Also, solving the system using decomposition(CA,'lu') and lu(CA) produce the same results. So why not the 'qr' pair?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Christine Tobler on 24 Jul 2024 at 12:23

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#answer_1490021

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#answer_1490021

Open in MATLAB Online

  • post.mat

There are two reasons that the results don't match:

1) When the matrix is not full-rank, the QR-based solver in decomposition only uses the upper left triangle of the R matrix returned from QR. I have replicated this in output x3 in the code below.

2) The matrix Q in decomposition is stored in a more compact format (Householder reflectors) than the one returned by the QR function. This results in some differences on the level of round-off error.

load post.mat

x1 = decomposition(CA,'qr')\b_f;

Warning: Rank deficient, rank = 44, tol = 1.470347e-01.

[qq2,rr2,pp2] = qr(CA);

x2= pp2 * (rr2\(qq2'*b_f));

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.100607e-25.

norm(x1 - x2)

ans = 4.3604e+09

rk = 44;

m = size(CA, 1);

nrhs = size(b_f, 2);

[qq2,rr2,pp2] = qr(CA);

x3 = pp2 * [(rr2(1:rk, 1:rk)\(qq2(:, 1:rk)'*b_f)); zeros(m-rk, nrhs)];

norm(x1 - x3)

ans = 1.2555e-13

2 Comments

Show NoneHide None

Qiang Li on 24 Jul 2024 at 14:05

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#comment_3219616

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#comment_3219616

Open in MATLAB Online

  • post.mat

Hi Christine,

I used the 'RankTolerance' option of decomposition, and compared the results. Is the 0.0024 difference coming from your second point? Thanks.

load post.mat

min(svd(CA))

ans = 3.2181e-12

x1 = decomposition(CA,'qr','RankTolerance',1e-12)\b_f;

rk = 60;

m = size(CA, 1);

nrhs = size(b_f, 2);

[qq2,rr2,pp2] = qr(CA);

x3 = pp2 * [(rr2(1:rk, 1:rk)\(qq2(:, 1:rk)'*b_f)); zeros(m-rk, nrhs)];

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.100607e-25.

norm(x1 - x3)

ans = 0.0024

Christine Tobler on 24 Jul 2024 at 16:41

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#comment_3219751

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/2139861-solving-linear-system-with-decomposition-a-qr-and-qr-a-produce-different-results#comment_3219751

Open in MATLAB Online

  • post.mat

Yes, it's initially coming from point (2). This is amplified by the fact that matrix CA is ill-conditioned (max / min singular value is about 3e24), which means that the full matrix R is also ill-conditioned, and so the application of R\(Q'*b) takes a small difference in Q'*b and amplifies it a lot.

While RankTolerance=1e-12 doesn't seem particularly tiny, this is an absolute tolerance (not scaled by the maximum singular value of A), meaning it corresponds to about 1e-25 in relative terms.

load post.mat

max(svd(CA))

ans = 1.1161e+13

min(svd(CA))

ans = 3.2181e-12

cond(CA)

ans = 3.4681e+24

[qq2,rr2,pp2] = qr(CA);

cond(rr2)

ans = 3.4532e+24

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

Signal ProcessingDSP System ToolboxStatistics and Linear AlgebraLinear Algebra

Find more on Linear Algebra in Help Center and File Exchange

Tags

  • qr decomposition
  • linear algebra
  • linear system

Products

  • MATLAB

Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


solving linear system with decomposition(A,'qr') and qr(A) produce ... (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

solving linear system with decomposition(A,'qr') and qr(A) produce ... (2024)

FAQs

What is the QR decomposition system of linear equations? ›

In linear algebra, a QR decomposition, also known as a QR factorization or QU factorization, is a decomposition of a matrix A into a product A = QR of an orthonormal matrix Q and an upper triangular matrix R.

Is QR decomposition is the same as LU decomposition? ›

Another decomposition method is QR decomposition. One advantage of QR decomposition over LU decomposition is that this method does not require that the decomposition be carried out on a square matrix.

When to use QR decomposition? ›

So-called QR-decompositions are useful for solving linear systems, eigenvalue problems and least squares approximations.

What is the formula for the QR factorization? ›

A = QR ⇒ QT A = QT QR = R. In other words, the formula R = QT A holds, no matter what m and n are. It doesn't matter if the matrix is square or not.

What is the QR decomposition of linear regression? ›

The QR decomposition is an approach of breaking a matrix down into its constituent elements. Where A is the matrix that we wish to decompose, Q a matrix with the size m x m, and R is an upper triangle matrix with the size m x n. The QR decomposition is a popular approach for solving the linear least squares equation.

What is the LU decomposition method applied to the linear system? ›

The LU decomposition was developed by Alan Turing as an alternative way carrying out Gaussian elimination through factorization of the coefficient matrix into a product of upper and lower triangular matrices, namely, A = LU [8] . The system is solved in two consecutive steps using the equations LY = B and UX = Y [9] .

What is the existence of QR decomposition? ›

A QR decomposition can be created for any matrix — it need not be square and it need not have full rank. The matrix Q is unitary, and R is upper triangular. Thus, each column of A can be expressed as a linear combination of the columns of Q, which form an orthonormal basis.

What is the solution QR to this system of linear equations 12q + 3r + 15? ›

Summary: The solution (q, r) to this system of linear equations 12q + 3r = 15 and - 4q - 4r = - 44 is (-2, 13).

Top Articles
Keene Swap Meet 2023
Sugaring Nyc Lubbock
Amy Davis No Wedding Ring
Sombouns Asian Market - Murfreesboro, TN
Oak Lawn Patch News
Myusu Canvas
Virtual Prepaid Minutes
Local Body Rubs
AccuWeather APIs | Frequently Asked Questions
Mobile Patrol Prentiss County Ms
Ivegore Machete Mutolation
S&P 500 Hits Record High Buoyed by Economic Hopes: Markets Wrap
CYCLE WORLD 10 BEST BIKES 2022 | Cycle World | Issue 3 2022
Mommy Countdown Calendar™ with Pregnancy Gifts
Pogoda długoterminowa Warszawa na 16, 25 i 45 dni – Długoterminowa prognoza pogody w INTERIA.PL
albuquerque cars & trucks - craigslist
Cats For Free Craigslist
Devotion Showtimes Near Xscape Theatres Blankenbaker 16
craigslist: panama city, FL jobs, apartments, for sale, services, community, and events
Shell Shockers Online Unblocked
Gulfstream Entries Results
8 best things to do in Miami - Lonely Planet
Aphug Calculator
Terrorist Usually Avoid Tourist Locations
Twitter co-founder Jack Dorsey steps down as chief executive
Elliman.sharepoint
National Museum of the United States Army
Sdsaram
Bmo Branch Near Me
Www.ebtedge.com Wic
Peekskillpatch
Txdot Average Unit Prices
Fortune House Southbury Menu
Matlab Bar Graph Labels
Florida (FL) Powerball - Winning Numbers & Results
Craigslist Derry Nh
Jm White Funeral
Numbrix May 19 2019
Costco Holiday Hours California
Ilsos.gove
Commercial Cleaning Tips and Tricks: The Ultimate Guide - Green Planet
B&B Auto Salvage Okc
Ozembique
Musas Tijuana
'Saw X': Release Date, Cast, Trailer, and Everything We Know So Far
Norwegian Luna | Cruise Ship
Rimworld Prison Break
My Name Is Skyler White Yo Copypasta
Donkey Weenus
Vera Bradley Factory Outlet Sunbury Photos
Bulletbound Codes
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6451

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.