Question: need number 3 coding language python (code is also both photos, i couldnt include it all in one) 1 # 1. Add comments for every

need number 3 coding language python (code is also both photos, i couldnt include it all in one)
need number 3 coding language python (code is also both photos, i
couldnt include it all in one) 1 # 1. Add comments for

1 # 1. Add comments for every line 2 # 2. Add a function that takes a coefficients table and a new point (xi, yi) and returns 3# an updated coefficients table 4 #3. Add a function that takes x,y and a polynomial and plots the points and the polynomial together 5 with X-axis ranging from min(x)-1 to max(x)+1 15 16 17 8 import numpy as np 9 import matplottib.pyplot as plt 10 poly = np.polynomial.polynomial 11 12 #its a function and it has two arguments x, y are an array of point and are just coefficents 13 def findcoefs(x,y): 14 #sets to the size of x (which is also the same size as y) n = len(x) # create an n by n array of zeros #makes an array of zeros 18 coefs = np.zeros((n,n)) 19 20 21 for j in range(n): 22 coefs(7,0) = y01 23 for i in range(1,n): for j in range(n - 1): coefslj,i] = (coefs [j+1, 1-11 - coefslj, 1-11)/(x[j+1)-x[j]) return coefs 27 29 28 def findpoly(coefs): p = poly. Polynomial Icoefs [0,0]]) 30 pterm = poly. Polynomial([1]) 31 for i in range(1, coefs.shape [0]): 32 pterm = pterm poly.Polynomial((-x[i-1], 1)) 33 P= P + coefs [0,1]*pterm 34 return p 35 36 x = (0,2,3) 37 y = 11,2,4] 39 coefs = findcoefs(x,y) 40 print(coefs) 41 p = findpoly(coefs) 42 print (p) 43 44 coefs2 = poly.polyfit(x, y, len(x)-1) 45 p2 - poly. Polynomial(coefs2) 46 print(p2) 47 38 1 # 1. Add comments for every line 2 # 2. Add a function that takes a coefficients table and a new point (xi, yi) and returns 3# an updated coefficients table 4 #3. Add a function that takes x,y and a polynomial and plots the points and the polynomial together 5 with X-axis ranging from min(x)-1 to max(x)+1 15 16 17 8 import numpy as np 9 import matplottib.pyplot as plt 10 poly = np.polynomial.polynomial 11 12 #its a function and it has two arguments x, y are an array of point and are just coefficents 13 def findcoefs(x,y): 14 #sets to the size of x (which is also the same size as y) n = len(x) # create an n by n array of zeros #makes an array of zeros 18 coefs = np.zeros((n,n)) 19 20 21 for j in range(n): 22 coefs(7,0) = y01 23 for i in range(1,n): for j in range(n - 1): coefslj,i] = (coefs [j+1, 1-11 - coefslj, 1-11)/(x[j+1)-x[j]) return coefs 27 29 28 def findpoly(coefs): p = poly. Polynomial Icoefs [0,0]]) 30 pterm = poly. Polynomial([1]) 31 for i in range(1, coefs.shape [0]): 32 pterm = pterm poly.Polynomial((-x[i-1], 1)) 33 P= P + coefs [0,1]*pterm 34 return p 35 36 x = (0,2,3) 37 y = 11,2,4] 39 coefs = findcoefs(x,y) 40 print(coefs) 41 p = findpoly(coefs) 42 print (p) 43 44 coefs2 = poly.polyfit(x, y, len(x)-1) 45 p2 - poly. Polynomial(coefs2) 46 print(p2) 47 38

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!