g | x | w | all
Bytes Lang Time Link
098BQN250308T211356Zpanadest
019Octave171226T214349ZMr. Xcod
324Python 2171227T012457ZTyilo
037R171226T215258Zrturnbul
028Python with numpy171227T003354ZTyilo
002Julia171227T001840ZAlex A.
027SageMath171226T235308ZTyilo
015Wolfram Language Mathematica171226T221151Znotjagan

BQN, 110 100 98 bytes

+˝∘×⎉1‿∞{1=⊢´≢𝕩?𝕩⊸÷⟜⊑⊸⋈√+˝×˜𝕩;∾˘{(q𝔽𝕨)⋈(r𝔽t)∾0𝔽⍟k𝕩}´𝕊𝔽{𝕘-𝕩𝔽t↩𝕩⍉⊸𝔽𝕘}(k↓˘𝕩)⊑q‿r←𝕊𝕩↑˘˜k←⌈2÷˜⊢´≢𝕩⊣t←@}

An answer without built-ins. Inspired by the recursive block QR algorithm from Golub and van Loan's book, algorithm 5.2.3. Uses Gram–Schmidt.

BQN online REPL

Octave, 19 bytes

@(x)[[q,r]=qr(x),r]

Try it online!

My first Octave answer \o/

Octave’s qr has quite a few alternatives in other languages that return both Q and R: QRDecomposition (Mathematica), matqr (PARI/GP), 128!:0 - if I recall correctly - (J), qr (R)...

Python 2, 329 324 bytes

import fractions
I=lambda v,w:sum(a*b for a,b in zip(v,w))
def f(A):
 A,U=[map(fractions.Fraction,x)for x in zip(*A)],[]
 for a in A:
    u=a
    for v in U:u=[x-y*I(v,a)/I(v,v)for x,y in zip(u,v)]
    U.append(u)
 Q=[[a/I(u,u)**.5 for a in u]for u in U];return zip(*Q),[[I(e,a)*(i>=j)for i,a in enumerate(A)]for j,e in enumerate(Q)]

We must use fractions to ensure correct output, see https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process#Numerical_stability

Indentation used:

  1. 1 space
  2. 1 tab

R, 38 37 bytes

pryr::f(list(qr.R(q<-qr(m)),qr.Q(q)))

Try it online!

Python with numpy, 28 bytes

import numpy
numpy.linalg.qr

Julia, 2 bytes

qr

The function qr accepts a square matrix and returns a Tuple of matrices: Q and R.

Try it online!

SageMath, 27 bytes

lambda x:matrix(RDF,x).QR()

Wolfram Language (Mathematica), 15 bytes

QRDecomposition

Try it online!

I mean... what can I say?