dicotomia.py

Created by numworks-pt

Created on March 10, 2020

217 Bytes

A função solve(f,a,b,epsilon) procura uma solução da equação f(x)=0 entre a e b com uma precisão de epsilon por dicotomia. As imagens de a e b por f, f(a) e f(b) devem ter sinais diferentes.


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 cookies policy.