README.markdown in polynomials-0.3.0 vs README.markdown in polynomials-0.4.0

- old
+ new

@@ -2,54 +2,53 @@ ## Usage <pre><code> require 'polynomials' - require 'gnuplot' - include Polynomials +require 'gnuplot' +include Polynomials - polynomial = Polynomial.parse(ARGV[0]) +polynomial = Polynomial.parse(ARGV[0]) - points = polynomial.roots | polynomial.local_extrema | polynomial.inflection_points +points = polynomial.roots | polynomial.local_extrema | polynomial.inflection_points - max_x = points.max_by(&amp;:x).x - min_x = points.min_by(&amp;:x).x +max_x = points.max_by(&amp;:x).x +min_x = points.min_by(&amp;:x).x - start = (min_x - 0.1) - stop = (max_x + 0.1) +start = (min_x - min_x.abs/2) +stop = (max_x + max_x.abs/2) - x = start - data_x,data_y = [],[] - while x &lt; stop - data_x &lt;&lt; x - data_y &lt;&lt; polynomial.(x) - x += 0.005 - end +step = (max_x-min_x).abs/200 - Gnuplot.open do |gp| - Gnuplot::Plot.new(gp) do |plot| - plot.xrange &quot;[#{start}:#{stop}]&quot; - plot.title &quot;Polynomial&quot; - plot.ylabel &quot;f(x)&quot; - plot.xlabel &quot;x&quot; - plot.grid - plot.data &lt;&lt; Gnuplot::DataSet.new( [data_x,data_y] ) do |ds| - ds.with = &quot;lines&quot; - ds.linewidth = 0.1 - ds.title = &quot;f(x) = #{polynomial}&quot; - end +pointset = polynomials.pointset(start,stop,step) - [:inflection_point,:root, :maximum, :minimum].each do |kind_of_point| - selected_points = points.select(&amp;:&quot;#{kind_of_point}?&quot;) - plot.data &lt;&lt; Gnuplot::DataSet.new([selected_points.map(&amp;:x), selected_points.map(&amp;:y)]) do |ds| - ds.with = &quot;points&quot; - ds.linewidth = 2 - ds.title = kind_of_point.to_s.pluralize.titleize - end +data_x = pointset.map(&:x) +data_y = pointset.map(&:y) + +Gnuplot.open do |gp| + Gnuplot::Plot.new(gp) do |plot| + plot.xrange &quot;[#{start}:#{stop}]&quot; + plot.title &quot;Polynomial&quot; + plot.ylabel &quot;f(x)&quot; + plot.xlabel &quot;x&quot; + plot.grid + plot.data &lt;&lt; Gnuplot::DataSet.new( [data_x,data_y] ) do |ds| + ds.with = &quot;lines&quot; + ds.linewidth = 0.2 + ds.title = &quot;f(x) = #{polynomial}&quot; + end + + [:inflection_point,:root, :maximum, :minimum].each do |kind_of_point| + selected_points = points.select(&amp;:&quot;#{kind_of_point}?&quot;) + plot.data &lt;&lt; Gnuplot::DataSet.new([selected_points.map(&amp;:x), selected_points.map(&amp;:y)]) do |ds| + ds.with = &quot;points&quot; + ds.linewidth = 2 + ds.title = kind_of_point.to_s.pluralize.titleize end end end +end </code></pre> ### Bash Command <pre><code> % ruby examples/plot_only_mutual_data.rb '20.432 x^4 - 17.75 x^3 - 20x^2 + 5 x -50'</code></pre>