Jump to content

QR decomposition: Difference between revisions

m
→‎{{header|Python}}: Add note on Numpy qr function.
(Python solution)
m (→‎{{header|Python}}: Add note on Numpy qr function.)
Line 1,312:
=={{header|Python}}==
{{libheader|numpy}}
Numpy has a qr function but here is a reimplementation to show construction and use of the Householder reflections.
<lang python>#!/usr/bin/env python3
 
Line 1,338 ⟶ 1,339:
( 6, 167, -68),
(-4, 24, -41),
)))
)), dtype=np.float64)
 
q, r = qr(a)
Line 1,353 ⟶ 1,354:
return np.linalg.solve(r[:n, :], np.dot(q.T, b)[:n])
 
x = np.array((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), dtype=np.float64)
y = np.array((1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321), dtype=np.float64)
 
print('\npolyfit:\n', polyfit(x, y, 2))</lang>
1,707

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.