You are now ready to perform optimization with Solver. Since the values are squared, they can only be positive. Then the sum of all these squares is calculated. So in D2 the value is defined as = (C2-B2) ^ 2. In the third column, for each row, the original data value for Y is subtracted from the fitted equation value, and the result is squared. The standard way to do this is to calculate the sum of the squares of the differences. Next, we need a way to quantify the difference between the data and our equation. It makes sense to use markers for the original data points, since these are discrete values with noise, and use a line for the fitted equation. absolute, and references to x values must be relative.Īlthough not required, you can get a visual indication of how well the equation fits by plotting both y columns over the x values in the same XY scatter plot. Note that the coefficients must be referenced to copy the formula down the column. In this example, we will consider fitting an equation of the form ax ^ b + cx ^ d to the data shown below.Īrrange the dataset by the x-values in column A and the y-values in column B.Ĭreate 4 coefficient values (a, b, c and d) somewhere in the spreadsheet, they can be given arbitrary initial values.Ĭreate a column with matching Y values using an equation of the form ax ^ b + cx ^ d that references the coefficients you created in step 2 and the x values in column A. For more complex functions, Solver can be used to minimize least squares. Many common nonlinear functions can be linearized, which means that linear regression can be used to fit functions such as exponents. Fitting a Complex Model with the Excel Solver Add-inĮxcel has a built-in function to perform linear regression that allows you to fit a straight line across a dataset.