Graphics Programs Reference
In-Depth Information
Where p i is the population for year x i , and i =1 , 2 ,...N . We can write
this series of equations as a matrix equation:
x 1
p 1
p 2
. . .
p N
1 x 1
c 0
c 1
c 2
1 x 2
x 2
.
=
. . .
1 x N x 2 N
Or, defining matrices,
P = X
·
C .
In matlab the X matrix is calculated as follows:
>> X = [ones(size(year)) year year.^2]
X=
1
1788
3196944
1
1790
3204100
.
.
.
1
1993
3972049
1
1994
3976036
1
1995
3980025
The backslash operator solves the equation for the coeQcient matrix C :
>> C = X\P
C=
1.0e+09 *
2.0067
-0.0022
0.0000
The third coe Q cient is not really zero; it is simply too small (compared
to 2 . 0
10 9 ) to show in the default output format. We can change this
by typing:
×
>> format long e
>> C
C=
2.006702229622023e+09
-2.201930087288049e+06
6.039665477603122e+02
The backslash operator does its best to solve a system of linear equations
using Gaussian elimination or least-squares algorithms, depending on
whether the system is exact, or over- or under-determined. We can
Search WWH ::




Custom Search