Question: need number 2 coding language is python 1 # 1. Add comments for every line 2 * 2. Add a function that takes a coefficients
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 an updated coefficients table 4 * 3. Add a function that takes x,y and a polynomial and plots the points and the polynomial together with X-axis ranging from min(x)-1 to max(x)+1 3 11 8 import numpy as np 9 import matplot lib.pyplot as plt 10 poly = np.polynomial.polynomial 12 Hits a function and it has two arguments x, y are an array of point and are just coefficents 13 def findcoefs(x,y): #sets to the size of x (which is also the same size as y) 15 n = len(x) * create an n by n array of zeros #makes an array of zeros coefs = np. zeros((n,n)) 14 16 17 18 19 20 21 22 23 for j in range(n): coefs (3,0) = y for i in rangel1.n): for j in range(n-1): coefslj,i] = (coets [j+1,1-1) - coefslj,1-1])/(x[j+i]- [j]) return coefs 25 26 27 28 def findpoly(coefs): 29 p = poly. Polynomial (coefs[0,0]]) 38 pterm = poly. Polynomial([1]) 31 for i in rangel1.coefs.shape [0]): pterm = pterm poly. Polynomial(1-x[1-11,1]) 33 D = p + coefs[0,il-pterm return p 36 x = (0,2,31 37 y = 11,2,4] 38 39 coefs = findcoefs(x,y) 40 print(coefs) 41 p = findpoly(coefs) 42 print(p) 43 44 coefs2 = poly.polyfit(x, y, ten(x)-1) 45 p2 = poly. Polynomial(coefs2) 46 print(p2) 47 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 an updated coefficients table 4 * 3. Add a function that takes x,y and a polynomial and plots the points and the polynomial together with X-axis ranging from min(x)-1 to max(x)+1 3 11 8 import numpy as np 9 import matplot lib.pyplot as plt 10 poly = np.polynomial.polynomial 12 Hits a function and it has two arguments x, y are an array of point and are just coefficents 13 def findcoefs(x,y): #sets to the size of x (which is also the same size as y) 15 n = len(x) * create an n by n array of zeros #makes an array of zeros coefs = np. zeros((n,n)) 14 16 17 18 19 20 21 22 23 for j in range(n): coefs (3,0) = y for i in rangel1.n): for j in range(n-1): coefslj,i] = (coets [j+1,1-1) - coefslj,1-1])/(x[j+i]- [j]) return coefs 25 26 27 28 def findpoly(coefs): 29 p = poly. Polynomial (coefs[0,0]]) 38 pterm = poly. Polynomial([1]) 31 for i in rangel1.coefs.shape [0]): pterm = pterm poly. Polynomial(1-x[1-11,1]) 33 D = p + coefs[0,il-pterm return p 36 x = (0,2,31 37 y = 11,2,4] 38 39 coefs = findcoefs(x,y) 40 print(coefs) 41 p = findpoly(coefs) 42 print(p) 43 44 coefs2 = poly.polyfit(x, y, ten(x)-1) 45 p2 = poly. Polynomial(coefs2) 46 print(p2) 47
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
