fiche2_suites_exo7.py

Created by frederic-junier

Created on September 18, 2019

447 Bytes

suiteUV(a, b, n) retourne les termes de rang n de la suite définie par u(0)=a, v(0)=b, u(n+1)=(u(n)+v(n))/2 et v(n+1)=sqrt((u(n)2+v(n)2)/2)


from math import sqrt

def suiteUVFausse(a, b, n):
  u = a 
  v = b
  for k in range(n):
    u = (u + v) / 2
    v = sqrt((u ** 2 + v ** 2)/2)
    print(u, v)
  return (u, v)
  
def suiteUVCorrecte(a, b, n):
  u = a 
  v = b
  for k in range(n):
    w = u  #variable de stockage
    u = (u + v) / 2
    v = sqrt((w ** 2 + v ** 2)/2)
    print(u, v)
  return (u, v)
  
print(suiteUVFausse(0, 4, 3))
print(suiteUV(0, 4, 3))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.