SHARE
TWEET

Untitled

a guest Nov 18th, 2014 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #encoding: utf-8
  2.  
  3. def f(x)
  4.   0.6 * (x ** 2)
  5. end
  6.  
  7. def nn(x, table, n)
  8.   nn_val = 0
  9.   for i in 0..n do
  10.     div_diff = 0
  11.     for j in 0..i do
  12.       d = 1
  13.       for k in 0..i do
  14.         d *= (table[j][:x] - table[k][:x]) if j != k
  15.       end
  16.       div_diff += table[j][:y].to_f / d.to_f;
  17.     end
  18.     for k in 0..i do
  19.       div_diff *= x - table[k][:x]
  20.     end
  21.     nn_val += div_diff
  22.   end
  23.   return nn_val
  24. end
  25.  
  26. n = 6
  27. table = []
  28.  
  29. for i in 0..n
  30.     table[i] = {x: i/n.to_f, y: f(i/n.to_f)}
  31.     puts table[i][:y]
  32. end
  33.  
  34. puts nn(0.5, table, n)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top