ForHosting KIT · Math

Diagonalize a matrix

For the matrix with rows (2, 1) and (1, 2) you get the eigenvalues 3 and 1, the diagonal matrix D and the eigenvector matrix P, so that A = P·D·P⁻¹. A matrix that cannot be diagonalized is reported plainly. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Runs in your browser. Free, unlimited — your data never leaves this page.

The diagonalize matrix calculator takes a square matrix and returns its full eigendecomposition: the eigenvalues, the diagonal matrix D built from them, and the change-of-basis matrix P whose columns are the corresponding eigenvectors, so that A = P·D·P⁻¹. Diagonalization turns hard problems into easy ones — matrix powers, exponentials, differential equations and Markov chains all become entrywise operations once a matrix is written in its eigenbasis. Instead of working the characteristic polynomial by hand or installing a numerical library, you send the entries and get the decomposition back in one deterministic call, with every value rounded to the precision you choose. The same code runs free in your browser on this page, so you can check a matrix by pasting it and only pay when you automate the workflow.

What diagonalizing a matrix means

A square matrix A is diagonalizable when it has enough independent eigenvectors to form a basis — n of them for an n×n matrix. In that case you can write A = P·D·P⁻¹, where D is a diagonal matrix holding the eigenvalues and P is the change-of-basis matrix whose columns are the eigenvectors, in the same order.

This decomposition is one of the central results of linear algebra because diagonal matrices are trivial to work with: raising D to the fiftieth power just raises each diagonal entry to the fiftieth power. The diagonalize matrix calculator computes this factorization directly from the entries you provide. It returns the eigenvalues sorted from largest to smallest, the diagonal matrix D and the full matrix P, so you can verify the identity A·P = P·D yourself or feed the pieces into the next step of your calculation.

How the computation works

The algorithm is fully deterministic — no random starting points, no iteration counts that change from run to run — so the same matrix always produces the same decomposition. Symmetric matrices, which appear constantly in statistics, physics and optimization, are handled with cyclic Jacobi sweeps: a sequence of plane rotations that zeroes the off-diagonal entries while accumulating the rotations into the eigenvector matrix.

Jacobi is slow in theory for huge matrices but is extremely accurate for the small and medium sizes this tool accepts, and it copes gracefully with repeated eigenvalues, where other methods struggle. General non-symmetric matrices are handled with a Wilkinson-shifted QR iteration to extract the eigenvalues, followed by inverse iteration to recover an eigenvector for each one. Every output entry is rounded to the decimal precision you request, from 0 to 15 places, with ten as the default.

Where teams use it

Diagonalization shows up anywhere a linear system evolves over time. Engineers computing the long-term behavior of a Markov chain need the eigenvalues to know whether the chain converges and how fast; the dominant eigenvalue and its eigenvector give the steady state directly. Developers working with recurrence relations or coupled difference equations diagonalize the transition matrix to get a closed-form solution instead of iterating.

In graphics and geometry, decomposing a transformation reveals the axes along which it stretches space. Data teams use it as a building block: principal component analysis is the eigendecomposition of a covariance matrix, and spectral graph methods start from the eigenvectors of a Laplacian.

Compute matrix powers fast

Get P and D once, then compute A^k as P·D^k·P⁻¹ — each eigenvalue is simply raised to the k-th power.

Analyze a Markov chain

Extract the dominant eigenvalue and its eigenvector to find the steady-state distribution and convergence rate.

Check homework and course work

Verify a hand-worked diagonalization against a deterministic reference before submitting it.

What matrices are accepted?

Any square matrix of real, finite numbers up to 50×50.

What if my matrix cannot be diagonalized?

Matrices with complex eigenvalues, or defective matrices without n independent real eigenvectors, are rejected with a clear error rather than an approximate answer.

How are the results ordered?

Eigenvalues are returned from largest to smallest, and the columns of the change-of-basis matrix P follow the same order.

How do I verify the answer?

Multiply A·P and P·D — they must be equal. For symmetric matrices the columns of P are also orthonormal, so P⁻¹ equals the transpose of P.

Is my matrix stored anywhere?

No. It is processed in memory and discarded; only the decomposition is returned.

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.

POSThttps://api.kit.forhosting.com/math/diagonalize-matrix

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.

curl -X POST https://api.kit.forhosting.com/math/diagonalize-matrix \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"matrix":[[2,1],[1,2]]}'
{
  "matrix": [
    [
      2,
      1
    ],
    [
      1,
      2
    ]
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.diagonalize_matrix",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_n50
max_abs_entry1000000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

What diagonalizing a matrix means

If the matrix is not square the request is rejected, and if it has complex eigenvalues or no complete set of real eigenvectors the tool says so plainly instead of returning numbers that look plausible but are wrong.

How the computation works

Before returning, the tool checks that the eigenvector matrix P is invertible; if the columns are nearly parallel the matrix is defective — like the classic [[1,1],[0,1]] — and cannot be diagonalized, so the request fails with a clear error rather than a silently broken answer.

Where teams use it

Because the capability runs on our global edge with nothing stored after the response, it also fits cleanly into automated pipelines — a script can submit matrices as part of a nightly job for $0.002 per call, while a human checks the same matrices free in the browser with byte-identical results. That parity between the free web tool and the paid API is deliberate: the same module powers both.

What does it cost?

$0.002 per request via the API. It is also free to run in your browser on this page, with identical results.

Read the full KIT documentation →