# MATLAB: Backslash operator using symbolic variables with an overdetermined system

I have an overdetermined system (too many equations), expressed as Ax=b, in MATLAB. When I try to solve it using A\b, I receive the error:

Warning: System is inconsistent. Solution does not exist.

However, if I substitute values for the symbolic variables, the system can be solved, and the answer presented matches what I calculated by hand. Is MATLAB unable to handle overdetermined systems involving symbolic variables?

• Over determined systems are solved by methods such as least squares fitting. I don't think they can meaningfully be applied to symbolic equations. Even if they could be applied, I'm sure the resulting expression would be so complex as to be useless, unless your matrix is very small. Commented Mar 19, 2015 at 11:04
• I tried using rref with the augmented matrix, and though it spat out results such as (7205749749412839*P1)/10808664850654496 + P2, this is actually 2/3 * P1 + P2, which is correct. Why is it that rref works, but the backslash operator throws an error? Commented Mar 19, 2015 at 11:08
• The matrix is 8x5 Commented Mar 19, 2015 at 11:09

tl;dr: Use MATLAB primarily for numerical computation, not symbolic computation.

MATLAB was primarily designed as a numerical computation package, and its symbolic capabilities were added later. Also, as a general rule, it's easier to compute quantities with concrete values than it is to calculate the same quantities in the abstract. For instance, no closed form solutions exist for general polynomial equations of a single variable of degree 5 or greater. Given both of these trends, the expectation is that, for any given symbolic expression and MATLAB operation, MATLAB is unlikely to return a symbolic solution.

For the specific case of overdetermined linear systems, MATLAB backslash, as noted by DaveP, is doing least-squares, so it's doing a QR factorization, followed by a linear solve, probably by LU decomposition. rref, on the other hand, is putting the system into reduced row echelon form.

In principle, the rref algorithm is essentially Gaussian elimination, probably augmented by good choices of pivots for some numerical stability. Divisions are done by pivots, which probably makes symbolic computation relatively straightforward (even if the resulting expressions are beyond heinous).

QR decompositions can be computed with many algorithms (modified Gram-Schmidt, Givens rotations, Householder transformations). Modified Gram-Schmidt is probably the simplest, and involves norms and divisions.

Heuristically, since rref is likely to yield simpler expressions, that is probably why rref works, but backslash fails. In either case, trying to use these algorithms for symbolic manipulation is generally not a good strategy because these algorithms were designed primarily for numerical computation, not to grind through symbolic expressions. Could you use them for symbolic manipulation? Sure. Is it a good idea? Probably not.

• Add to this the issue that many (most?) numerical methods involve testing some criteria to determine the next step (e.g. choosing the largest value for pivoting in Gaussian elimination). When the terms are symbolic there is no way to know the outcome of these tests (which element to pivot on). Commented Mar 20, 2015 at 0:14
• "Householder transformations and Givens rotations both require some trig to compute angles" -- no, just square roots, exactly like MGS 1 2. Commented Mar 20, 2015 at 23:40
• Yes, the "trig functions" could be expressed using fractions and square roots via right triangle definitions. Commented Mar 21, 2015 at 20:37