Simultaneous Equations Solver in MATLAB

For most numerical linear systems A*x = b, use MATLAB's backslash operator: x = A\b. It solves the system without explicitly forming A⁻¹. Check the residual norm before relying on the result.

Written and checked by TheToolNet Editorial Team · Last reviewed: August 21, 2026 · Editorial policy

Recommended numerical syntax
x = A\b

The backslash operator calls mldivide. MathWorks recommends it for most numerical linear systems.

AdvertisementReserved space — no ad is loaded

Solve a numerical linear system

For 2x + 3y = 13 and x − y = −1, put coefficients in A and constants in b:

A = [2 3; 1 -1];
b = [13; -1];
x = A\b

MATLAB returns a column vector with x = 2 and y = 3. Semicolons create new rows, spaces separate columns, and the row order in b must match the equation order in A.

A 3×3 system uses exactly the same pattern:

A = [1 1 1; 2 -1 1; 1 2 -1];
b = [6; 3; 2];
x = A\b

This returns [1; 2; 3].

Verify the MATLAB solution

Calculate the residual vector and its norm:

residual = A*x - b;
residualNorm = norm(residual)

For an ordinary well-conditioned system, the residual norm should be close to zero, allowing for floating-point rounding. A small residual shows that A*x is close to b; it does not by itself guarantee that a badly conditioned system has an accurate x. Check rcond(A) for a square matrix when conditioning matters.

Check a 2×2 or 3×3 system online

Backslash, linsolve or symbolic solve?

MATLAB methodUse it forExample
A\bMost numerical linear systems; MATLAB chooses an appropriate factorization.x = A\b
linsolve(A,b)Numerical systems when you want its optional reciprocal-condition or rank output, or can safely specify matrix properties.[x,r] = linsolve(A,b)
solveSymbolic equations, exact parameters, or expressions that are not already written as A*x = b. Requires Symbolic Math Toolbox.[x,y] = solve(eqns,[x y])
Avoid inv(A)*b for routine numerical solving. MathWorks explains that backslash solves A*x = b without explicitly computing the inverse, which is generally less work and avoids extra finite-precision error.

Singular and rectangular systems

If A is square but singular or nearly singular, MATLAB may issue a warning and return a basic or approximate result depending on the matrix. Do not treat that output as a unique solution without checking rank and residual:

rankA = rank(A);
rankAugmented = rank([A b]);

If rank(A) is smaller than rank([A b]), the system is inconsistent. If the ranks match but are smaller than the number of unknowns, there are free variables and infinitely many exact solutions.

Backslash also accepts rectangular matrices. For an overdetermined system it ordinarily returns a least-squares solution; that is a best fit, not necessarily a vector that makes every residual zero. Always interpret the dimensions and residual in context.

Common MATLAB problems

ProblemCheck
Incorrect matrix dimensionsA and b must have the same number of rows for A\b.
Unexpected one-row resultUse semicolons in b to create a column vector: [13; -1], not [13 -1].
Singular-matrix warningCompare ranks and inspect the residual; the system may lack a unique solution.
Symbolic variables are undefinedCreate them with syms and confirm Symbolic Math Toolbox is available.
Tiny non-zero residualsFloating-point rounding is normal; judge the scale instead of testing exact equality.

Frequently asked questions

How do I solve simultaneous equations in MATLAB?

For a numerical linear system, put coefficients in A, constants in b, and run x = A\b. Verify with norm(A*x − b).

Why is backslash better than inv(A)*b?

Backslash solves the system directly without explicitly computing A inverse. This generally requires less work and avoids extra numerical error.

Can MATLAB solve nonlinear simultaneous equations?

Yes, but A\b is only for linear systems. Depending on the problem and installed toolboxes, symbolic solve, numerical vpasolve, or an optimization/root-finding function may be appropriate.

Official MATLAB references

For visible row operations, return to the online simultaneous equations solver. Spreadsheet users can follow the Excel guide.