Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Partie 1
- #Question 4
- def methodeNewton(a,epsilon):
- x=a+1
- While abs((x**2)-a)>=epsilon:
- x=x-(((x**2)-a)/(2*x))
- return x
- #Partie 2.1
- #Question 3
- def derive(P):
- Q=[]
- n=len(P)
- for i in range(1,n):
- Q.append(i*P[i]) #on ajoute un à un les coefficient de Q
- return Q
- #Question 4
- def primitive(P):
- n=len(P)
- Q=[1]
- for i in range(1,n):
- Q.append(P[i]*(1/(i+1)))
- return Q
- #Question 5
- def addition(P,Q):
- S=[] # S=P+Q
- n=len(P)
- assert len(P)==len(Q) #on vérifie la condition que doivent vériier les deux polynômes
- for i in range(n):
- S.append(P[i]+Q[i])
- return S
- #Question 6
- def addition_v2(P,Q):
- S=[]
- n=len(P)
- m=len(Q)
- R=[]
- R[0] for k in range(abs(m-n))
- if max(m,n)=m:
- P=P+R
- else Q=Q+R
- for i in range (max(n,m)):
- S.append(P[i]+Q[i])
- While S[max(n,m)]=0
- S;pop()
- Return S
- #Partie 2.2
- #Question 3
- def evalue_naive(P,x):
- n=len(P)
- A=P[0]
- X=1
- for i in range(1,n):
- X*=x #on utilise une variable X qui nous permet d'élever x au degré qui correspond à chaque i
- A+=P[i]*X
- return A
- #Partie 2.3
- #Question 1
- def evalue_rapide(P,x):
- n=len(P)
- A=0
- for i in range(n):
- A+=P[i]*(x**)
- return A
- #Partie 2.5
- #Question 3
- def evalue_horner(P,x):
- n=len(P)
- A=P[n-1]
- for k in range(0,n-1):
- A=A*x+P[n-(k+2)]
- return A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement