Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

For more details contact:  clement@auburn.

edu 

Tutorial Problem for using EXCEL Solver to fit experimental data to a model
Developed by: Dr Prabhakar Clement, Department of Civil Engineering, Auburn University.
The solver option available in EXCEL is a powerful optimization tool. In this tutorial, I will show how
you can use it to for regression (curve fitting) applications. The first step is to select Options under File
menu and go to “Add Ins” and include “Solver Add-Ins” tools. Then click on the “Data” tab and you
should see and option called Solver option in EXCEL. See below for details.

In this exercise we will use the solver option to fit a nonlinear equation to an experimental dataset. The
problem involves understanding how toxic metals such as arsenic when discharged in the groundwater
would absorb and contaminate soils. To understand this, environmental engineers typically run lab
experiments where mix the contaminant in water and let the soil “soak” in the solution for a long time
(long enough to reach equilibrium) and then analyze contaminant concentrations in the water phase
(designate as C) and in the soil phase ( designated as S). We do this many, many times by soaking the
soil in water containing various levels of contaminants. A typical data set collected from such an
experiment is given below. Typical units used are: water concentration c in mg/Liter of water and soil
concentration S in mg/mg of soil. Now if we plot the values of C (x axis) vs. S (y-axis) we get a graph
which is provides useful picture that shows how toxic contaminated water would eventually soak into soil
pores and contaminate soil. Note, this process can happen (and happens all the time) in any neighborhood
where someone dumps used motor oil, waste coolant or even excess amount of fertilizer in the backyard!
The graph shown below provides excellent visual information to assess how the contaminant would
partition from water and pollute soils.


 
For more details contact:  clement@auburn.edu 

While the above analysis useful, the problem is that the experimental data are always bit “random” due to
experimental errors and the curve is not clean and continuous. In addition, this experimental dataset
cannot tell us what happens when water concentration goes above say 8 mg/L or at an exact value of c
where the experimental data point is not there; essentially, we do not have a continuous mathematical
function (also known as a model) to describe the dataset.

K max * c
We will propose to use the following mathematical function (or model) for this purpose: S  .
Ks  c
where Kmax and Ks are some arbitrary constants (also known as model parameters). These constants are
other constants such as slope (m) and intercept (c) that we are used to using in standard linear
mathematical function, y = mx + c. There is not much difference, except now the function is not a
straight line rather a crooky line, so we call it a “non-linear” function. The real cool thing here is that
now we have continuous relationship for water concentration (c) and soil concentration (S). If the value
of Kmax and Ks are known, I can forget about experiments and simply “predict” the value of S for any
given value of c. This sort of predictions is the true power of scientific pursuits! But the issue now is that
how can we find the values of Kmax and Ks? Well, the first option is to make an educated guess. Who
can do that? It should be done by you the engineer who knows and understands the problem (through
college education) and has the past experience (by dealing with similar situations); in fact, this is why you
will be paid more than the field or lab technicians who have no understanding of the basic problem. Let
us assume that using your experience you estimated the model parameters should be close to: Kmax = 1.5
and Ks = 1. You can now use EXCEL to check your guess values, and later use the solver to find the
exact values.

First let us program the mathematical model in EXCEL and use the guess values to make predictions for
the experimental system and compare against the actual experimental data. The figure below shows that
our model predictions (continuous line) appear to track the trend well, but the predictions do not fit the
data points well. We can quantify how bad the fit is by calculating the absolute error between the data
and model predictions, point-by-point, and later sum the total error at the end. The right most column in
the spread sheet accomplishes this and the total error is at the bottom (values is circled). The figure also
shows various EXCEL formulae used to construct the spreadsheet.


 
For more details contact:  clement@auburn.edu 

Now, a simple approach to improve the fit is to play with the guess values. Simply change one or both
values and you will see EXCEL will immediately update your plot to show the new fit. You keep
adjusting the values until you see better results in the graph or see small total error in the cell D23. This
is known as the “trial-and-error” method. While this is a legitimate way to fit a mathematical function to
a dataset, the problem is we are not sure whether the method will give the best fit.

EXCEL solver is a mathematical tool that can automatically adjust the parameters and provide the best
estimate for the model parameter the will fit the data well. EXCEL solver will do that for you. But,
before using the EXCEL solver, we will use the naming tools available in EXCEL to name the input (or
initial guess) values corresponding to Kmax and Ks with proper variable names. To do that select, cell
B2 and go to the name box (which right next to the function box designated by fx) which will display
“B2” and type over “B2” and replace B2 with “Kmax.” Do the same with B3 and replace with Ks.
Essentially, what you have accomplished here is that you have given variable names Kmax to the excel
cell B2, and name Ks to the cell B3. You can review these names by clicking on the “Formulas” tab and
then click on “Name Manager” which will show these variable names which can be managed here. Under
name manager you can delete, edit, or add new variable definitions. Ok, now you are really ready to use
the Solver, finally!

To use EXCEL solver, go under “Data” tab and then click on solver (see the first figure in this handout
for details on how to find the Solver). You should now see a screen shown below. Now do the following
(see figure below):
1) To: Select Min button (marked green circle in the picture)
2) Set Objectives: Type $D$23 for set the objective. This simply implies your objective is to
minimize the value in cell D23. Note this is the cell where you have the total absolute error (see
previous figure) so you are telling the computer to minimize total error.
3) By changing variable cells: type Kmax, Ks. You are asking the computer to vary these two
parameter s,which are named variables linked to values in the cells B2 and B3.
4) Subject to constraints: Here can set constraints on the model parameter values. You can do that
by clicking the Add button and then typing necessary information. You do not have to set
constraints for all problems, but if you are aware of some constraints it is a good idea to include
them to restrict the search space since this will help the computer to get better solutions. In this
case, we know the model parameter Ks and Kmax cannot be negative; therefore, I have included
these two constraints.
5) Select GRG Nonlinear as you solver (which is the default value)
6) The click on solve.


 
For more details contact:  clement@auburn.edu 

If you have done everything right then the solver will search and automatically find the correct results and
update the values of Kmax and Ks (in cells B2 & B3) automatically, and you should see a good-looking
fit. You should also see low total error in D23. If you need more help, please see the posted EXCEL
tutorial where I demonstrate the above example. Also, read this nice journal article where the author
discusses how this analysis can be extended to include an R2 analysis and other more statistical analysis
of the dataset. Brown, A.M (2001), A step-by-step guide to non-linear regression analysis of
experimental data using a Microsoft Excel spreadsheet, Computer Methods and Programs in Biomedicine
65, 191–200.


 

You might also like