Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: MA 531
Views: 42
Visibility: Unlisted (only visible to those who know the link)
#3.4.13. Calculations check #makes Sage simplify polynomials more easily sometimes R = PolynomialRing(QQ, 'x') #multiplying out the polynomials p=7*1/168*(x-2)*(x-3)*(x-4)*(x-7)+10*-1/20*x*(x-3)*(x-4)*(x-7)+20*1/12*x*(x-2)*(x-4)*(x-7)+32*(-1/24)*x*(x-2)*(x-3)*(x-7)+1*(1/420)*x*(x-2)*(x-3)*(x-4) p #part of 3.5.26 #defines 31 equally spaced test points #used m so it didn't conflict with n=10 at all n=10 f(x)=1/(1+25*x^2) points=[(-1+i*(2/n),f(-1+i*(2/n))) for i in [0,1,..,n]] m=31 #defines function f(x)=1/(1+25*(x^2)) #calculates interpolation polynomial p(x) p(x)=Newton_Interpolation(x) xvalues=[-1+i*(2/m) for i in [0,1,..,m]] #evaluates f and p for 31 points #notice that xvalues[i] selects the ith entry in the xvalues array (which is just like a row matrix with m columns) ftruevalues=[f(xvalues[i]) for i in [0,1,..,m]] pestvalues=[p(xvalues[i]) for i in [0,1,..,m]] #calculates error between f and p, outputs maximum error of the 31 values (using 11 evenly spaced nodes to build p). error=[abs(ftruevalues[i]-pestvalues[i]).n(20) for i in [0,1,..,m]] error max_error=max(error[i] for i in [0,1,..,m]) max_error