Method: AppMath::Graph#draw_func

Defined in:
lib/graph.rb

#draw_func(f, n, color = 'red', auto_adjust_y = true) ⇒ Object

Drawing a polygon which represents function f. The x-values to be used for creating this polygon are determined by interval @ivx and the number n of points. f is assumed to be a ‘function object’ in the sense that it dfines a method ‘at’ so that f.at(x) is what one normally would write as f(x). So ‘at’ replaces C++‘s operator(). Of course, the last argument allows auto-scaling of the y-range.



201
202
203
204
205
206
207
208
209
210
# File 'lib/graph.rb', line 201

def draw_func(f, n, color = 'red', auto_adjust_y = true)
  arr_x = @ivx.to_array(n)
  arr_y = Array.new(n, 0.0)
  for i in 0...n
    xi = arr_x[i]
    yi = f.at(xi)
    arr_y[i] = yi.to_f
  end
  draw(arr_x, arr_y, color, auto_adjust_y)
end