Data:
Year |
Time Variable t= year-1970 |
Population y |
Year |
Time Variable t= year-1970 |
Population y |
1971 |
1 |
33815 |
1986 |
16 |
34520 |
1972 |
2 |
33981 |
1987 |
17 |
34507 |
1973 |
3 |
34004 |
1988 |
18 |
34509 |
1974 |
4 |
34165 |
1989 |
19 |
34521 |
1975 |
5 |
34212 |
1990 |
20 |
34513 |
1976 |
6 |
34217 |
1991 |
21st |
34515 |
1977 |
7 |
34344 |
1992 |
22 |
34517 |
1978 |
8 |
34458 |
1993 |
23 |
34519 |
1979 |
9 |
34498 |
1994 |
24 |
34519 |
1980 |
10 |
34476 |
1995 |
25 |
34521 |
1981 |
11 |
34483 |
1996 |
26 |
34521 |
1982 |
12 |
34488 |
1997 |
27 |
34523 |
1983 |
13 |
34513 |
1998 |
28 |
34525 |
1984 |
14 |
34497 |
1999 |
29 |
34525 |
1985 |
15 |
34511 |
2000 |
30 |
34527 |
The basic forms of the logistic model are:
Y=1/(A+b*exp (-T))
So make y ' =1/y; X ' =exp (-t) strong curves into linear models
Y ' =a+b*x '
Matlab code to analyze and fit the calculation:
Code one: (intentionally in this way when the data is low, enter data directly into the code)
Clear
CLC
% Read population data (1971-2000)
y=[33815 33981 34004 34165 34212 34327 34344 34458 34498 34476 34483 34488 34513 34497 34511 34520 34507 34509 34521 34513 34515 34517 34519 34519 34521 34521 34523 34525 34525 34527]
% Read time variable data (t= year -1970)
t=[1 2 3 4 5 6 7 8 9 m ( 20)
The linearization of
the treatment for t = 1:30, the
x (t) =exp (-T);
Y (t) =1/y (t);
End
%, and output regression coefficient B, that is to calculate the value of a and B in the regression equation y ' =a+bx '
c=zeros (30,1) +1;
The x=[c,x '];% equals 30 equations that solve the values of A and B.
B=INV (X ' *x) *x ' *y '
for i=1:30,
% compute regression fitting value
z (i) =b (1,1) +b (2,1) *x (i);
% calculates the deviation
s (i) =y (i)-sum (y)/30;
% calculation Error
W (i) =z (i)-Y (i)
; End
% calculates the deviation squared and S
s=s*s ';
% regression error squared and Q
q=w*w ';
% calculates regression squared and U
u=s-q;
% computed, and output F-test value
f=28*u/q
% to calculate the fitting value of nonlinear regression model for
j=1:30,
Y (j) =1/(B (1,1) +b (2,1) *exp (-j));
End
% output fitting curve of nonlinear regression model (logisic curve)
plot (t,y, ' r* ')
Fitting Graphics:
Improved code (reads data from Excel when there is more data):
Clear
CLC
y=xlsread (' D:\sun1.xlsx ', 1, ' b1:b30 ');% read Data
y=y ';
T=xlsread (' D:\sun1.xlsx ', 1, ' a1:a30 ');% read Data
t=t ';
For t=1:30,
x (t) =exp (-T);
Y (t) =1/y (t);
End
C=zeros (30,1) +1;
X=[c,x '];
B=INV (x ' *x) *x ' *y '%b=inv (x ' *x) *x ' *y '
for i=1:30,
z (i) =b (1,1) +b (2,1) *x (i);
S (i) =y (i)-sum (y)/30;
W (i) =z (i)-Y (i);
End
s=s*s ';
Q=w*w ';
U=s-q;
f=28*u/q
for j=1:30,
Y (j) =1/(B (1,1) +b (2,1) *exp (-j));
End
Plot (t,y)
Fitting curve Graph:
Output results:
Regression coefficient b and f test value:
B =
1.0E-04 *
0.2902
0.0182
F =
47.8774