Example #1
0
from newton import Newton

# Ejercicio 1
newton = Newton(
    value_range=[0, 10],
    f=lambda l: l * (20 - 2 * l)**2,
    fp=lambda l: 12 * l**2 - 160 * l + 400,
    fpp=lambda l: 24 * l - 160,
)
newton.calculate([3])
Example #2
0
def f(x):
    return x**2 + 4 * np.sin(x)


left = int(input('Enter left border: '))
right = int(input('Enter right border: '))
n = int(input('Enter number of points: '))

bf = Bruteforce(left, right, n, f)
bf.FirstStep()
bf.plots()

s1 = Secant.find(f, a=-2, b=-1)
s2 = Secant.find(f, a=-1, b=1)
b1 = Bisect.find(f, a=-2, b=-1)
b2 = Bisect.find(f, a=-1, b=1)

print("\nSecant: {} {}".format(s1, s2))
print("Bisect: {} {}".format(b1, b2))


def dfunc(x):
    return 2 * x + 4 * cos(x)


newton = Newton(f, dfunc, x=2, max_iterations=50, eps=10e-7)
root = newton.calculate()

print("Newton: {}".format(root))