1+ function get_points (f:: Function , options= Dict ())
2+ opt = merge ([" left" => - 10 , " right" => 10 , " step" => 0.5 , " name" => " $f " ], options)
3+ n:: Int = (opt[" right" ] - opt[" left" ]) / opt[" step" ] + 1
4+ X = Float64[0 for i in 1 : n]
5+ Y = Float64[0 for i in 1 : n]
6+ for i in 1 : n
7+ x = opt[" step" ]* (i- 1 ) + opt[" left" ]
8+ y = f (x)
9+ X[i] = round (x, 8 )
10+ Y[i] = round (y, 8 )
11+ end
12+
13+ return [" x" => X, " y" => Y, " type" => " scatter" , " mode" => " lines" , " name" => opt[" name" ]]
14+ end
15+
16+ function plot (fs:: Array{Function,1} , options= Dict ())
17+ data = [get_points (f, options) for f in fs]
18+ return plot ([data], options)
19+ end
20+
21+ function plot (f:: Function , options= Dict ())
22+ return plot ([f], options)
23+ end
24+
25+ if Pkg. installed (" Polynomial" ) != = nothing
26+ using Polynomial
27+
28+ function plot {T<:Number} (ps:: Array{Poly{T},1} , options= Dict ())
29+ data = [get_points (x-> polyval (p,x), merge ([" name" => " $p " ], options)) for p in ps]
30+ return plot ([data], options)
31+ end
32+
33+ function plot (p:: Poly , options= Dict ())
34+ return plot ([p], options)
35+ end
36+ end
0 commit comments