Advertisement
Guest User

Sabrina Khorsi MPSI4

a guest
Apr 4th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #Partie 1
  2. #Question 4
  3. def methodeNewton(a,epsilon):
  4.   x=a+1
  5.   While abs((x**2)-a)>=epsilon:
  6.     x=x-(((x**2)-a)/(2*x))
  7.   return x
  8.  
  9. #Partie 2.1
  10. #Question 3
  11. def derive(P):
  12.   Q=[]
  13.   n=len(P)
  14.   for i in range(1,n):
  15.     Q.append(i*P[i]) #on ajoute un à un les coefficient de Q  
  16.   return Q
  17.  
  18. #Question 4
  19. def primitive(P):
  20.   n=len(P)
  21.   Q=[1]
  22.   for i in range(1,n):
  23.     Q.append(P[i]*(1/(i+1)))
  24.   return Q
  25.  
  26. #Question 5
  27. def addition(P,Q):
  28.   S=[] # S=P+Q
  29.   n=len(P)
  30.   assert len(P)==len(Q) #on vérifie la condition que doivent vériier les deux polynômes
  31.   for i in range(n):
  32.     S.append(P[i]+Q[i])
  33.   return S
  34.  
  35. #Question 6
  36. def addition_v2(P,Q):
  37.   S=[]
  38.   n=len(P)
  39.   m=len(Q)
  40.   R=[]
  41.   R[0] for k in range(abs(m-n))
  42.   if max(m,n)=m:
  43.     P=P+R
  44.   else Q=Q+R
  45.   for i in range (max(n,m)):
  46.     S.append(P[i]+Q[i])
  47.   While S[max(n,m)]=0
  48.     S;pop()
  49.   Return S
  50.  
  51. #Partie 2.2
  52. #Question 3
  53. def evalue_naive(P,x):
  54.  n=len(P)
  55.  A=P[0]
  56.  X=1
  57.  for i in range(1,n):
  58.    X*=x #on utilise une variable X qui nous permet d'élever x au degré qui correspond à chaque i
  59.    A+=P[i]*X
  60.  return A
  61.  
  62. #Partie 2.3
  63. #Question 1
  64. def evalue_rapide(P,x):
  65.   n=len(P)
  66.   A=0
  67.   for i in range(n):
  68.     A+=P[i]*(x**)
  69.   return A
  70.  
  71. #Partie 2.5
  72. #Question 3
  73. def evalue_horner(P,x):
  74.   n=len(P)
  75.   A=P[n-1]
  76.   for k in range(0,n-1):
  77.     A=A*x+P[n-(k+2)]
  78.   return A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement