% CLASS15OCT  A few commands I used in class to show the actual
%   difference between the function  f(x) = cos(x)  and the interpolating
%   polynomial  P(x) = 1 + (cos(1)-1)x  using x_0=0, x_1=1

% plot of y=f(x) and y=P(x)
x=0:.001:1;
plot(x,cos(x),x,1+(cos(1)-1)*x)
axis([0 1 0 1])
grid on

% location where max |P(x)-f(x)| occurs, found by calculus
format long g
xc=asin(1-cos(1))           % x-location of max |P(x)-f(x)|
yc=1+(cos(1)-1)*xc-cos(xc);
abs(yc)                     % actual value of max |P(x)-f(x)|

% quick way to get max with good-enough accuracy
max(abs(1+(cos(1)-1)*x - cos(x)))


% on a *different* problem: estimate of error from LRT on f(x)=2^x
%    and x0=0.5,...,x5=3  problem
(log(2))^6*2^3*(2.5)^6/(6*5*4*3*2*1)

6*5*4*3*2*1
factorial(6)    % in class I could not think of it ...
