Appendix: How To Use The Excel Solver To Fit Data To Any Equation
Appendix: How To Use The Excel Solver To Fit Data To Any Equation
A very handy, but not very well known, feature of Excel is the “Solver”. It is essentially a glorified
version of “Goal seek”. The differences are that you can manipulate more than 1 cell value to
achieve your target value, and you can also perform minimisations and maximisations.
Amongst other things, the Solver can be used for “custom” curve fitting, using the least squares
method. You may already came across the standard curve fitting facility of Excel. However, this
has only a limited range of fitting functions. In this example (taken from the Part A Computing
labs) we will look at fitting data to an exponential increase (as occurs in e.g. the concentration of
a reaction product). You will find that you cannot do this using the standard Excel “exponential”
curve fit. If the equation you want to fit to your experimental data is different to this then don’t
worry – the equation can be easily modified later (once you have seen how the solver works).
(vii) Go to Solver option under the Data menu . If you cannot see you need to import the
feature under Add-ins.
In Excel 2007 click the large Microsoft Office button on left hand side of menu, then click
“Excel Options”, then click “Add-Ins”, then make sure “Excel Add-ins” is selected under
“manage”, then click “Go”, then click “Solver Add-in” followed by “OK”.
In Excel 2010 go to the File menu and select Options instead of clicking the Microsoft Office
button (which doesn’t exist).
For other versions of Excel please refer to the on-line help and you should find it.
(viii) Open the solver. You should make the following settings:
(a) “Set target” should be the sum of squares value (e.g. D23 in the spreadsheet
overleaf)
(b) “Equal to” should be set to “Min” (as we are trying to minimise this value)
(c) “By changing cells” should be the cells containing the constants A,B, and C
(i.e. B3:B5 in the spreadsheet overleaf).
(d) We do not have any constraints on what values A, B, or C can take so just
click “Solve”.
(e) This should produce your fit. If you are happy with the values then click “Keep
Solver Solution” and then “OK”. You have the option of producing some
reports but you don’t generally need these.
(f) Make a plot of your experimental data and fitted equation. The data should be
plotted as symbols only (with no line) and the fitted eqution as a line only (with
no symbols).
This method is general and can be used to fit data to any equation – just type in the
relevant equation in step (iv). The above example has 3 fit parameters, but if you need
to use more or fewer fit constants then change the number you use in step (i) and (viii
c) . (N.B. If fitting more than 3 fit constants, it may not always find the best fit – it can
depend on what initial guesses you provide in step (ii)).