# QR decomposition: qr

### 5.49.2 QR decomposition: qr

The QR decomposition of a square matrix A is A=QR, where Q is an orthogonal matrix (QTQ=I) and R is upper triangular. The qr command finds the QR decomposition of a matrix.

- qr takes one argument:
  A, a numeric square matrix.
- qr(A) returns a list [Q,R] with Q and R from the QR decomposition.

#### Examples.

- Input:

  A := [[3,5],[4,5]]:;
  qr(A)

  Output:

  ⎛
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎝

  3
  5

  4
  5

  4
  5

  −

  3
  5

  ⎞
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎠

  ,

  ⎡
  ⎢
  ⎣

  5 | 7
  0 | 1

  ⎤
  ⎥
  ⎦

- Input:
  qr([[1,2],[3,4]])
  Output:

  ⎛
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎝

  1

  √

  10

  3

  5

  √

  10

  5

  3

  √

  10

  −

  1

  5

  √

  10

  5

  ⎞
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎠

  ,

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  √

  10

  7
  5

  √

  10

  0

  √

  10

  5

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦