Least Squares Solver
Enter A and b or paste data points to get the least-squares solution from AᵀAx = Aᵀb, the residual table, SSE, RMSE, R² and a plot of the fit.
Läuft in Ihrem Browser. Ihre Dateien verlassen nie Ihr Gerät. So prüfen Sie es
…
So geht's
- 1Choose a mode
Pick line, polynomial, plane or matrix Ax = b.
- 2Enter the data
Paste points, import a CSV, or type A and b.
- 3Set the model
Choose the degree and whether the fit passes through the origin.
- 4Read the fit
See the equation, SSE, RMSE, R² and the plot.
- 5Check the algebra
Study AᵀA, Aᵀb, the reduction steps and the Aᵀr check.
- 6Export
Download the residual table as CSV or print the report.
Über dieses Tool
When there are more equations than unknowns, Ax = b usually has no exact solution. Least squares picks the x that makes the error vector r = b − Ax as short as possible, which is the same as projecting b onto the column space of A. The answer satisfies the normal equations AᵀAx = Aᵀb, and this is the route most linear algebra courses teach before moving to QR. Curve fitting is the everyday use: a straight line through measured points is the least-squares solution for a matrix whose columns are a column of ones and the x values. This solver works both ways. In matrix mode you type A and b. In data mode you paste x and y pairs, or x, y and z triples for a plane, or import a CSV file, and the tool builds the design matrix for a line, a polynomial up to degree six, or a plane, with an option to force the fit through the origin. It forms AᵀA and Aᵀb in exact fractions, row-reduces the normal equations with every step shown, and writes the fitted equation. A residual table lists observed, fitted and residual values, and the tool reports SSE, RMSE, R² and the check that Aᵀr is the zero vector. Line and polynomial fits are drawn as an SVG plot with the residuals marked.
Why the normal equations work
The error b − Ax is smallest when it is perpendicular to every column of A, which means Aᵀ(b − Ax) = 0. Rearranged, that is AᵀAx = Aᵀb. The tool prints both sides, solves them by row reduction, and then confirms the perpendicularity by computing Aᵀr for the final residual.
Dependent columns
If the columns of A are dependent, AᵀA is singular and many x give the same smallest error. The tool then reports the minimum-norm solution, the one with no component in the null space, and warns you. This is the answer the pseudoinverse gives.
Measures of fit
SSE is the sum of squared residuals. RMSE is the square root of SSE divided by the number of points, in the units of y. R² is 1 − SSE/SST, where SST is the total squared deviation from the mean of y; it appears only when the model has a constant term, because without one it can be misleading.
Worked example
Choose Fit a line and enter the points (0, 6), (1, 0), (2, 0) and (3, 0). The normal equations have AᵀA with rows 4 6 and 6 14 and Aᵀb = (6, 0). Solving gives the line y = 21/5 − (9/5)x, that is y = 4.2 − 1.8x. The residuals are 9/5, −12/5, −3/5 and 6/5, so SSE = 54/5 = 10.8, RMSE ≈ 1.6432 and R² = 3/5 = 0.6. Aᵀr is (0, 0), confirming the residual is orthogonal to both columns. The height and weight sample in the examples gives y = 0.772x − 66.62 with R² ≈ 0.9946.
Limits
Up to 200 data points and 12 columns are accepted. The normal equations square the condition number, so for nearly dependent columns a QR or SVD method is more stable in floating point; here the exact arithmetic avoids that rounding problem, but very large inputs can make fractions long. This tool fits models; it does not give confidence intervals or p-values.
Rechenbeispiel
Points (0, 6), (1, 0), (2, 0), (3, 0): y = 21/5 − (9/5)x, residuals 9/5, −12/5, −3/5, 6/5, SSE 54/5, R² 3/5.
Kurzinfos
- Kategorie: Mathe & Wissenschaft
- Läuft in Ihrem Browser, ohne Anmeldung, ohne Upload.
- Ihre Eingaben bleiben auf Ihrem Gerät.
- Auf Englisch verfügbar.
- Inhalt zuletzt geprüft:
- Offizielle Quelle: Least squares by the normal equations (Strang, Introduction to Linear Algebra, section 4.3)
Häufig gestellte Fragen
What does least squares minimize?
The sum of the squared residuals, |b − Ax|². Squaring treats points above and below the line alike and gives a unique answer that the normal equations find directly.
How do I fit a straight line to data?
Choose Fit a line and paste x and y values, one pair per line. A header row is fine. The tool builds the design matrix with a column of ones and a column of x values.
Can I fit a parabola or cubic?
Choose Polynomial and set the degree from 1 to 6. You need more points than the degree; with exactly degree + 1 points the curve passes through all of them.
What is the difference between SSE, RMSE and R²?
SSE is the total squared error. RMSE is a typical error size in the units of y. R² is the share of the variation in y explained by the model, between 0 and 1 for models with a constant.
What if AᵀA is singular?
Then the columns of A are dependent. The tool still answers, choosing the minimum-norm solution, and labels it so you know the fit is not unique.
Can I import a spreadsheet?
Export your sheet as CSV and use Import CSV or text. Columns separated by commas, tabs, spaces or semicolons all work, and the first line may be a header.
