dichotomie.py

Created by numworks

Created on April 11, 2018

218 Bytes

La fonction solve(f,a,b,epsilon) recherche une solution de l’équation f(x)=0 entre a et b avec une précision de epsilon par dichotomie. Les images de a et b par f, f(a) et f(b), doivent être de signes différents.


from math import *
def solve(f,a,b,epsilon):
  if f(a)*f(b)>0:
    return None
  else:
    while (b-a)>=epsilon:
      c=(a+b)/2
      if f(b)*f(c)<=0:
        a=c
      else:
        b=c
    return c

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.