12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Where p i is the population for year x i , <strong>and</strong> i =1, 2,...N. We can writethis series <strong>of</strong> equations as a matrix equation:⎛ ⎞ ⎛⎞p 1 1 x 1 x 2 1 ⎛p 2⎜ .⎝⎟. ⎠ = 1 x 2 x 2 2⎜⎝⎟ ⎝ c ⎞0c 1⎠ .. ⎠c 2p N 1 x N x 2 NOr, defining matrices,P = X · C .In matlab the X matrix is calculated as follows:>> X = [ones(size(year)) year year.^2]X =1 1788 31969441 1790 3204100...1 1993 39720491 1994 39760361 1995 3980025The backslash operator solves the equation for the coefficient matrix C:>> C = X\PC =1.0e+09 *2.0067-0.00220.0000The third coefficient is not really zero; it is simply too small (comparedto 2.0 × 10 9 ) to show in the default output format. We can change thisby typing:>> format long e>> CC =2.006702229622023e+09-2.201930087288049e+066.039665477603122e+02The backslash operator does its best to solve a system <strong>of</strong> linear equationsusing Gaussian elimination or least-squares algorithms, depending onwhether the system is exact, or over- or under-determined. We canc○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!