Skip to content

Commit 305afc4

Browse files
committed
Add examples to series() and taylor() docstrings
1 parent 27b3336 commit 305afc4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/taylor.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
series(y, x, [x0=0,] ns; name = nameof(y))
33
44
Expand the variable `y` in a power series in the variable `x` around `x0` to orders `ns`.
5+
6+
Examples
7+
========
8+
9+
```julia
10+
julia> @variables z ϵ
11+
2-element Vector{Num}:
12+
z
13+
ϵ
14+
15+
julia> series(z, ϵ, 2, 0:3)
16+
z[0] + z[1]*(-2 + ϵ) + z[2]*((-2 + ϵ)^2) + z[3]*((-2 + ϵ)^3)
17+
```
518
"""
619
function series(y, x, x0, ns; name = nameof(y))
720
c, = @variables $name[ns]
@@ -15,6 +28,21 @@ end
1528
taylor_coeff(f, x[, n]; rationalize=true)
1629
1730
Calculate the `n`-th order coefficient(s) in the Taylor series of `f` around `x = 0`.
31+
32+
Examples
33+
========
34+
```julia
35+
julia> @variables x y
36+
2-element Vector{Num}:
37+
x
38+
y
39+
40+
julia> taylor_coeff(series(y, x, 0:5), x, 0:2:4)
41+
3-element Vector{Num}:
42+
y[0]
43+
y[2]
44+
y[4]
45+
```
1846
"""
1947
function taylor_coeff(f, x, n = missing; rationalize=true)
2048
if n isa AbstractArray
@@ -70,6 +98,9 @@ julia> taylor(exp(x), x, 0:3; rationalize=false)
7098
7199
julia> taylor(√(x), x, 1, 0:3)
72100
1 + (1//2)*(-1 + x) - (1//8)*((-1 + x)^2) + (1//16)*((-1 + x)^3)
101+
102+
julia> isequal(taylor(exp(im*x), x, 0:5), taylor(exp(im*x), x, 0:5))
103+
true
73104
```
74105
"""
75106
function taylor(f, x, ns; kwargs...)

0 commit comments

Comments
 (0)