![]()
![]()
Lab for Nonlinear Curve Fitting
![]()
Background. The method of "linearization of the data" will is used.
Exponential curve fitting ![]()
for the data points
.
The method of "linearization of the data" will is used.
Take the logarithm of both sides: ln(y) = ln(c) + a x .
Introduce the change of variables: X = x and Y = ln(y).
The previous equation becomes Y = ln(c) + a X which is now
"linearized."
Use this change of variables on all the data points:
![]()
i.e. same abscissa's but transformed ordinates in this case.
Now you have transformed data points:
.
Use the "Fit" procedure get Y = A X + B, which must match the
form Y = ln(c) + a X so you see that
and a = A.
First load Mathematica's graphics package "Colors".
Report to be handed in.
Computer Exercises
Exercise 1. Fit the curve
to the data points (0,1.5), (1, 2.5), (2, 3.5), (3, 5.0) and (4,
7.5).
Solution. Enter the point into a two dimensional array;
Look at the transpose of this "list of lists."
The two portions of this data structure are separated by breaking off the first and second parts of the "list of lists" tr[[1]] and tr[[2]] .
We want to use the same abscissas, and take the logarithm of the ordinates. Notice that Mathematica uses Log[x] for the natural logarithm ln[x] this is because it has been taught the proper notation used in "Complex Variables" i.e. the terminology Log[x] is used in advanced mathematics.
Now glue together the transformed parts to form the pairs
.
Now use the Mathematica procedure Fit to get the least squares line in XY space. Then we shall graph this line in the transformed XY plane.
![]()
![[Graphics:cf.txtgr20.gif]](cf.txtgr20.gif)
To get back to xy space we could copy the coefficients from g or we could go looking inside Mathematica to see where they are kept. The data structure of g looks like:
So the coefficients A and B are:
Now we are in business, we use
and a = A to get the coefficients of
back in the original xy plane.
![]()
![[Graphics:cf.txtgr31.gif]](cf.txtgr31.gif)
More Background. Power
function curve fitting
for the data points
.
In a similar fashion, the method of "linearization of the data" will
is used.
Exercise 2. Fit the curve
to the data points (0,1.5), (1, 2.5), (2, 3.5), (3, 5.0) and (4,
7.5).
Solution. Enter the point into a two dimensional array;
Look at the transpose of this "list of lists."
The two portions of this data structure are separated by breaking off the first and second parts of the "list of lists" tr[[1]] and tr[[2]] .
We want to use the same abscissas, and take the logarithm of the ordinates. Notice that Mathematica uses Log[x] for the natural logarithm ln[x] this is because it has been taught the proper notation used in "Complex Variables" i.e. the terminology Log[x] is used in advanced mathematics.
Now glue together the transformed parts to form the pairs
.
Now use the Mathematica procedure Fit to get the least squares line in XY space. Then we shall graph this line in the transformed XY plane.
![]()
![[Graphics:cf.txtgr49.gif]](cf.txtgr49.gif)
To get back to xy space we could copy the coefficients from g or we could go looking inside Mathematica to see where they are kept. The data structure of g looks like:
So the coefficients A and B are:
Now we are in business, we use
and a = A to get the coefficients of
back in the original xy plane.
![]()
![[Graphics:cf.txtgr60.gif]](cf.txtgr60.gif)
Exercise 3. Often times a
scientist must decide which formula "fits" the data best.
i. Find both the "exponential
fit" and "power fit" for the data points: (1, 2), (2, 4), (3, 8), (4,
13), (5, 21).
ii. Discuss how this was
accomplished and what transformations were used in the process.
iii. Determine which curve fits
the data best.
3 (a). Fit the curve
to the data points: (1, 2), (2, 4), (3, 8), (4, 13), (5, 21)
Solution. Enter the point into a two dimensional array;
Find the logarithm of the ordinates and form list of transformed points.
Compute the coefficients of the linear system and get the
coefficients A and B,
and compute the coefficients a and c and the exponential fit.
![]()
![[Graphics:cf.txtgr69.gif]](cf.txtgr69.gif)
3 (b). Fit the curve
to the data points: (1, 2), (2, 4), (3, 8), (4, 13), (5, 21).
Solution. Enter the point into a two dimensional array;
Find the logarithm of the ordinates and form list of transformed points.
Compute the coefficients of the linear system and get the coefficients A and B, and compute the coefficients a and c and the power fit.
![]()
![[Graphics:cf.txtgr78.gif]](cf.txtgr78.gif)
3 (c). Determine which "curve
fit"
or
is the better fit to the data points:
(1, 2), (2, 4), (3, 8), (4, 13), (5, 21).
First, consider
and the sum of the squares of the residuals ![]()
Second, consider
and the sum of the squares of the residuals ![]()
It appears that the fit
is best.
![]()
![]()
(c) John H. Mathews, 1998