Consider the following data
or rearranging...
and
In general, if the polynomial is higher order, the sums simply increase in terms as per the order of the polynomial. For example, second order polynomial produces three sums corresponding to three coefficients which look in matrix form like...
Clearly, the elements of the matrices look like
where k and j run from 0 to M, where M is the order of the polynomial.
where A is the coefficient matrix. Solving
Now, let us apply this to the data provided above for a first and second order fit..
This is read as
Plotting the results...
Which is what we saw previously.
Now, let us fit again to a second order polynomial...Now
Which is a much better fit.
As long as the function is a polynomial, this procedure works extremely well. Most software packages, including this MCAD have regression built in. In MCAD, the regression is accomplished using the built in function, regress. Using the data as above, it is executed as follows:
Obviously, the x and y are the data values used. The 2 is the order.
As you can see, there seem to be too many numbers! The first three numbers are those utilized by MCAD and can be disregarded unless more advanced work is carried out. Note that the last three numbers are identical to the fit obtained earlier.
This whole process can clearly be outlined in a very efficient fashion. Your humble professor has done this and the result is presented in as the MCAD document, GenLin.mcd. This document is reproduced below. Included in this is the calculation of the standard deviation of the coefficients and of the fit. Also included is a graphical fit for visual comparison.
To use this document, the user need only to replace the highlighted values with the data and order of fit desired.
In order to carry out this regression, the user is required to supply the number of data points, N, the order of the polynomial to be fit, Order, and the data points, x and y.
ref.. Peter C. Jurs "Computer Software Applications in Chemistry
Replace highlighted areas only with your data.
regression command
regression coefficients
Error analysis...
standard deviation of fit
standard deviations
of the coefficients
Final Equation...
Plotting data with curve fit...
In some instances, functions may appear to be non-linear, but can be manipulated into the proper form. As an example, consider the following function:
where A and B are constants to be determind.
Some representative data of T related to p is given and plotted as follows:
A cursory examination show that the relationship is clearly non-linear as plotted. However, we have a function that is purported to represent the data. We would like to fit the data to the function, however, we only have linear tools.
We can make the funcion linear, however, by simple algebraic manipulation. Taking the log of both sides and rearranging gives:
Comparison to the equation of a straight line shows that a plot of ln(P) vs. 1/T should produce a linear relationship. Carrying this out..
Now, we can carry out a curve fit. Defining new variables:
regression command
regression coefficients
Since a
or
Sometimes, functions are linear in the coefficients, but the functional forms are more complex. Consider the following example and associated data:
Note: For illustrative examples, I've selected the coefficients randomly and generated matching data accordingly.
Clearly, in order to fit this function, we would have to carry out a manipulation followed by a recalculation of data in both the x and y axes. For example, I could produce the manipulated expression:
Examining this expression shows the difficulty in this approach. There is no concerted value for the independent variable.
Clearly, the least squares approach carried out at the beginning needs to be re-expressed for this function. Although it can be done, it is difficult to obtain a generalized approach to this type of system.
MCAD, however, as many other software packages, offers a solution.
The solution to this problem is in the built in function, LINFIT. In order to execute this, one needs to define a linear function that matches the function for which a fit is desired. From above..
This is the function that I wish to fit with the linfit function
This is the linfit command given as linfit(x,y,F). It calculates the coefficient matrix, in this case, s.
The coefficients are the result of this function.
This will now build the actual function, or you can do it by hand.
The plot matches the original data to an excellent degree!
Note that if I alter the order of the
functions within the matrix, the
coefficients alter accordingly!
It is not uncommon to desire a fit to an expression that is non-linear in nature. This is, in general, a numerical problem and can be accomplished in a number of ways. One approach is to expand the desired function in a series expansion, thus producing a linear function with which the above techniques may be employed. This has the disadvantage of losing the orginal form of the expression that one may wish to keep.
FIrst is a function built in to MCAD called MINERR and the second is a widely used technique called cubic spline fitting.
A standard deviation of the fit similar to that produced in a linear regression is given as follows:
Finally, plotting the data values in comparison to the sigma values shows that the fitted values fall within the standard deviations. The upper and lower limits shown are produced by double-clicking on the plot and checking "Show Markers" on the "y-axis". Then
Use " Show Markers "
to place
on graph.
limits manually.
A cubic spline fit endeavors to fit sequential subsets of data within a given data set to cubic polynomials. The result is a fit that is extremely closely tied to the data points. This is suitable for data that is precise, but does not fit any conventional function.
Example 1: Curve fit to spectral data
This is the new function...plotting with the data points...
Here, I execute integrations of the function to find thermodynamic values.
This is a short/quick example of using titration data alng with MCAD functions in order to extract values. Here, we desire the equivalence point, which is aninflection point. Thus the first and secdon derivatives are equal to 0. We cna take the derivatives and solve for the roots.
Here, I execute the second derivative
I provide a guess value and proceed to solve for the inflection point volume.
The second derivative plot is given below...