Lecture 17 Math 221
Least Squares Application to Logistic Equations
Another common occurance in the physical world is when the rate of change of a quanity is directly proportional to the amount present. This occurs in many biological problems and in the radio-active decay of material. The above relationship can be modeled by a differential equation
If we separate variables and then integrate we obtain the relationship between the variable y and t.
or
which given ln(y)=kt +c . By raising both sides to the power e we arrive at the logistic equation.
or y =
which can be written as
. The last equation is the usual starting point of the logistic equation. Here we need to find the value b and the constant of proportionality k. We are at an advantage from our development because we can back up to the equation ln(y) = kt +c. If we set
then the equation becomes a linear relationship between
and t. l.e.
. At this point we are back to the problem that we studied in the linear least squares problem.
Example
Consider the following data set (1,5.10),(1.25,5.79),(1.50,6.53),(1.75,7.45),(2.00,8.45). We are assuming that we know the date is to fit the logistic equation of the form above. Instead of starting with the equation
we will start with tye equation ln(y)=kt +c or
.
The first thing that we need to do is to take the log of each of the dependent variables.
Let us made a table
1.00 1.25 1.50 1.75 2.00
5.10 5.79 6.53 7.45 8.46
ln(
) 1.629 1.756 1.876 2.008 2,135
We will now go to Maple to finish the problem
| > |
t:=<1.00,1.25,1.50,1.75,2.00>; |
| > |
y:=<5.10,5.79,6.53,7.45,8.46>; |
| > |
y1:=<ln(y[1]),ln(y[2]),ln(y[3]),ln(y[4]),ln(y[5])>; |
| > |
XS:=BackwardSubstitute(GaussianElimination(<ATA|ATY>)); |
The only problem we have is that we would like to write the equation as
and we have
found c instead of b. b =
so we need to take the exp(c).
We can plot the data points and then we can plot the equation. They can be plotted on the same graph. We will look at how to plot the points first.
| > |
plot([[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]],style=POINT); |
By using the semilog plot that follows we can now see the linear relationship between the data points. This is scaling the dependent values in a different manner than before . There was semi-log paper and log-log paper that you could use to do the plotting. Now most of this is done on the computer by using the commands like the following.
| > |
logplot([[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]],style=POINT); |
We now have our logistic equation for this set of data.
.
We would now like to plot the data and the graph all on one graph. The origional data not the the semi log plots. We will need to set up different plots commands so that they can be combined into one plot. I use the command like in your text and call them data_list.
| > |
data_list:=[[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]]]; |
| > |
CurvePlot:=plot(formula,tt=1..2): |
| > |
PointPlot:=plot(data_list,style=POINT): |
| > |
display([PointPlot,CurvePlot],title=`Data Points & Least Squares Curve Fit`); |
Equations With Non-Integer Exponent.
We conclude the section on Least Squares with a discussion of equation that arise from the following type of physical problems.
Suppose you know that the rate of change of a substance present varies directly with the substance and inversely with the time. i.e.
. Again, when we separate the varialbes we obtain
the following equation.
. Now integrate both side we obtain ln(y) = k ln(t) + c
or by taking the exp of both sides we obtain
or
. Again our development
leads us to the correct equation that we wish to explore before we get to the finished product.
The equation we want to find is the equation
but the one that is best suited for the least squares examination is the equation ln(y) = k ln(t) + c. By setting
and
we now have a linear equation in the new variables
which can be studied just line the linear least squares equation that we have looked at before.
| > |
t:=<2.0,3.0,3.2,3.6,4.0,4.3>; |
| > |
y:=<2.0,7.0,8.0,11.5,15.0,18.5>; |
| > |
t1:=<ln(t[1]),ln(t[2]),ln(t[3]),ln(t[4]),ln(t[5]),ln(t[6])>; |
| > |
y1:=<ln(y[1]),ln(y[2]),ln(y[3]),ln(y[4]),ln(y[5]),ln(y[6])>; |
| > |
Sol:=BackwardSubstitute(GaussianElimination(<A1TA1|A1TY1>)); |
The value of k1 is fine but the value of c1 is not the one desired. We must again take the exp of this value. b=
Our equation can then be written as
We can again plot the above data against the equation just as we did on the previous problem.
| > |
data_list1:=[[t[1],y[1]],[t[2],y[2]],[t[3],y[3]],[t[4],y[4]],[t[5],y[5]],[t[6],y[6]]]; |
![[[2.0, 2.0], [3.0, 7.0], [3.2, 8.0], [3.6, 11.5], [4.0, 15.0], [4.3, 18.5]]](images/lecture17_57.gif) |
(3.1) |
 |
(3.2) |
| > |
CurvePlot:=plot(formula,tt=1.9..4.4): |
| > |
PointPlot:=plot(data_list1,style=POINT): |
| > |
display([PointPlot,CurvePlot],title=`Data plots & Least Squares Fit`); |
When there is more than one possible fit to the data and you want to know which least squares fit is the best representation of the data. You should pick the least squares fit where the error =norm(y-ys,2) is the smallest. Here ys is the least squares fit at the t data points. Also, the least squares fit should not be extended out side the data set since you have no idea of what is happening there. Least square fit are only good in the interval of the independent variable data points. Here the independent data points are represented by t.
Exercise 2.6
Exercise 2.6.8, Exercise 2.6.10, Exercise 2.611 Problmes are due on October 31, 2008. You need to plot the data then do a combined plot of the data and the formula as in the examples above.