Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import log
- def tailor(x):
- a_n=float(-1.0*pow(x,2))/4.0
- n=1
- sum=a_n
- eps = pow(10,-6)
- '''
- an+1=an*qn
- '''
- while True:
- q_n = (-1.0*x*x*n)/((n+1.0) * (2.0*n+1.0) * (2.0*n+2.0))
- a_n1=a_n*q_n
- r=abs(a_n1-a_n)
- sum+=a_n1
- a_n=a_n1
- n+=1
- if r<eps:
- break
- return sum
- def fun(x):
- return 0.577215+log(x)+tailor(x)
- def lagran(x, fi, xi):
- sum=0
- for i in range(len(xi)):
- p=1
- for j in range(len(xi)):
- if i != j:
- p*=(x-xi[j])/(xi[i]-xi[j])
- sum+=fi[i]*p
- return sum
- import numpy as np
- print("Tailor")
- a=0.4
- b=4.0
- print("max esp")
- for l in np.arange(25,300,10):
- n=l
- h=b/n
- i=a
- f=[]
- x=[]
- # print("x\tf(x)")
- while i<=b+h:
- x.append(i)
- f.append(fun(i))
- i+=h
- # for i,j in zip(f,x):
- # print(f"{j:.1f}\t{i}")
- # print("\nLagrang")
- # print("x\tL(x)\t\t\tf(x)\t\t\tesp")
- e_max=0
- j=a+0.1
- while j<=b:
- L=lagran(j,f,x)
- fu=fun(j)
- e=abs(fu-L)
- if e>e_max:
- e_max=e
- # print(f"{j:.1f}\t{L}\t{fu}\t{e}")
- j+=h
- print(f"{n}\t{e_max}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement