#ex A.1 from numpy import * #a def sequence_a(N): index_set = range(N+1) a = zeros(len(index_set)) for n in index_set: a[n] = (7+1.0/(n+1))/(3-1.0/(n+1)**2) return a #print(sequence_a(100)) #print(7.0/3) #b def sequence_b(N): index_set = range(N+1) D = zeros(len(index_set)) for n in index_set: D[n] = sin(2**(-n))/2**(-n) return D #print(sequence_b(100)[-1]) #c def D(f,x,N): index_set = range(N+1) D = zeros(len(index_set)) for n in index_set: h = 2**(-n) print(h) D[n] = (f(x+h)-f(x))/h return D import matplotlib.pyplot as plt D1 = D(sin,0,80) plt.plot(range(80+1),D1,'o') plt.show() #d) #D1 = D(sin,pi,80) #plt.plot(range(80+1),D1,'o') #plt.show() """ e) The problem is round-off error. If h is smaller than approx 1e-16, pi + h = 0 on a computer. The numerator then becomes exactly zero (to machine precision), and the fraction is zero even if the denominator is also very small. """