Engee documentation
Notebook

Building polynomial models

In this example, using the specialized library Polynomials, the construction of polynomials of various orders and their visualization will be demonstrated.

Installing the library of Polynomials required for building polynomials:

In [ ]:
Pkg.add("Polynomials")

Launching the Polynomials Library:

In [ ]:
using Polynomials

Forming a set of data from which the polynomials will be constructed:

In [ ]:
xs = collect(0:20); ys = @. exp(-xs) + sin(xs);

Building polynomial models:

In [ ]:
pol1 = fit(xs,ys,1)
pol5 = fit(xs,ys,5)
pol9 = fit(xs,ys,9)
pol20 = fit(xs,ys,20)
println(pol1)
0.411552 - 0.0288685*x

Launching the charting library:

In [ ]:
using Plots

Plotting the resulting polynomials:

In [ ]:
scatter(xs,ys,label="исходные данные")
plot!(pol1, extrema(xs)..., label="полином 1-й степени")
plot!(pol5, extrema(xs)..., label="полином 5-й степени")
plot!(pol9, extrema(xs)..., label="полином 9-й степени")
plot!(pol20, extrema(xs)..., label="полином 20-й степени")
Out[0]:

Conclusion:

In this example, the construction of polynomials and their visualization were demonstrated. Using the graph, you can estimate how much the degree of the polynomial affects its fit to the original data set.