Taylor Series
For a real example of how to use the Taylor series functionality, see this tutorial.
Symbolics.series
— Functionseries(cs, x, [x0=0,], ns=0:length(cs)-1)
Return the power series in x
around x0
to the powers ns
with coefficients cs
.
series(y, x, [x0=0,] ns)
Return the power series in x
around x0
to the powers ns
with coefficients automatically created from the variable y
.
Examples
julia> @variables x y[0:3] z
3-element Vector{Any}:
x
y[0:3]
z
julia> series(y, x, 2)
y[0] + (-2 + x)*y[1] + ((-2 + x)^2)*y[2] + ((-2 + x)^3)*y[3]
julia> series(z, x, 2, 0:3)
z[0] + (-2 + x)*z[1] + ((-2 + x)^2)*z[2] + ((-2 + x)^3)*z[3]
Symbolics.taylor
— Functiontaylor(f, x, [x0=0,] n; rationalize=true)
Calculate the n
-th order term(s) in the Taylor series of f
around x = x0
. If rationalize
, float coefficients are approximated as rational numbers (this can produce unexpected results for irrational numbers, for example).
Examples
julia> @variables x
1-element Vector{Num}:
x
julia> taylor(exp(x), x, 0:3)
1 + x + (1//2)*(x^2) + (1//6)*(x^3)
julia> taylor(exp(x), x, 0:3; rationalize=false)
1.0 + x + 0.5(x^2) + 0.16666666666666666(x^3)
julia> taylor(√(x), x, 1, 0:3)
1 + (1//2)*(-1 + x) - (1//8)*((-1 + x)^2) + (1//16)*((-1 + x)^3)
julia> isequal(taylor(exp(im*x), x, 0:5), taylor(exp(im*x), x, 0:5))
true
Symbolics.taylor_coeff
— Functiontaylor_coeff(f, x[, n]; rationalize=true)
Calculate the n
-th order coefficient(s) in the Taylor series of f
around x = 0
.
Examples
julia> @variables x y
2-element Vector{Num}:
x
y
julia> taylor_coeff(series(y, x, 0:5), x, 0:2:4)
3-element Vector{Num}:
y[0]
y[2]
y[4]