Question: Please help debug my code binChop.py Pls fill In the python code, in the file module binChop.py, fill in the missing code in the function
Please help debug my code binChop.py
Pls fill In the python code, in the file module binChop.py, fill in the missing code in the function solution(self) to carry out binary-chop solution for the roots of an arbitrary function. Your function should include a scheme to automatically bracket the root based on only one initial guess.
binChop.py code blow
# -*- coding: utf-8 -*- from module_basicSolver import basicSolver #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ class binChop(basicSolver): #============================================================================== # Class Attributes __default_step = 0.1 #============================================================================== # Initializer / Instance Attributes def __init__(self): basicSolver.__init__(self) #============================================================================== # Instance methods #------------------------------------------------------------------------------ def solution(self): a = self.get_guess() N = self.get_stop() f = self.deriv(a,0) step = binChop.__default_step # Bracket root # ..........Fill in code
given1 = 0.1 given2 = 0.1 for i in range(1,N+1): given1 = given1 * 2 given2 = given2 / 2 if self.deriv( a + given1,0) * self.deriv(a,0) < 0: b = a + given1 break elif self.deriv( a + given1,0) * self.deriv(a,0) < 0: b = a - given1 break elif self.deriv( a + given2,0) * self.deriv(a,0) < 0: b = a + given2 break elif value(a - given2) * value(a) < 0: b = a - given2 break
# Binary chop # ..........Fill in code #
f = 0.5 return f #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
