Polynomial().equality()
\(\displaystyle f{\left(x \right)} = \sum_{i=0}^{n} x^{i} {a}_{i}\)
A single variable polynomial with real coefficients is a function of the form \(f\) that takes a real number as input, produces a real number as output, and has the form:
\[f(x)=a_0+a_1x+a_2x^2+...+a_nx^n\]
where \(a_0,a_1,...,a_n\) are real numbers. The number \(a_i\) are called the coefficients of f. The degree of the polynomial is the integer \(n\).
Polynomial (function_name:str='f', variable_name:str='x', degree:Union[int,str]='n', coefficient_name:str='a')
A class used to represent a general polynomial, which is a function that both takes and returns real numbers. Currently only supports single-variable polynomial functions. Polynomials require: - coefficients - degree
Type | Default | Details | |
---|---|---|---|
function_name | str | f | name of function |
variable_name | str | x | name of variable |
degree | typing.Union[int, str] | n | degree of polynomial |
coefficient_name | str | a | str for name of coefficients |
\(\displaystyle g{\left(t \right)} = t^{3} {a}_{3} + t^{2} {a}_{2} + t {a}_{1} + {a}_{0}\)
If you want to set a specific polynomial all at once, here’s a helper function for that:
polynomial (degree:int, coefficients:list)
Returns a polynomial function with the given degree and coefficients
Type | Details | |
---|---|---|
degree | int | degree of polynomial |
coefficients | list | list of coefficients starting with the lowest indexed coefficient |
Sometimes it might be better to directly generate a polynomial with the equation
function.
For example, to create the above polynomial as a one liner, see below. It’s up to you to decide which is clearer.
For any integer \(n\geq 0\), and any list of \(n+1\) points \((x_0,y_0),(x_1,y_1),...,(x_n,y_n)\) in R^2 there is a unique polynomial \(f\) of degree at most \(n\) such that \(f(x_i)=y_i\) for all \(i=0,1,...,n\).
polynomial_to_test = polynomial(3, [2, 0, 4, -1])
simple_polynomial = polynomial(1, [1, 1])
polynomial_to_test.polynomial
\(\displaystyle f{\left(x \right)} = - x^{3} + 4 x^{2} + 2\)
sample_pairs = make_examples('real', 6, 5, positive_only=True, increasing_only=True)
for pair in sample_pairs:
print(pair)
print('bigger:', polynomial_to_test.get_output(pair[0]))
print('simple:', simple_polynomial.get_output(pair[0]))
(97, 5)
bigger: Eq(f(97), -875035)
simple: Eq(f(97), 98)
(187, 5)
bigger: Eq(f(187), -6399325)
simple: Eq(f(187), 188)
(261, 5)
bigger: Eq(f(261), -17507095)
simple: Eq(f(261), 262)
(315, 5)
bigger: Eq(f(315), -30858973)
simple: Eq(f(315), 316)
(338, 5)
bigger: Eq(f(338), -38157494)
simple: Eq(f(338), 339)
(382, 5)
bigger: Eq(f(382), -55159270)
simple: Eq(f(382), 383)