As a programmer, you will find an algorithm to be even better than a formula, especially if the algorithm is based on simple steps. There is one, "sequential matching," that requires no matrix algebra and no specialized mathematical procedures (like Cholesky decomposition, QR decomposition, or matrix pseudo-inversion). It is easy to code, easy to test, extensible, and reasonably efficient.
A good algorithm for this situation is derived from the idea of "matching" developed by Tukey and Mosteller, as described in my answer at "How to Normalize Regression Coefficients". For quadratic regression it involves these simple ideas:
There are three independent variables: a constant (usually set to $1$ for simplicity and easy interpretation), $x$ itself, and $x^2$. For this purpose, you compute $x^2$ once and for all and then treat it henceforth as if it had no mathematical relationship to $x$ whatsoever.
After you have fit (or "matched") a single dependent variable $y$ to a single independent variable $x$, thereby producing a formula in the form $y = \beta_{y\cdot x} x + \text{ error },$ you take the fit away from the dependent variable by subtracting the fit, writing $y - \beta_{y\cdot x} x$ for what is left over. This (the "error" term above) is the residual. As a matter of notation, let the residual after matching $y$ to $x$ be called $y_{\cdot x}.$
To fit a dependent variable $y$ to $n\ge 2$ independent variables $x_1, x_2, \ldots, x_n$, you separately match $y$ and the last $n-2$ variables to the first one, producing dependent residual $y_{\cdot x_1}$ and independent residuals $x_{2\cdot x_1}, x_{3\cdot x_1}, \ldots, x_{n\cdot x_1}.$ Now proceed recursively to fit the dependent residual to the $n-1$ independent residuals.
Provided, then, that you have a routine to match a dependent variable to a single independent variable, you can figure out the residual for any multivariate linear fitting problem with practically no more coding. If you know the residuals, you know the prediction, so at this point it's just a matter of finding the coefficients. The most direct way to proceed is to do the algebra to work out the proper combination of all the appropriate $\beta$'s. This is worked out for the case $n=2$ in the answer previously referenced. The R
code below shows it for quadratic regression. Rather than coding it in a loop over the $x_i$, I have unrolled that loop to exhibit every one of the steps that is needed, showing the basic simplicity of the algorithm. I have also avoided using any R
-specific idioms, apart from its readiness to combine two vectors (such as x
and y
) component-by-component when they are added, subtracted, multiplied, or divided.
The output of this sample program consists of the coefficients of $1$, $x$, and $x^2$, named beta.0
, beta.1
, and beta.2
, respectively, followed by the same coefficients as computed with R
's built-in regression function:
> c(beta.0, beta.1, beta.2)
[1] 18.5575094 2.1555036 -0.1092891
> coef(lm(y ~ x + I(x^2)))
(Intercept) x I(x^2)
18.5575094 2.1555036 -0.1092891
The perfect agreement attests to the correctness and precision of this sequential matching process.

#
# Data.
#
n <- 32
set.seed(17)
x <- runif(n, -5, 20)
y <- floor(30 - ((x-10)/3)^2 + rnorm(n, sd=3))
#
# Linear regression ("matching")
#
fit.ls <- function(y, x) sum(x*y) / sum(x*x) # Returns the coefficient
#
# The additional variables are a constant `one` and the squared x's.
#
one <- rep(1, length(x))
x2 <- x*x
#
# Step 1: Match everything to `one`.
#
beta.x.1 <- fit.ls(x, one)
beta.x2.1 <- fit.ls(x2, one)
beta.y.1 <- fit.ls(y, one)
#
# Compute the residuals.
x.1 <- x - one * beta.x.1
x2.1 <- x2 - one * beta.x2.1
y.1 <- y - one * beta.y.1
#
# Step 2: Match the residuals to `x`.
#
beta.x2.1.x <- fit.ls(x2.1, x.1)
beta.y.1.x <- fit.ls(y.1, x.1)
#
# Compute the residuals.
#
x2.1.x <- x2.1 - x.1 * beta.x2.1.x
y.1.x <- y.1 - x.1 * beta.y.1.x
#
# Step 3: Match the residuals to x^2.
#
beta.y.1.x.x2 <- fit.ls(y.1.x, x2.1.x)
y.1.x.x2 <- y.1.x - x2.1.x * beta.y.1.x.x2
#
# Combine the coefficients into the full formula for `y` in terms of
# `one`, `x`, and x^2.
#
beta.2 <- beta.y.1.x.x2
beta.1 <- beta.y.1.x - beta.2*beta.x2.1.x
beta.0 <- beta.y.1 - beta.y.1.x*beta.x.1 - beta.2*(beta.x2.1 - beta.x2.1.x*beta.x.1)
c(beta.0, beta.1, beta.2)
#
# Compare this to the output of `R`'s built-in multiple regression.
#
coef(lm(y ~ x + I(x^2)))
#
# Plot the results.
#
par(mfrow=c(1,1))
plot(x, y)
curve(beta.0 + beta.1*x + beta.2*x^2, lwd=2, col="Red", add=TRUE)
LINEST
function will give you the formula directly. For one independent variable, the method is described and illustrated at stats.stackexchange.com/questions/8040/…. SinceLINEST
also does multiple regression (that is, it applies to multiple independent variables), that answer works just fine in your case provided you compute a third column containing the squares ofx
and place it immediately to the right of thex
column in your spreadsheet. $\endgroup$