<< ddpow DD: 16 bytes decimal arithmetics ddrand >>

DD_QD (MuPAT) >> DD_QD (MuPAT) > DD: 16 bytes decimal arithmetics > qr

qr

QR factorization of a DD matrix

Syntax

[Q, R] = qr(A)

Parameters

A

matrix of DD real numbers, of size [m,n].

Q

Orthogonal matrix of DD real numbers, of size [m,m].

R

upper Right triangular matrix of DD real numbers, of size [m,n] = size(A).

Description

[Q,R]= qr(A) computes the matrices Q and R such that A = Q*R, with Q orthogonal, and R upper-Right triangular.

Examples

Square input matrix:

A = ddrand(3,3)
[Q,R] = qr(A)
Q'*Q     // Q orthogonal
Q*R - A
--> A = ddrand(3,3)
 A  = 
[d1]
   0.6912788   0.76934     0.9561172
   0.7656859   0.5477634   0.2207409
   0.357265    0.0962289   0.0143259

[d2] 10^-17 *
  -2.1563392  -3.3012259   0.0754278
   3.3926528  -4.8015079   0.5082632
  -1.6398934  -0.3715576  -0.0100407


--> [Q,R] = qr(A)
 R  = 
[d1]
  -1.0916865  -0.9028437  -0.7649447
   0.          0.2933632   0.5700987
   0.          0.         -0.2300846

[d2] 10^-17 *
  -9.0947905   2.7862969   1.1048161
   0.          1.7805365   0.8939544
   0.          0.          0.6188504


 Q  = 
[d1]
  -0.633221    0.6737055  -0.3809883
  -0.7013789  -0.2913525   0.6505239
  -0.3272597  -0.6791425  -0.6570133

[d2] 10^-17 *
   0.6394485  -0.9725349  -2.2612669
   5.1128525   1.4099617  -2.095428 
   1.0405078  -4.7400587  -2.6590128


--> Q'*Q     // Q orthogonal
 ans  =
[d1]
   1.   0.   0.
   0.   1.   0.
   0.   0.   1.

[d2] 10^-17 *
  -1.849D-15   0.          0.       
   0.          3.698D-15   0.       
   0.          0.         -4.314D-15


--> Q*R - A
 ans  =
[d1] 10^-32 *
  -1.2325952   1.2325952  -0.3081488
   1.2325952   0.          0.9244464
   0.         -0.2311116  -1.3866696
  
[d2] zeros(3,3)

Rectangular input matrix:

A = ddrand(3,4)
[Q,R] = qr(A)
Q'*Q     // Q orthogonal
(Q*R)(2), A(2)
(Q*R)(1:$-1,:) - A
--> A = ddrand(3,4)
 A  = 
[d1]
   0.7883861   0.9709819   0.8525161   0.028486 
   0.3453042   0.8875248   0.6744698   0.2367841
   0.2659857   0.2066753   0.9152874   0.7015344

[d2] 10^-17 *
  -0.3388527   1.1452892  -4.2847864   0.0475098
   2.485645    2.0398681   3.9345457  -0.3019807
   1.5545584   0.5803466  -2.9278544   3.8157225


--> [Q,R] = qr(A)
 R  = 
[d1]
  -0.900853  -1.2509781  -1.2748612  -0.3228259
   0.        -0.4563709  -0.0454238   0.0461185
   0.         0.         -0.6261867  -0.6653459

[d2] 10^-17 *
   5.1095656  -8.5066542  -4.2787347   0.6116295
   0.         -2.7577039  -0.1083261   0.2324751
   0.          0.          0.8326262   5.4850138

   
 Q  = 
[d1]
  -0.8751551   0.2713101   0.4006174
  -0.3833081  -0.8940419  -0.2318707
  -0.2952599   0.3564827  -0.8864207
   0.          0.          0.       

[d2] 10^-17 *
  -2.6423348   1.9069959  -0.586978 
   1.729251    1.0532369   0.2681887
   0.8431917   2.658457    4.3158254
   0.          0.          0.       


--> Q'*Q     // Q orthogonal
 ans  =
[d1]
   1.   0.   0.
   0.   1.   0.
   0.   0.   1.

[d2] 10^-17 *
   3.081D-16   0.          0.       
   0.         -8.936D-15   0.       
   0.          0.          2.465D-15


--> (Q*R)(2), A(2)
 ans  =
   0.7883861   0.9709819   0.8525161   0.028486 
   0.3453042   0.8875248   0.6744698   0.2367841
   0.2659857   0.2066753   0.9152874   0.7015344
   0.          0.          0.          0.       

 ans  =
   0.7883861   0.9709819   0.8525161   0.028486 
   0.3453042   0.8875248   0.6744698   0.2367841
   0.2659857   0.2066753   0.9152874   0.7015344


--> (Q*R)(1:$-1,:) - A 
 ans  =
[d1] 10^-32 *
   0.6933348  -5.0844551  -2.4651903   0.6162976
  -0.9244464  -7.395571   -3.6977855  -2.0800043
   0.          0.3081488   1.2325952  -1.2325952

[d2] zeros(3,4)

See Also

Authors

Copyright (C) 2011 - Tsubasa Saito Copyright (C) 2018 - Samuel GOUGEON

Report an issue
<< ddpow DD: 16 bytes decimal arithmetics ddrand >>