QR decomposition
Factor a real matrix into Q with orthonormal columns and an upper-triangular R using Gram-Schmidt: the matrix with rows 3, 1 and 0, 2 is already triangular, so Q is the identity and R equals it. Up to 20 rows and 20 columns. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
This QR decomposition calculator factors a real matrix A into an orthonormal factor Q and an upper-triangular factor R so that A equals Q times R, using the Gram-Schmidt process on the columns of A. The arithmetic is fully deterministic: inner products, Euclidean norms, and column updates use only finite floating-point operations with no network calls, no sampling, and no date-dependent shortcuts.
What QR decomposition means and what you get
The QR factorization of a real matrix A with m rows and n columns, where m is at least n, writes A as the product of an m-by-n matrix Q whose columns are orthonormal and an n-by-n upper-triangular matrix R. Orthonormal means that the transpose of Q times Q equals the identity of order n: each column has Euclidean length one and distinct columns are pairwise orthogonal. Existence of this thin factorization with a strictly positive diagonal on R is equivalent to the columns of A being linearly independent.
If a later column lies in the span of earlier ones, Gram-Schmidt produces a residual whose Euclidean norm is zero and no well-defined unit column can be formed. This calculator applies the Gram-Schmidt process, modified for numerical stability, to the columns you supply, records the successive inner products in R, and normalizes each residual to obtain Q.
Where QR factorization fits in study, science, and software
Students meet QR decomposition when a linear algebra course moves from Gram-Schmidt orthogonalization to least squares, when a contest problem asks for Q and R of a small integer matrix, or when they check that Q transpose times Q is the identity before trusting a hand calculation. Teachers can pre-generate answer keys for modest m and n without trusting opaque calculator apps that silently switch to Householder reflectors, flip column signs, or drop a dependent column without saying so.
Developers call the same contract from scripts to seed deterministic test vectors for solvers, to orthonormalize user-entered basis columns before a projection demo, or to satisfy programming-challenge statements that demand the Gram-Schmidt QR pair rather than a sketch. Engineering and data practice often needs a fast, offline factorization of a small full-rank system so a least-squares residual or a change of basis can be checked without a full computer-algebra stack under time pressure.
Product and education tools use the factorization when a learner types a matrix and the interface must show Q beside R with the method named. Keep m and n modest and coefficients within ordinary floating-range magnitudes so cancellation does not dominate; for classroom integers and typical engineering scales the factors are exact within double precision.
What you can do with it
Homework and Gram-Schmidt checks
Factor textbook matrices into Q and R and verify that Q has orthonormal columns and A equals Q times R before exams or least-squares lessons.
Solvers and tutoring software
Orthonormalize user-entered basis columns into a thin QR pair for projection demos, least-squares helpers, and interactive linear-algebra lessons.
FAQ
What does the QR decomposition calculator cost?
It is free in your browser on this page.
How are Q and R computed?
By modified Gram-Schmidt on the columns of A. Each column is orthogonalized against the unit columns already accepted; the residual length becomes a positive diagonal entry of R and the residual is scaled to unit length to form the next column of Q.
What happens if the columns are linearly dependent?
A residual of near-zero length means a later column lies in the span of earlier ones, so a thin QR with a strictly positive diagonal does not exist. This tool does not drop columns or return a rank-revealing substitute.
Does this work for rectangular matrices?
Yes, when the matrix is tall or square (at least as many rows as columns) and the columns are linearly independent. A fat matrix with more columns than rows is rejected because those columns cannot be independent.
Why are results rounded to a precision?
Default precision is 10 decimal places; you can set precision from 0 to 15.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/qr-decomposition \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"matrix":[[1,1],[1,0],[0,1]]}'const res = await fetch("https://api.kit.forhosting.com/math/qr-decomposition", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"matrix": [
[
1,
1
],
[
1,
0
],
[
0,
1
]
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/qr-decomposition",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"matrix": [
[
1,
1
],
[
1,
0
],
[
0,
1
]
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/qr-decomposition", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"matrix":[[1,1],[1,0],[0,1]]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"matrix":[[1,1],[1,0],[0,1]]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/qr-decomposition", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"matrix": [
[
1,
1
],
[
1,
0
],
[
0,
1
]
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.qr_decomposition",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_rows | 20 |
max_cols | 20 |
max_abs_entry | 1000000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
When a column is a linear combination of earlier columns, the residual after orthogonalization collapses and the request is rejected with invalid input instead of inventing a rank-revealing substitute or a Householder path.
What QR decomposition means and what the response contains
The response returns Q and R rounded to the requested precision, an echo of the input matrix, the dimensions, the method tag gram_schmidt, the precision used, and a short formula reminder. There is no Householder reflector path, no Givens rotation path, and no rank-revealing fallback: the engine either finishes with a full-column-rank factorization inside the documented size and magnitude limits or rejects the input with invalid_input. Rejected cases include a missing matrix, non-array rows, jagged shapes, more columns than rows, non-finite entries, magnitudes above the ceiling, and any matrix whose columns are linearly dependent.
How the matrix is read and how Q and R stay reproducible
Optional leading plus signs and scientific notation on entry strings are allowed when they parse as finite decimals; embedded spaces, hex prefixes, and non-numeric tokens are rejected with a clear message so a bad cell does not become a wrong factor. The shape must be tall or square: m rows by n columns with m at least n, because more columns than rows cannot be linearly independent. Computation uses modified Gram-Schmidt: each working column is orthogonalized against the unit columns already accepted, the residual length becomes the next positive diagonal entry of R, and the residual is scaled to unit length. The preferred field is matrix, a nested array of rows of finite numbers with the same column count in every row, but aliases a, A, and mat are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. An optional precision field, with aliases decimals and dp, chooses how many decimal places to expose for every entry of Q and R, defaulting to ten and capped at fifteen so JSON goldens stay stable. A residual whose length falls below a tight absolute and relative tolerance is treated as linear dependence and fails with invalid_input. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing Gram-Schmidt yourself.
Where QR factorization fits in study, science, and software
On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result.
Integration use cases
Deterministic test fixtures
Generate reproducible Q and R values for unit tests, property checks, and continuous-integration assertions that must not depend on a local numeric library.