Skip to content

Commit f68b7ea

Browse files
committed
Shifted interval calculation back into recipe file
1 parent 5e4023d commit f68b7ea

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

src/PlotRecipes.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
using RecipesBase
22

3-
@recipe function poly_recipe(p::Poly, xs = polyinterval(p))
3+
function poly_interval(p::Poly)
4+
# Find points of interest
5+
zero_pts = roots(p)
6+
crit_pts = roots(polyder(p, 1))
7+
infl_pts = roots(polyder(p, 2))
8+
pts = sort([ real(pt) for pt in [zero_pts; crit_pts; infl_pts] if isreal(pt) ])
9+
10+
# Choose a range that shows all interesting points with some margin
11+
min_x, max_x = length(pts) > 0 ? (pts[1], pts[end]) : (-1, 1)
12+
diff = max(max_x - min_x, 1)
13+
a = min_x - diff
14+
b = max_x + diff
15+
16+
return a : diff/100 : b
17+
end
18+
19+
@recipe function poly_recipe(p::Poly, xs = poly_interval(p))
420
buff = IOBuffer()
521
printpoly(buff, p)
622
label --> String(take!(buff))

src/Polynomials.jl

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Polynomials
55

66
export Poly, poly
77
export degree, coeffs, variable, printpoly
8-
export polyval, polyint, polyder, roots, polyfit, polyinterval
8+
export polyval, polyint, polyder, roots, polyfit
99
export Pade, padeval
1010

1111
import Base: length, size, eltype, collect, eachindex, lastindex
@@ -717,40 +717,6 @@ end
717717
polyfit(x,y,sym::Symbol) = polyfit(x,y,length(x)-1, sym)
718718

719719

720-
"""
721-
polyinterval(p)
722-
723-
Choose a sensible interval containing points of interest for the polynomial `p`.
724-
725-
The interval contains some margin either side to allow for plotting.
726-
727-
# Examples
728-
729-
```julia-repl
730-
julia> polyinterval(Poly([0, 0, 1])) # contains single critical point at x=0
731-
-1.0:0.01:1.0
732-
733-
julia> polyinterval(Poly([1, 0, 3, -1])) # points of interest between 0 and 3.1
734-
-3.103803402735535:0.031038034027355346:6.20760680547107
735-
```
736-
"""
737-
function polyinterval(p :: Poly)
738-
# Find points of interest
739-
zero_pts = roots(p)
740-
crit_pts = roots(polyder(p, 1))
741-
infl_pts = roots(polyder(p, 2))
742-
pts = sort([ real(pt) for pt in [zero_pts; crit_pts; infl_pts] if isreal(pt) ])
743-
744-
# Choose a range that shows all interesting points with some margin
745-
min_x, max_x = length(pts) > 0 ? (pts[1], pts[end]) : (-1, 1)
746-
diff = max(max_x - min_x, 1)
747-
a = min_x - diff
748-
b = max_x + diff
749-
750-
return a : diff/100 : b
751-
end
752-
753-
754720
### Pull in others
755721
include("pade.jl")
756722
include("PlotRecipes.jl")

0 commit comments

Comments
 (0)