Skip to content

Commit

Permalink
Add examples to series() and taylor() docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle committed Oct 9, 2024
1 parent 8927055 commit cf81667
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
series(y, x, [x0=0,] ns; name = nameof(y))
Expand the variable `y` in a power series in the variable `x` around `x0` to orders `ns`.
Examples
========
```julia
julia> @variables z ϵ
2-element Vector{Num}:
z
ϵ
julia> series(z, ϵ, 2, 0:3)
z[0] + z[1]*(-2 + ϵ) + z[2]*((-2 + ϵ)^2) + z[3]*((-2 + ϵ)^3)
```
"""
function series(y, x, x0, ns; name = nameof(y))
c, = @variables $name[ns]
Expand All @@ -15,6 +28,21 @@ end
taylor_coeff(f, x[, n]; rationalize=true)
Calculate the `n`-th order coefficient(s) in the Taylor series of `f` around `x = 0`.
Examples
========
```julia
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]
```
"""
function taylor_coeff(f, x, n = missing; rationalize=true)
if n isa AbstractArray
Expand Down Expand Up @@ -70,6 +98,9 @@ julia> taylor(exp(x), x, 0:3; rationalize=false)
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
```
"""
function taylor(f, x, ns; kwargs...)
Expand Down

0 comments on commit cf81667

Please sign in to comment.