Differentiating and integrating polynomials
This example shows the use of the functions derivative()
and integrate()
from the Polynomials.jl library to analytically find derivatives and integrals of polynomials.
Let's connect the library Polynomials.jl:
using Polynomials
Differentiating polynomials
Let's define a polynomial
p = Polynomial([7, 0, -4, 1])
Find the first derivative of the polynomial :
q_1 = derivative(p)
Find the second derivative of the polynomial :
q_2 = derivative(p, 2)
Find the derivative of the rational expression , where and are polynomials:
a = Polynomial([5, 3, 1]);
b = Polynomial([6, 4, 2]);
ab = a // b
The first derivative of such an expression will be equal to:
In case the function derivative()
returns one value when calculating the derivative of a rational function, the value obtained will also be a rational function:
c = derivative(ab)
If the function derivative()
returns two values when calculating the derivative of a rational function, then we will get polynomials of the numerator and denominator of the resulting expression:
c_n, c_d = derivative(ab)
[c_n, c_d]
Integration of polynomials
Let's find the integral of the polynomial
s_0 = integrate(q_1)
Let us find the integral of the same polynomial, but with the addition of the free coefficient:
s = integrate(q_1, 7)
Conclusion
In this demo we have looked at how to differentiate and integrate polynomials using the Polynomials.jl library.