% PROB5ONA6  Solve problem 5 on Assignment #6.

x = [0.1, 0.2, 0.3];
y = [-0.29004996, -0.56079734, -0.81401972];

format long
y018 = ncspline(x,y,0.18)
f = @(x) x.^2 .* cos(x) - 3 * x;
f(0.18)
abs(y018 - f(0.18))  % actual error  |S0(0.18) - f(0.18)|

% I filled in the coefficients of these polynomials after running the above the
%   first time to get b,c,d
S0 = @(x) -0.29004996 - 2.7512863 * (x-0.1) + 4.38125 * (x-0.1)^3;
dS0dx = @(x) -2.7512863 + 3 * 4.38125 * (x-0.1)^2;
dfdx = @(x) 2*x.*cos(x) - x.^2 * sin(x) - 3;

dS0dx(0.18)
dfdx(0.18)
abs(dS0dx(0.18) - dfdx(0.18))  % actual error  |S0'(0.18) - f'(0.18)|
