Class: SciYAG::Backends::MathBackend
- Includes:
- Dobjects, Math
- Defined in:
- lib/SciYAG/Backends/math.rb
Instance Method Summary collapse
- #get_data(set) ⇒ Object
-
#initialize ⇒ MathBackend
constructor
A new instance of MathBackend.
-
#make_dvector(range, nb_points, log = @log) ⇒ Object
Turns a Range and a number of points into a Dvector.
-
#query_xy_data(set) ⇒ Object
This is called by the architecture to get the data.
Methods inherited from Backend
#base_line=, #clear_xy_filters, default_state, describe, #expand_sets, #get_cached_entry, #has_set?, list_backends, list_descriptions, logger=, #meta_data, #pop_xy_filter, #push_xy_filter, #set_type, #sets_available, #xy_data, #xyz_data
Methods included from MetaBuilder::DescriptionExtend
#base_description, #create_factory, #describe, #description, #factory_class, #factory_description, #factory_description_hash, #factory_description_list, #group, #has_factory?, #inherit_parameters, #param, #param_accessor, #param_reader, #param_writer, #register_class, #set_description
Methods included from MetaBuilder::DescriptionInclude
#description, #get_param, #get_param_raw, #long_name, #option_parser_banner, #option_parser_fill, #option_parser_options, #parameter, #restore_state, #save_state, #set_param, #set_param_raw
Constructor Details
#initialize ⇒ MathBackend
Returns a new instance of MathBackend.
47 48 49 50 51 52 53 |
# File 'lib/SciYAG/Backends/math.rb', line 47 def initialize super() @samples = 100 @x_range = -10.0..10.0 @t_range = -10.0..10.0 @log = false end |
Instance Method Details
#get_data(set) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/SciYAG/Backends/math.rb', line 67 def get_data(set) # Parametric plot with a : in the middle if set =~ /:/ x_block, y_block = set.split(/:/).map { |s| eval "proc {|t| #{s}}" } t_v = make_dvector(@t_range, @samples) x_v = t_v.collect(&x_block) y_v = t_v.collect(&y_block) else y_block = eval "proc {|x| #{set} }" x_v = make_dvector(@x_range, @samples) y_v = x_v.collect(&y_block) end return [x_v,y_v] end |
#make_dvector(range, nb_points, log = @log) ⇒ Object
Turns a Range and a number of points into a Dvector
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/SciYAG/Backends/math.rb', line 86 def make_dvector(range, nb_points, log = @log) n = nb_points -1 a = Dvector.new(nb_points) { |i| i.to_f/(n.to_f) } # a is in [0:1] inclusive... if log delta = range.last/range.first # delta is positive necessarily a *= delta.log a.exp! a *= range.first else delta = range.last - range.first a *= delta a += range.first end return a end |
#query_xy_data(set) ⇒ Object
This is called by the architecture to get the data. It splits the set name into func@range, reads the file if necessary and calls get_data.
58 59 60 61 62 63 64 |
# File 'lib/SciYAG/Backends/math.rb', line 58 def query_xy_data(set) if set =~ /(.*)@(.*)/ @x_range = ParamRange.new($2) set = $1 end return Function.new(*get_data(set)) end |