Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168747
Image: ubuntu2004
#8a)
s(i,n) = -5 + (10*i)/n f(x) = 1/(1+x^2) var('x') def L(i,n): prod = 1 for j in range(n): if j != i: prod = prod*((x - s(j,n)) / (s(i,n) - s(j,n))) return prod; def p(n): sum = 0; for i in range(n): sum = sum + f(s(i,n))*L(i,n) return sum
n=20 plot(p(n),(-4,4),color="green") + plot(f(x),(-4,4),color="red") #show(p(n))
n=30 plot(p(n),(-4,4),color="green") + plot(f(x),(-4,4),color="red") #show(p(n))
#8b)
T(i,n) = cos(((2*i + 1)/(n+1))*(pi/2)) s(i,n) = (1/2)*((5 + 5)*T(i,n) -5 + 5) f(x) = 1/(1+x^2) var('x') def L(i,n): prod = 1 for j in range(n): if j != i: prod = prod*((x - s(j,n)) / (s(i,n) - s(j,n))) return prod; def p(n): sum = 0; for i in range(n): sum = sum + f(s(i,n))*L(i,n) return sum
n=20 plot(p(n),(-4,4),color="green") + plot(f(x),(-4,4),color="red")
n=30 plot(p(n),(-4,4),color="green") + plot(f(x),(-4,4),color="red")
#9b)
s(i,n) = (pi*i)/n f(x) = cos(x) def L(i,n): prod = 1 for j in range(n): if j != i: prod = prod*((x - s(j,n)) / (s(i,n) - s(j,n))) return prod; def p(n): sum = 0; for i in range(n): sum = sum + f(s(i,n))*L(i,n) return sum
eps = 10^-6 for n in range (3,10): diff(x) = f(x) - p(n) max = diff.find_maximum_on_interval(0,pi) if(max[0] < eps): print n
8 9
#9c)
T(i,n) = cos(((2*i + 1)/(n+1))*(pi/2)) s(i,n) = (1/2)*(pi*T(i,n) + pi) f(x) = cos(x) var('x') def L(i,n): prod = 1 for j in range(n): if j != i: prod = prod*((x - s(j,n)) / (s(i,n) - s(j,n))) return prod; def p(n): sum = 0; for i in range(n): sum = sum + f(s(i,n))*L(i,n) return sum
eps = 10^-6 for n in range (3,10): diff(x) = f(x) - p(n) max = diff.find_maximum_on_interval(0,pi) if(max[0] < eps): print n
8 9