Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.89 KB | None | 0 0
  1. class Funkcja
  2.    
  3.     def initialize
  4.         @function = Proc.new
  5.     end
  6.    
  7.     def value(x)
  8.         return @function.call(x)
  9.     end
  10.  
  11.     def poch(x) #http://www.obliczeniowo.com.pl/706
  12.         f_x1 = @function.call(x)
  13.         x += 0.0000001
  14.         f_x2 = @function.call(x)
  15.         return (f_x2 - f_x1) / 0.0000001
  16.     end
  17.  
  18.     def pole(a, b) #http://www.obliczeniowo.com.pl/704
  19.         dx = (b - a) / 100
  20.         integr = 0
  21.         (0..100).each do |i|
  22.             i = (i * dx) + a
  23.             fx1 = @function.call(i)
  24.             i += dx
  25.             fx2 = @function.call(i)
  26.             integr += (0.5 * dx * (fx1 + fx2))
  27.         end
  28.         return integr
  29.     end
  30.  
  31.     def zerowe(a,b,e)
  32.         return "do zaimplementowania leniwy smieciu"
  33.     end
  34. end
  35.  
  36.  
  37.  
  38. syf = Funkcja.new{ |x| x*x }
  39. puts syf.value(42)
  40. puts syf.poch(1)
  41. puts syf.pole(0,1)
  42. puts syf.zerowe(0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement