Example #1
0
__author__ = 'harrisonjordan'
from polynomials import bisection, eval
x = 3
poly = [2, 3, 0, 5]

print("x: ", x)
print("poly: ", poly)
print("Evaluation: ", eval(x, poly))
Example #2
0
                try:
                    parts = data_string.split(' ')
                    messageToClient = ''
                except Exception as e:
                    messageToClient = 'Xspacing in request wrong'

                # Evaluate Request
                if requestType == 'E':
                    if(len(parts) < 2):
                        messageToClient = 'Xnot enough arguments'
                    else:
                        try:
                            x = int(float(parts[0]))
                            parts = parts[1:]
                            poly = [int(float(x)) for x in parts]
                            evaluate = eval(x, poly)
                            messageToClient = 'E{}'.format(evaluate)
                        except Exception as e:
                            messageToClient = 'Xinvalid format numeric data'

                #Bisection Request
                if requestType == 'S':
                    if(len(parts) < 4):
                        messageToClient = 'Not enough arguments'
                    else:
                        try:
                            a = int(float(parts[0]))
                            b = int(float(parts[1]))
                            tol = float(parts[-1])
                            print('a: {} b: {} tol: {}'.format(a, b, tol))
                            poly = [int(float(x)) for x in parts[2:-1]]
Example #3
0
__author__ = 'Harrison Jordan'

from polynomials import bisection, eval

toler = 1e-14

poly1 = [-945, 1689, -950, 230, -25, 1]
# roots are 1, 3, 5, 7, 9
x1 = bisection(0, 2, poly1, 1e-15)
# print root and evaluate the polynomial
print(x1, eval(x1,poly1))
x2 = bisection(4,2,poly1,toler)
print(x2, eval(x2,poly1))
x3 = bisection(4,6,poly1, toler)
print(x3, eval(x3,poly1))
x4 = bisection(8,6,poly1, toler)
print(x4, eval(x4,poly1))
x5 = bisection(8,100,poly1, toler)
print(x5, eval(x5,poly1))
# compare the roots to the expected values
print(x1-1, x2-3, x3-5, x4-7, x5-9)

print(eval(1, [1,2,2]))