# Calculus with Polynomials [ex203.0]#

This example demonstrates the use of arithmetic manipulations on polynomials.

Arithmetic Operations

• Summation of polynomials

• Product of polynomials

• Integral of polynomials over a single or multiple variables

• Derivative of polynomials

• Shifting a polynomial to the left or right

• Dilating a polynomial

Out:

```Defining univariate polynomials
(array([1, 3, 5]),), (array([0, 1, 2]),)
(array([ 2, -1]),), (array([0, 1]),)

----------------------------------------

Adding two polynomials p1 and p2

(array([ 1.,  3.,  5.,  2., -1.]),), (array([0., 1., 2., 0., 1.]),)

Multiply two polynomials p1 and p2

(array([ 2, -1,  6, -3, 10, -5]),), (array([0., 1., 1., 2., 2., 3.]),)

Square polynomial p1

(array([ 1,  3,  5,  3,  9, 15,  5, 15, 25]),), (array([0., 1., 2., 1., 2., 3., 2., 3., 4.]),)

Shift polynomial p1

(array([27., 23.,  5.]),), (array([0, 1, 2]),)

Dilation polynomial p1

(array([  1, -15, 125]),), (array([0, 1, 2]),)

Integration polynomial p1

(array([1.        , 1.5       , 1.66666667]),), (array([1, 2, 3]),)

Differentiation polynomial p1

(array([ 0,  3, 10]),), (array([0, 0, 1]),)
```

```import lmlib as lm

print("Defining univariate polynomials")
p1 = lm.Poly([1, 3, 5], [0, 1, 2])
p2 = lm.Poly([2, -1], [0, 1])

print(p1)
print(p2)
print("\n"+"-"*40+"\n")
print("Adding two polynomials p1 and p2\n")
print(lm.poly_sum((p1, p2)), '\n')

print("Multiply two polynomials p1 and p2\n")
print(lm.poly_prod((p1, p2)), '\n')

print("Square polynomial p1\n")
print(lm.poly_square(p1), '\n')

print("Shift polynomial p1\n")
gamma = 2
print(lm.poly_shift(p1, gamma), '\n')

print("Dilation polynomial p1\n")
eta = -5
print(lm.poly_dilation(p1, eta), '\n')

print("Integration polynomial p1\n")
print(lm.poly_int(p1), '\n')

print("Differentiation polynomial p1\n")
print(lm.poly_diff(p1), '\n')
```

Total running time of the script: ( 0 minutes 0.003 seconds)

Gallery generated by Sphinx-Gallery