def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options)
      dataset = data.is_a?(Dataset) ? Dataset.new(data.data) : Dataset.new(data)
      opts_str = OptionHandling.ruby_class_to_gnuplot(options)
      output = gnuplot_fit(function, dataset, opts_str, initials, term_options)
      res = parse_output(initials.keys, function, output)
      {
        formula_ds: Dataset.new(res[2], title: 'Fit formula'),
        coefficients: res[0],
        deltas: res[1],
        data: dataset
      }
    end
def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options)
      dataset = data.is_a?(Dataset) ? Dataset.new(data.data) : Dataset.new(data)
      opts_str = OptionHandling.ruby_class_to_gnuplot(options)
      output = gnuplot_fit(function, dataset, opts_str, initials, term_options)
      res = parse_output(initials.keys, function, output)
      {
        formula_ds: Dataset.new(res[2], title: 'Fit formula'),
        coefficients: res[0],
        deltas: res[1],
        data: dataset
      }
    end
Fit given data with function.

 Fit waits for output from gnuplot Settings.max_fit_delay and throw exception if gets nothing.
 One can change this value in order to wait longer (if huge datasets is fitted).

 @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new
   and Dataset object
 @param :function [String] function to fit data with
 @param :initials [Hash] initial values for coefficients used in fitting
 @param :term_options [Hash] terminal options that should be setted to terminal before fit.
   You can see them in Plot's documentation (or even better in gnuplot doc)
   Most useful here are ranges (xrange, yrange etc) and fit option which tunes fit parameters
   (see {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] p. 122)
 @param options [Hash] options passed to Gnuplot's fit such as *using*. They are covered in
   {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] (pp. 69-74)

 @return [Hash] hash with four elements:
   - :formula_ds - dataset with best fit curve as data
   - :coefficients - hash of calculated coefficients. So if you gave
     ``{ initials: {a: 1, b: 1, c: 1} }`` it will return hash with keys :a, :b, :c and its 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(some_data, function: 'exp(a/x)', initials: {a: 10}, term_option: { xrange: 1..100 })
   fit(some_dataset, using: '1:2:3')