Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Code. Newton Interpolation Method. I am trying to graph the polynomail by

ID: 3826995 • Letter: P

Question

Python Code. Newton Interpolation Method. I am trying to graph the polynomail by interpolating points given. I am missing some steps to print the polynomial and graph it against the orginal points.

Newton Interpolation Method (x) In (25 def F2 (i,j xe, ye) return (ye[ i 1-ye[ j 1) (xe[ ij-xe[ j 1) def F3 (i, j, k, xe ye) return (F2 (i,j, xe, ye) k,xe, ye) /(xe[i]-xe[k]) def F4 (i, j, k, l,xe, ye) return k, xe,ye (j,k,l,xe ye)) (xe [ij-xe[l]) xe C-2 3, 6, 81; ye (-4, 1, -2, 5); cl yee 01 c2 F2 (1 xe, ye) c3 F3 2,1,0 xe, ye) C4 F4 3, 2,1,0 ye) def newt (x) return cl c2 (x-xe[ 0]) c3* (x-xe 01)*(x-xe( 1]) c4* (x-xe(01)* (x-xe (11) n 28 plt plot (C-2,3, 6, 8 (-4,1 2,5 ro) plt.axis(C-5, 10 -5, 10 x1

Explanation / Answer

For the above program, changes are made in the plot.py code to print the polynomial and graph it against the original points as below:-

def F2(i,j,xe,ye);
   return((ye[i]-ye(j))/(xe[i]-xe(j)))
def F3(i,j,k,xe,ye);
   return (F2(i,j,xe,ye)-F2(j,k,xe,ye)/(xe[i]-xe[k])
def F4(i,j,k,l,xe,ye);
   return (F3(i,j,k,xe,ye)-F2(j,k,xe,ye)/(xe[i]-xe[l])

  
xe=[-2,3,6,8];
ye=[-4,1,-2,5];
c1=ye[0];
c2=F2(1,0,xe,ye);
c3=F3(2,1,0,xe,ye)
c4=F4(3,2,1,0,xe,ye)

def newt(x);
   return c1+c2*(x-xe(0))+c3*(x-xe(0))*(x-xe(1))+c4*(x-xe(0))*(x-xe(1))

#plot.py   :-
---------------
from newt import newt
from nest import nest
from pylab import plot, show
xdata=[-2,3,6,8];
ydata=[-4,1,-2,5];
plot(xdata,ydata,'ro')
interpolant = newt(xdata)
x = linspace(-5,10,-5,10,endpoint=True)
y = nest(interpolant,x,xdata)
plot(x,y,'b')
show()