\documentclass[12pt, letterpaper]{article}

\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{setspace}

\title{Homework 10}
\author{Menyoung Lee}
\geometry{margin=1in}
%\doublespacing

\newcommand{\<}[0]{\Leftarrow}

\begin{document}
\maketitle

\subsection*{CP9}
\begin{verbatim}
x = 2:0.2:4;
v = vander(x);
u = v(:,11-5:11);
y = sum(u');
a = (u'*u)\(u'*y')
  =1.00000017837590
   0.99999731404223
   1.00001595230769
   0.99995331974803
   1.00006726440287
   0.99996183281005
u = v(:,11-6:11);
y = sum(u');
a = (u'*u)\(u'*y')
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 2.337960e-17.
a =0.99997464146416
   1.00045741872700
   0.99660034498889
   1.01332056418028
   0.97099001879468
   1.03328584898733
   0.98428343198428
u = v(:,11-8:11);
y = sum(u');
a = (u'*u)\(u'*y')
Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 5.266425e-25.
a =1.0e+03 *
   0.00135381489493
  -0.00749502319083
   0.08956078130055
  -0.52249685205043
   1.91979951101377
  -4.46402450290450
   6.44181355670735
  -5.26420274975354
   1.86835087719298
\end{verbatim}

The coefficients can be computed to (a) 4 places (b) 1 place (c) no place.
For (c), just like example 4.5, when trying to compute 8 coefficients from the 11 points, we get garbage.
We fare slightly better, but still unsatisfactorily, for the other polynomial degrees.
As indicated by matlab, the condition number gets really big (rcond = inverse of the condition number).
So the last step, where we solve the normalized equation, is a horribly ill-conditioned problem that won't get the right answer.

\subsection*{CP1}
\begin{verbatim}
x = 1:12;
y = [6.224 6.665 6.241 5.302 5.073 5.127 4.994 5.012 5.108 5.377 5.510 6.372]*10^6;
x = (x-0.5)/12;
A = [ones(12,1) cos(2*pi*x') sin(2*pi*x') cos(4*pi*x')]
  =1.00000000000000   0.96592582628907   0.25881904510252   0.86602540378444
   1.00000000000000   0.70710678118655   0.70710678118655   0.00000000000000
   1.00000000000000   0.25881904510252   0.96592582628907  -0.86602540378444
   1.00000000000000  -0.25881904510252   0.96592582628907  -0.86602540378444
   1.00000000000000  -0.70710678118655   0.70710678118655  -0.00000000000000
   1.00000000000000  -0.96592582628907   0.25881904510252   0.86602540378444
   1.00000000000000  -0.96592582628907  -0.25881904510252   0.86602540378444
   1.00000000000000  -0.70710678118655  -0.70710678118655   0.00000000000000
   1.00000000000000  -0.25881904510252  -0.96592582628907  -0.86602540378444
   1.00000000000000   0.25881904510252  -0.96592582628907  -0.86602540378444
   1.00000000000000   0.70710678118655  -0.70710678118655  -0.00000000000000
   1.00000000000000   0.96592582628907  -0.25881904510252   0.86602540378444
c = A\y'
  =1.0e+06 *
   5.58375000000000
   0.69686216653820
   0.31298484741002
   0.09944858386791
norm((A*c)'-y)
    =7.547408574050438e+05
\end{verbatim}
The RMSE is 755 thousand barrels per day.
\subsection*{CP3}
\begin{verbatim}
x = [1960 1970 1990 2000];
y = [3039585530 3707475887 5281653820 6079603571];
A = [ones(4,1) x']
  =        1        1960
           1        1970
           1        1990
           1        2000
c = A\log(y)'
  =-12.26234902764795
   0.01740324629807
exp(-12.26234902764795+0.01740324629807*1980)-4452584592
   =-9.109867659928703e+07
\end{verbatim}
The estimation error was -91098677.
\subsection*{CP6}
\begin{verbatim}
x = 1:10;
y = [6.2 9.5 12.3 13.9 14.6 13.5 13.3 12.7 12.4 11.9];
A = [ones(10,1) x']
  =  1     1
     1     2
     1     3
     1     4
     1     5
     1     6
     1     7
     1     8
     1     9
     1    10
c = A\(log(y)-log(x))'
  =1.96319223063350
  -0.18384897401197
f =  Inline function:
     f(x) = exp(1.96319223063350)*x.*exp(-0.18384897401197*x)-4
fzero(f,0)
    =0.63068619092697
fzero(f,20)
    =19.21447694093067
\end{verbatim}
The drug concentration is within theraputic levels for 18.5838 hours.
\end{document}


