Skip to content

Commit b63d7e1

Browse files
fixed docs issues (#342)
* fixed docs issues * fixed * fixed error
1 parent ad58cd1 commit b63d7e1

File tree

7 files changed

+43
-44
lines changed

7 files changed

+43
-44
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Basic arithmetic, integration, differentiation, evaluation, and root finding ove
1010
## Installation
1111

1212
```julia
13-
(v1.5) pkg> add Polynomials
13+
(v1.6) pkg> add Polynomials
1414
```
1515

1616
## Available Types of Polynomials
@@ -23,36 +23,36 @@ Basic arithmetic, integration, differentiation, evaluation, and root finding ove
2323

2424
## Usage
2525

26-
```julia
26+
```jldoctest
2727
julia> using Polynomials
2828
```
2929

3030
### Construction and Evaluation
3131

3232
Construct a polynomial from an array (a vector) of its coefficients, lowest order first.
3333

34-
```julia
34+
```jldoctest
3535
julia> Polynomial([1,0,3,4])
3636
Polynomial(1 + 3*x^2 + 4*x^3)
3737
```
3838

3939
Optionally, the variable of the polynomial can be specified.
4040

41-
```julia
41+
```jldoctest
4242
julia> Polynomial([1,2,3], :s)
4343
Polynomial(1 + 2*s + 3*s^2)
4444
```
4545

4646
Construct a polynomial from its roots.
4747

48-
```julia
48+
```jldoctest
4949
julia> fromroots([1,2,3]) # (x-1)*(x-2)*(x-3)
5050
Polynomial(-6 + 11*x - 6*x^2 + x^3)
5151
```
5252

5353
Evaluate the polynomial `p` at `x`.
5454

55-
```julia
55+
```jldoctest
5656
julia> p = Polynomial([1, 0, -1]);
5757
julia> p(0.1)
5858
0.99
@@ -62,7 +62,7 @@ julia> p(0.1)
6262

6363
Methods are added to the usual arithmetic operators so that they work on polynomials, and combinations of polynomials and scalars.
6464

65-
```julia
65+
```jldoctest
6666
julia> p = Polynomial([1,2])
6767
Polynomial(1 + 2*x)
6868
@@ -99,11 +99,11 @@ Polynomial(0.25 - 0.5*x)
9999

100100
Operations involving polynomials with different variables will error.
101101

102-
```julia
102+
```jldoctest
103103
julia> p = Polynomial([1, 2, 3], :x);
104104
julia> q = Polynomial([1, 2, 3], :s);
105105
julia> p + q
106-
ERROR: Polynomials must have same variable.
106+
ERROR: ArgumentError: Polynomials have different indeterminates
107107
```
108108

109109
#### Construction and Evaluation
@@ -179,7 +179,7 @@ Integrate the polynomial `p` term by term, optionally adding a constant
179179
term `k`. The degree of the resulting polynomial is one higher than the
180180
degree of `p` (for a nonzero polynomial).
181181

182-
```julia
182+
```jldoctest
183183
julia> integrate(Polynomial([1, 0, -1]))
184184
Polynomial(1.0*x - 0.3333333333333333*x^3)
185185
@@ -190,7 +190,7 @@ Polynomial(2.0 + 1.0*x - 0.3333333333333333*x^3)
190190
Differentiate the polynomial `p` term by term. The degree of the
191191
resulting polynomial is one lower than the degree of `p`.
192192

193-
```julia
193+
```jldoctest
194194
julia> derivative(Polynomial([1, 3, -1]))
195195
Polynomial(3 - 2*x)
196196
```
@@ -201,19 +201,19 @@ Polynomial(3 - 2*x)
201201
Return the roots (zeros) of `p`, with multiplicity. The number of
202202
roots returned is equal to the degree of `p`. By design, this is not type-stable, the returned roots may be real or complex.
203203

204-
```julia
204+
```jldoctest
205205
julia> roots(Polynomial([1, 0, -1]))
206-
2-element Array{Float64,1}:
206+
2-element Vector{Float64}:
207207
-1.0
208208
1.0
209209
210210
julia> roots(Polynomial([1, 0, 1]))
211-
2-element Array{Complex{Float64},1}:
211+
2-element Vector{ComplexF64}:
212212
0.0 - 1.0im
213213
0.0 + 1.0im
214214
215215
julia> roots(Polynomial([0, 0, 1]))
216-
2-element Array{Float64,1}:
216+
2-element Vector{Float64}:
217217
0.0
218218
0.0
219219
```
@@ -222,7 +222,7 @@ julia> roots(Polynomial([0, 0, 1]))
222222

223223
Fit a polynomial (of degree `deg` or less) to `x` and `y` using a least-squares approximation.
224224

225-
```julia
225+
```jldoctest
226226
julia> xs = 0:4; ys = @. exp(-xs) + sin(xs);
227227
228228
julia> fit(xs, ys) |> p -> round.(coeffs(p), digits=4) |> Polynomial

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
44
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
5+
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
56

67
[compat]
78
Documenter = "0.24"

src/pade.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,12 @@ Evaluate the Pade approximant at the given point.
9292
```jldoctest pade
9393
julia> using Polynomials, Polynomials.PolyCompat, SpecialFunctions
9494
95-
96-
97-
9895
julia> p = Polynomial(@.(1 // BigInt(gamma(1:17))));
9996
100-
101-
10297
julia> pade = Pade(p, 8, 8);
10398
104-
10599
julia> pade(1.0) ≈ exp(1.0)
106100
true
107-
108101
```
109102
"""
110103
(PQ::Pade)(x) = PQ.p(x) / PQ.q(x)

src/polynomials/LaurentPolynomial.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,16 @@ julia> using Polynomials;
304304
julia> z = variable(LaurentPolynomial, :z)
305305
LaurentPolynomial(z)
306306
307-
julia> h = LaurentPolynomial([1,1], -1:0, :z)
307+
julia> h = LaurentPolynomial([1,1], -1, :z)
308308
LaurentPolynomial(z⁻¹ + 1)
309309
310-
julia> Polynomials.paraconj(h)(z) ≈ 1 + z ≈ LaurentPolynomial([1,1], 0:1, :z)
310+
julia> Polynomials.paraconj(h)(z) ≈ 1 + z ≈ LaurentPolynomial([1,1], 0, :z)
311311
true
312312
313-
julia> h = LaurentPolynomial([3,2im,1], -2:0, :z)
313+
julia> h = LaurentPolynomial([3,2im,1], -2, :z)
314314
LaurentPolynomial(3*z⁻² + 2im*z⁻¹ + 1)
315315
316-
julia> Polynomials.paraconj(h)(z) ≈ 1 - 2im*z + 3z^2 ≈ LaurentPolynomial([1, -2im, 3], 0:2, :z)
316+
julia> Polynomials.paraconj(h)(z) ≈ 1 - 2im*z + 3z^2 ≈ LaurentPolynomial([1, -2im, 3], 0, :z)
317317
true
318318
319319
julia> Polynomials.paraconj(h)(z) ≈ (conj ∘ h ∘ conj ∘ inv)(z)
@@ -459,11 +459,11 @@ The roots of a function (Laurent polynomial in this case) `a(z)` are the values
459459
```julia
460460
julia> using Polynomials;
461461
462-
julia> p = LaurentPolynomial([24,10,-15,0,1],-2:1,:z)
462+
julia> p = LaurentPolynomial([24,10,-15,0,1],-2,:z)
463463
LaurentPolynomial(24*z⁻² + 10*z⁻¹ - 15 + z²)
464464
465-
julia> roots(a)
466-
4-element Array{Float64,1}:
465+
julia> roots(p)
466+
4-element Vector{Float64}:
467467
-3.999999999999999
468468
-0.9999999999999994
469469
1.9999999999999998

src/polynomials/multroot.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ to identify roots of polynomials with suspected multiplicities over
1515
1616
Example:
1717
18-
```
18+
```jldoctest
1919
julia> using Polynomials
2020
2121
julia> p = fromroots([sqrt(2), sqrt(2), sqrt(2), 1, 1])
2222
Polynomial(-2.8284271247461907 + 11.656854249492383*x - 19.07106781186548*x^2 + 15.485281374238573*x^3 - 6.242640687119286*x^4 + 1.0*x^5)
2323
2424
julia> roots(p)
25-
5-element Array{Complex{Float64},1}:
25+
5-element Vector{ComplexF64}:
2626
0.999999677417768 + 0.0im
2727
1.0000003225831504 + 0.0im
2828
1.4141705716005981 + 0.0im
2929
1.4142350577588885 - 3.72273772278647e-5im
3030
1.4142350577588885 + 3.72273772278647e-5im
3131
3232
julia> Polynomials.Multroot.multroot(p)
33-
(values = [0.9999999999999993, 1.4142135623730958], multiplicities = [2, 3], κ = 5.218455674370636, ϵ = 2.8736226244218195e-16)
33+
(values = [0.9999999999999992, 1.4142135623730958], multiplicities = [2, 3], κ = 5.218455674370639, ϵ = 1.5700924586837747e-16)
3434
```
3535
3636
The algorithm has two stages. First it uses `pejorative_manifold` to

src/rational-functions/common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ julia> pq = (-s^2 + s + 1) // (s * (s+1)^2)
483483
(1.0 + 1.0*s - 1.0*s^2) // (1.0*s + 2.0*s^2 + 1.0*s^3)
484484
485485
julia> d,r = residues(pq)
486-
(Polynomial(0.0), Dict(-1.0 => [-1.9999999999999978, 1.0000000000000029], 2.0153919257182735e-18 => [1.0]))
486+
(Polynomial(0.0), Dict(-1.0 => [-1.999999999999996, 1.0000000000000058], -3.9475890993172333e-19 => [1.0]))
487487
488488
julia> iszero(d)
489489
true
@@ -498,7 +498,7 @@ julia> for (λ, rs) ∈ r # reconstruct p/q from output of `residues`
498498
end
499499
500500
julia> p′, q′ = lowest_terms(d)
501-
(1.0 + 1.0*s - 1.0*s^2) // (6.64475e-16 + 1.0*s + 2.0*s^2 + 1.0*s^3)
501+
(0.9999999999999823 + 1.0000000000000204*s - 0.9999999999999962*s^2) // (1.095165368514998e-15 + 0.9999999999999856*s + 1.9999999999999905*s^2 + 1.0*s^3)
502502
503503
julia> q′ ≈ (s * (s+1)^2) # works, as q is monic
504504
true

src/show.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,25 @@ also be useful for the default `show` methods. The following example
209209
shows how `Dual` objects of `DualNumbers` may be printed with
210210
parentheses.
211211
212-
```
213-
using DualNumbers
212+
```jldoctest
213+
julia> using DualNumbers
214+
214215
julia> Polynomial([Dual(1,2), Dual(3,4)])
215216
Polynomial(1 + 2ɛ + 3 + 4ɛ*x)
217+
```
218+
219+
```jldoctest
220+
julia> using DualNumbers, Polynomials
216221
217222
julia> function Base.show_unquoted(io::IO, pj::Dual, indent::Int, prec::Int)
218-
if Base.operator_precedence(:+) <= prec
219-
print(io, "(")
220-
show(io, pj)
221-
print(io, ")")
222-
else
223-
show(io, pj)
223+
if Base.operator_precedence(:+) <= prec
224+
print(io, "(")
225+
show(io, pj)
226+
print(io, ")")
227+
else
228+
show(io, pj)
229+
end
224230
end
225-
end
226231
227232
julia> Polynomial([Dual(1,2), Dual(3,4)])
228233
Polynomial((1 + 2ɛ) + (3 + 4ɛ)*x)

0 commit comments

Comments
 (0)