In: Computer Science
Use a python code to solve
Use Newton interpolation to find the unique polynomial p2(x) of degree 2 or less, that agrees with the following data: p2(0) = 1, p2(2) = 5, p2(4) = 17.
Explanation of the given question and evaluation:
(Python code attached below)
P2(0)=1
P2(2)=5
P2(4)=17
| X | Y |  Y | 
 2Y | 
| 0 | 1 | 
 4  | 
|
| 2 | 5 | 8 | |
| 4 | 17 | 
 12  | 
Using Newtons Intepretation formula
r= x-x0/h
here x0=0
h=degree=2
therefore r=x/2;
F(x)=Y0 + r
Y0+
r(r-1)/2
2Y
F(x)=1+ x/2*4 +(x/2*(x/2-1)/2 )*8
F(x)=1+x+x2
print("Enter X and Y coordinate respectively")
X0=int(input())
Y0=int(input())
X1=int(input())
Y1=int(input())
X2=int(input())
Y2=int(input())
degree=2
deltaY0= Y1-Y0
deltaY1= Y2-Y1
deltasqY=deltaY1-deltaY0
r="x"
rfrac=2
numpt2eq=int(deltaY0/rfrac)
numpt3eq=int(deltasqY/(degree*rfrac*rfrac))
numpt1eq=str(Y0)
result= numpt1eq+"+"+str(numpt2eq-numpt3eq)+r+"+"+str(numpt3eq)+r+"^2"
print("the equation is :",result)
