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(&:x).x
- min_x = points.min_by(&:x).x
+max_x = points.max_by(&:x).x
+min_x = points.min_by(&: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 < stop
- data_x << x
- data_y << 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 "[#{start}:#{stop}]"
- plot.title "Polynomial"
- plot.ylabel "f(x)"
- plot.xlabel "x"
- plot.grid
- plot.data << Gnuplot::DataSet.new( [data_x,data_y] ) do |ds|
- ds.with = "lines"
- ds.linewidth = 0.1
- ds.title = "f(x) = #{polynomial}"
- end
+pointset = polynomials.pointset(start,stop,step)
- [:inflection_point,:root, :maximum, :minimum].each do |kind_of_point|
- selected_points = points.select(&:"#{kind_of_point}?")
- plot.data << Gnuplot::DataSet.new([selected_points.map(&:x), selected_points.map(&:y)]) do |ds|
- ds.with = "points"
- 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 "[#{start}:#{stop}]"
+ plot.title "Polynomial"
+ plot.ylabel "f(x)"
+ plot.xlabel "x"
+ plot.grid
+ plot.data << Gnuplot::DataSet.new( [data_x,data_y] ) do |ds|
+ ds.with = "lines"
+ ds.linewidth = 0.2
+ ds.title = "f(x) = #{polynomial}"
+ end
+
+ [:inflection_point,:root, :maximum, :minimum].each do |kind_of_point|
+ selected_points = points.select(&:"#{kind_of_point}?")
+ plot.data << Gnuplot::DataSet.new([selected_points.map(&:x), selected_points.map(&:y)]) do |ds|
+ ds.with = "points"
+ 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>