Exemple #1
0
prec = 4

xr1 = _polyroots_todo.muller(f,
                             xr=5,
                             h=.5,
                             es100=.5 * 10**(2 - prec),
                             debug=True,
                             tab=18,
                             precision=prec)
print("xr1 = {:.{p}}".format(xr1, p=prec))

#we can find the remaining roots by finding xr1 conjugate first, then depleting
#polynomial a with resulting quadratic polynomial (x - xr1)(x - xr2), then
#continue applying muller() until we get a quadratic or linear equation,
#which then can be solved with the quadratic formula or simple solving.
b = _poly.defl(a, xr1)[0]

xr2, xr3 = _polyroots_todo.quadratic(a=b[2], b=b[1], c=b[0])
print("xr2 = {}".format(xr2))
print("xr3 = {}".format(xr3))

#plot roots
xr = [xr1, xr2, xr3]  #add additional roots here
_plot.graph(f, xl, xu, title="y = {}".format(_poly.tostr(a)), show=False)
axes = plt.gca()  #get current axes object and obtain dimensions
left, right = axes.get_xlim()
width = right - left
down, up = axes.get_ylim()
height = up - down
for i in range(len(xr)):
    plt.annotate("xr{} = {:.{p}}".format(i + 1, xr[i], p=prec),
Exemple #2
0
def f(x):
    return _poly.eval(a, x)


# Graphical Solution

xl, xu = -5, 5
# _plot.graph(f, xl, xu)
_plot.graph(f, xl, xu, title='y = {}'.format(_poly.tostr(a)))

#  Muller Method
xr1 = _polyroots_muller.muller(f, xr=1, h=.5, debug=True)
print('\nxr1 = {:.2f}'.format(xr1))

b, _ = _poly.defl(a, xr1)

xr2, xr3 = _polyroots_muller.quadratic(a=b[2], b=b[1], c=b[0])
print(f"xr2 = {xr2:.2}")
print(f"xr3 = {xr3:.2}")

# plot roots
xr = [xr1, xr2, xr3]
_plot.graph(f, xl, xu, title="y = {}".format(_poly.tostr(a)), show=False)
axes = plt.gca()  # get current axes object and obtain dimensions
left, right = axes.get_xlim()
width = right - left
down, up = axes.get_ylim()
height = up - down
for i in range(len(xr)):
    plt.annotate(f"xr{i + 1} = {xr[i]:.{2}}",
Exemple #3
0
                             h=.5,
                             es100=.5 * 10**(2 - prec),
                             debug=True,
                             tab=18,
                             precision=prec)
print("xr1 = {:.{p}}".format(xr1, p=prec))

#we can find the remaining roots by finding xr1 conjugate first, then depleting
#polynomial a with resulting quadratic polynomial (x - xr1)(x - xr2), then
#continue applying muller() until we get a quadratic or linear equation,
#which then can be solved with the quadratic formula or simple solving.
xr2 = xr1.conjugate()
print("xr2 = {:.{p}}".format(xr2, p=prec))

#Deflate the polynomial by dividing by the two roots found above
b = _poly.defl(a, xr1)[0]
c = _poly.defl(b, xr2)[0]

xr3, xr4 = _polyroots_todo.quadratic(a=c[2], b=c[1], c=c[0])
print("xr3 = {}".format(xr3))
print("xr4 = {}".format(xr4))

#plot roots
xr = [xr1, xr2, xr3, xr4]  #add additional roots here
_plot.graph(f, xl, xu, title="y = {}".format(_poly.tostr(a)), show=False)
axes = plt.gca()  #get current axes object and obtain dimensions
left, right = axes.get_xlim()
width = right - left
down, up = axes.get_ylim()
height = up - down
for i in range(len(xr)):