def main() -> None: """Find the root f(x) by bisection method.""" l_border = misc.inputf('left border: ') r_border = misc.inputf('right border: ') eps = misc.inputf('eps: ') x_root = bisect_root(f, l_border, r_border, eps) f_root = f(x_root) print(f'L: {l_border}\n' f'R: {r_border}\n' f'eps: {eps}\n') print(f'root = {x_root}\n' f'f(root) = {f_root}\n') # Plot result. vector_x = np.arange(l_border - 1, r_border + 1, 0.1) vectors = [ VectorXY(vector_x, f(vector_x), 'slategrey', 'f'), ] dots = [ Dot(x_root, f_root, 'ro'), ] lines_xv = [ LineXV(l_border, 'g'), LineXV(r_border, 'g'), ] plot_1d(vectors=vectors, dots=dots, lines_xv=lines_xv)
def main() -> None: """Newton method example.""" start_x = misc.inputf('Enter start X: ') start_y = misc.inputf('Enter start Y: ') eps = misc.inputf('eps: ') x_min, y_min = newton_2d(f, start_x, start_y, eps) f_min = f(x_min, y_min) print(f'x_min = {x_min}\n' f'y_min = {y_min}\n' f'f(x_min, y_min) = {f_min}\n') # Plot result. dots = [ Dot(x_min, y_min, 'ro'), ] plot_2d(f, dots=dots)
def main() -> None: """Conjugate gradient method example.""" start_x = inputf('Enter start X: ') start_y = inputf('Enter start Y: ') eps = inputf('eps: ') x_min, y_min = conjugate_gradient_2d(f, start_x, start_y, eps) f_min = f(x_min, y_min) print(f'x_min = {x_min}\n' f'y_min = {y_min}\n' f'f(x_min, y_min) = {f_min}\n') # Plot result. dots = [ Dot(x_min, y_min, 'ro'), ] plot_2d(f, dots=dots)
def main() -> None: """Find extremum dots f(x) by bisection method.""" l_border = misc.inputf('left border: ') r_border = misc.inputf('right border: ') eps = misc.inputf('eps: ') x_min = bisect_extremum(f, l_border, r_border, eps, mode='min') x_max = bisect_extremum(f, l_border, r_border, eps, mode='max') f_min = f(x_min) f_max = f(x_max) print(f'L: {l_border}\n' f'R: {r_border}\n' f'eps: {eps}\n') print(f'x_min = {x_min}\n' f'f(x_min) = {f_min}\n' f'x_max = {x_max}\n' f'f(x_max) = {f_max}\n') # Plot result. vector_x = np.arange(l_border - 1, r_border + 1, 0.1) vectors = [ VectorXY(vector_x, f(vector_x), 'slategrey', 'function'), ] dots = [ Dot(x_min, f_min, 'bo'), Dot(x_max, f_max, 'ro'), ] lines_xv = [ LineXV(l_border, 'g'), LineXV(r_border, 'g'), ] plot_1d(vectors=vectors, dots=dots, lines_xv=lines_xv)