3. Suppose you are to make a table of values of log(x); 1/2 <= x <= 3/2, on an equally space mesh of
width 1/(N + 1), for some positive integer N. Assume that polynomial interpolation will be applied
to the table, and that the maximum error in interpolation is to be at most 10^-6. What value of N
should you choose? To answer this question, write a computer program to
determine the interpolating polynomial p(x) for arbitrary values of the number of interpolation
points evaluate the error in the interpolation at arbitrary points x E [1/2; 3/2]
plot the error log(x) - p(x) as a function of x
determine the maximum error at points xj = 1/2 + j/100(N + 1) for 0 <= j <= 100(N + 1), and
plot the logarithm of the maximum error as a function of N.
Solution:
“logx.c” is written in C language (attachment), which can be compiled with "icc -o logx logx.c". The main program uses “N” as the input parameter, e.g.“./logx 10” interpolates log(x) with N = 10 (N+2 distinct points).
The program output the Newton interpolation coefficients in the file “coeff.out”, the polynomial values for x between [1/2, 3/2] in the file “px.out”, and the error = log(x) - p(x) as a function of x in the file “error.out”. Figures are drawn with gnuplot (scripts are attached). For N =1, the error as a function of x and the comparison between log(x) and p(x) are shown below
The max error and xmax are output on the screen for each N. It is found that,
So, when N >= 8, the max error is in the magnitude of 10-6.
And log(max error) decays linearly with N as shown by the figure below, which suggests that the error drops exponentially as ~exp(-N).