qr
result = qr(A)
Input: A · Output: result
What it is
Thin QR decomposition of A (r×c Mat), A = Q·R.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = qr(A) | A Matnot documented yet | Model —kind "qr"q Matr×k Mat, orthonormal columnsr Matk×c Mat, upper triangular | Returns a Model (kind "qr") with fields q (r×k Mat, orthonormal columns) and r (k×c Mat, upper triangular), k = min(r,c). |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
M = [4, 3; 6, 3]
res = qr(M)
print(res)
print("q = {res.q}")
print("r = {res.r}")
x = [0, 1, 3, 1, 0, 2, 4, 2, 0]
pk = findpeaks(x)
print(pk)
print("peaks = {pk.peaks}")
print("locations = {pk.locations}")
output
model(qr) {q = [0.5547, 0.83205; 0.83205, -0.5547], r = [7.211103, 4.160251; 0, 0.83205]}
q = [0.5547, 0.83205; 0.83205, -0.5547]
r = [7.211103, 4.160251; 0, 0.83205]
model(findpeaks) {peaks = [3, 4], locations = [2, 6], prominences = [3, 4], widths = [1.5, 2]}
peaks = [3, 4]
locations = [2, 6]from tour
s = svd([1, 2; 3, 4; 5, 6])
S = [s.s[0], 0; 0, s.s[1]]
print("U*S*Vt reconstructs A: {s.u * S * s.vt}")
r = qr([1, 2; 3, 4; 5, 6])
print("Q*R == A: {r.q * r.r}")
f = lu([2, 1, 1; 4, 3, 3; 8, 7, 9])
print("P*A == L*U: {f.p * [2,1,1;4,3,3;8,7,9]} vs {f.l * f.u}")
output
U*S*Vt reconstructs A: [1, 2; 3, 4; 5, 6] Q*R == A: [1, 2; 3, 4; 5, 6] P*A == L*U: [8, 7, 9; 2, 1, 1; 4, 3, 3] vs [8, 7, 9; 2, 1, 1; 4, 3, 3]
from numerics-dsp
function summarize(m: model<"qr">)
return "qr: q is {rows(m.q)}x{cols(m.q)}, r is {rows(m.r)}x{cols(m.r)}"
end function
function summarize(m: model<"svd">)
return "svd: singular values = {m.s}"
end function
function summarize(m: model)
return "generic model, kind unhandled"
end function
A = [4, 3; 6, 3]
qres = qr(A)
sres = svd(A)
pk = findpeaks([0,1,3,1,0,2,4,2,0])
print(summarize(qres))
print(summarize(sres))
print(summarize(pk))
from tour
How it works
qr(A) — the thin QR decomposition A = Q * R. Model kind "qr", fields q/r.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.