Engee documentation
Notebook

Differentiation and integration of polynomials

This example shows the application of functions derivative() and integrate() from the library Polynomials.jl for the analytical finding of derivatives and integrals of polynomials.

Connecting the library of Polynomials.jl:

In [ ]:
using Polynomials

Differentiation of polynomials

Define the polynomial

In [ ]:
p = Polynomial([7, 0, -4, 1])
Out[0]:
7 - 4∙x2 + x3

Let's find the first derivative of the polynomial :

In [ ]:
q_1 = derivative(p)
Out[0]:
-8∙x + 3∙x2

Let's find the second derivative of the polynomial :

In [ ]:
q_2 = derivative(p, 2)
Out[0]:
-8 + 6∙x

Let's find the derivative of a rational expression , where and - polynomials:

In [ ]:
a = Polynomial([5, 3, 1]);
b = Polynomial([6, 4, 2]);
ab = a // b
Out[0]:
(5 + 3*x + x^2) // (6 + 4*x + 2*x^2)

The first derivative of such an expression will be equal to:

In case the function derivative() When calculating the derivative of a rational function, it returns one value, then the resulting value will also be a rational function.:

In [ ]:
c = derivative(ab)
Out[0]:
(-2 - 8*x - 2*x^2) // (36 + 48*x + 40*x^2 + 16*x^3 + 4*x^4)

If the function derivative() When calculating the derivative of a rational function, it returns two values, then we get the polynomials of the numerator and denominator of the resulting expression.:

In [ ]:
c_n, c_d = derivative(ab)
[c_n, c_d]
Out[0]:
2-element Vector{Polynomial{Int64, :x}}:
 Polynomial(-2 - 8*x - 2*x^2)
 Polynomial(36 + 48*x + 40*x^2 + 16*x^3 + 4*x^4)

Integrating polynomials

Let's find the integral of the polynomial

In [ ]:
s_0 = integrate(q_1)
Out[0]:
-4.0∙x2 + 1.0∙x3

Let's find the integral of the same polynomial, but with the addition of a free coefficient.:

In [ ]:
s = integrate(q_1, 7)
Out[0]:
7.0 - 4.0∙x2 + 1.0∙x3

Conclusion

In this demo, we discussed ways to differentiate and integrate polynomials using the library Polynomials.jl.