Math 753/853 HW4 Polynomial Interpolation
(a) Write a function polyeval(c,x) that implements Horner’s method for polynomial interpolation without base points. I.e. given a vector of monomial coefficients c you want to evaluate the polynomial
using Horner’s method of nested multiplication. E.g. write the function so that it evaluates the polynomial
with this series of multiplications and additions
Your function should have inputs c and x , and it should return P(x) . Make sure the function works when x is a vector, returning a vector of values P(x) . Your function should also work equally well on all numerical types.
Warning: Note that the natural mathematical expressions for polynomials have indices that start at 0, but that Julia and many other programming languages use indices that start at 1. You’ll have to negotiate this difference when writing your Horner evaluation function
(b) Test your polyeval(c,x) function on a simple quadratic or cubic polynomial of your choice. Do this by constructing a simple polynomial function in Julia, e.g. f(x)=1+2x−3×2 , plotting a few points (x, f(x)) with dots, and then plotting the same polynomial as a smooth line using your polyeval function with inputs c=[1 2 -3] and an x vector created with linspace. Label the axes and add a legend that shows which symbol is for the datapoints and which is for polyeval.
(a). Write a function polyeval(c,b,x) that implements Horner’s method for polynomial interpolation with base points. E.g. given a vector of five coefficients c and four base points b you want to evaluate the polynomial
Your function should have inputs c, b, and x, and as in problem 1(a), it should work on vectors x of arbitrary numeric type. Typically the base points b will be the x values x1,x2,…, of the datapoints (xi,yi) used in a Newton divided difference polynomial fit.
(b) As in problem 1(b), test your polyeval(c,b,x) function graphically on the polynomial P(x)=3+(x−1)[−2+(x−2)[1+(x−3)2] .
(a) To familiarize yourself with the Newton Divided Differences algorithm, work out on paper (or in text/markdown in this notebook) the cubic interpolating polynomial for the (x,y) data points (−2,8),(0,4),(1,2),(3,−3) .
(b) Make a plot that verifies your interpolating polynomial graphically, showing the data points as dots and the interpolant as a smooth curve.
(a) Write a function newtondivdiff(x,y) that returns (c,b), the polynomial coefficients c and the base points b for the polynomial interpolant that passes through the data points (x1,y1),(x2,y2),…,(xm,ym) . The return values c and b should be arranged to pass directly into your polyeval(c,b) function from problem 2.
(b) Test your newtondivdiff(x,y) function with this series of steps
construct a quadratic or cubic polynomial, e.g. f(x)=1+2x−3×2
construct a vector xdata with three values for a quadratic, or four for a cubic, e.g. xdata = [-2 -1 1].
evaluate f at xdata to get a vector of y values ydata
compute the coefficients c and basepoints b of the polynomial interpolant using newtondivdiff(xdata, ydata)
evaluate your polynomial interpolant on a large number of x points, e.g. x = linspace(-2, 2); y = polyeval(c,b,x)
make a plot showing the datapoints xdata, ydata with dots and the smooth curve x,y with a line.
label the axes and provide a legend
The expected lifetime of an industrial fan decreases with operating temperature, according to the experimental data in this table
Estimate the expected fan lifetime at 130 degrees Farenheit using polynomial interpolation. Make a plot showing the datapoints with dots and the interpolant as a smooth curve over the range 50 to 150 weeks.
(a) Given these estimates of world human population over the last fifty years
estimate the world population in 2025 by extrapolating the polynomial interpolant.
(b) Add the current estimated world population of 7.404 billion in 2016 to the data set and give a revised estimate of 2025 population.
(c) Make a plot showing the datapoints and the two polynomial interpolants over the range 1950 to 2030. Plot the interpolant without the 2016 data in blue and with the 2016 data in red.
(d) What conclusions do you draw from the difference between the two curves?