lib/gnuplotrb/fit.rb
##
# Shortcut for fit with polynomial. Degree here is max power of *x* in polynomial.
#
# @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new
#   and Dataset object
# @param :degree [Integer] degree of polynomial
# @param options [Hash] all of this options will be passed to #fit so you
#   can set here any options listed in its docs. If you pass here :initials hash, it
#   will be merged into default initals hash. Formula by default is
#   "xn*x**n + ... + x0*x**0", initials by default "{ an: 1, ..., a0: 1 }"
#
# @return [Hash] hash with four elements:
#   - :formula_ds - dataset with best fit curve as data
#   - :coefficients - hash of calculated coefficients. So for degree = 3
#     it will return hash with keys :a3, :a2, :a1, :a0 and calculated values
#   - :deltas - Gnuplot calculates possible deltas for coefficients during fitting and
#     deltas hash contains this deltas
#   - :data - pointer to Datablock with given data
# @example
#   fit_poly(some_data, degree: 5, initials: { a4: 10, a2: -1 }, term_option: { xrange: 1..100 })
#   #=> The same as:
#   #=> fit(
#   #=>   some_data,
#   #=>   function: 'a5*x**5 + a4*x**4 + ... + a0*x**0',
#   #=>   initals: {a5: 1, a4: 10, a3: 1, a2: -1, a1: 1, a0: 1},
#   #=>   term_option: { xrange: 1..100 }
#   #=> )
Shortcut for fit with polynomial. Degree here is max power of *x* in polynomial.
Shortcut for fit with polynomial . Degree here is max power of * x * in polynomial .
def fit_poly(data, degree: 2, **options)
      sum_count = degree + 1
      initials = {}
      sum_count.times { |i| initials["a#{i}".to_sym] = 1 }
      options[:initials] = initials.merge(options[:initials] || {})
      function = sum_count.times.map { |i| "a#{i}*x**#{i}" }.join(' + ')
      fit(data, **options, function: function)
    end
def fit_poly ( data , degree : 2 , ** options ) sum_count = degree + 1 initials = { } sum_count . times { | i | initials [ "a#{i}" . to_sym ] = 1 } options [ :initials ] = initials . merge ( options [ :initials ] || { } ) function = sum_count . times . map { | i | "a#{i}*x**#{i}" } . join ( ' + ' ) fit ( data , ** options , function : function ) end
Shortcut for fit with polynomial.
Shortcut for fit with polynomial .
hash with four elements: - :formula_ds - dataset with best fit curve as data - :coefficients - hash of calculated coefficients. So for degree = 3 it will return hash with keys :a3, :a2, :a1, :a0 and calculated values - :deltas - Gnuplot calculates possible deltas for coefficients during fitting and deltas hash contains this deltas - :data - pointer to Datablock with given data
hash with four elements : - : formula_ds - dataset with best fit curve as data - : coefficients - hash of calculated coefficients . So for degree = 3 it will return hash with keys : a3 : a2 : a1 : a0 and calculated values - : deltas - Gnuplot calculates possible deltas for coefficients during fitting and deltas hash contains this deltas - : data - pointer to Datablock with given data
Hash
data
method accepts the same sources as Dataset.new and Dataset object
method accepts the same sources as Dataset . new and Dataset object
degree
<not_specific>
options
all of this options will be passed to #fit so you can set here any options listed in its docs. If you pass here :initials hash, it will be merged into default initals hash. Formula by default is "xn*x**n + ...
all of this options will be passed to #fit so you can set here any options listed in its docs . If you pass here : initials hash it will be merged into default initals hash . Formula by default is " xn * x ** n + ...
:degree
<not_specific>
degree of polynomial
degree of polynomial
example
None