[lua] qwdqfqwf

Viewer

copydownloadembedprintName: qwdqfqwf
  1. local diff_methods = {}
  2.  
  3.  
  4. function diff_methods.left_side(vals, step, ind)
  5.     if step == 0  or ind <= 1 then
  6.         return nil    
  7.     end
  8.  
  9.     return (vals[ind].- vals[ind - 1].y) / step
  10. end
  11.  
  12. function diff_methods.right_side(vals, step, ind)
  13.     if step == 0 or ind + 1 > #vals then
  14.         return nil
  15.     end
  16.  
  17.     return (vals[ind + 1].- vals[ind].y) / step
  18. end
  19.  
  20. function diff_methods.center_side(vals, step, ind)
  21.     if step == 0 or ind + 1 > #vals or ind <= 1 then
  22.         return nil
  23.     end
  24.  
  25.     return (vals[ind + 1].- vals[ind - 1].y) / (2 * step)
  26. end
  27.  
  28. function diff_methods.second_diff(vals, step, ind)
  29.     if step == 0 or ind + 1 > #vals or ind <= 1 then
  30.         return nil
  31.     end
  32.  
  33.     return (vals[ind + 1].- 2 * vals[ind].+ vals[ind - 1].y) / (step ^ 2)
  34. end
  35.  
  36.  
  37. function diff_methods.runge_left(vals, step, ind)
  38.     if ind < 3 then
  39.         return nil
  40.     end
  41.  
  42.     local f1 = diff_methods.left_side(vals, step, ind)
  43.     local f2 = (vals[ind].- vals[ind - 2].y) / 2 / step
  44.  
  45.     return f1 + f1 - f2
  46. end
  47.  
  48. function diff_methods.align_vars(vals, step, ind)
  49.     if ind < 1 or ind >= #vals then
  50.         return nil
  51.     end
  52.  
  53.     local diff = ((1 / vals[ind + 1].y) - (1 / vals[ind].y)) / 
  54.                  ((1 / vals[ind + 1].x) - (1 / vals[ind].x))
  55.  
  56.     return (diff * (vals[ind].^ 2)) / (vals[ind].^ 2)
  57. end
  58.  
  59. return diff_methods
  60.  

Editor

You can edit this paste and save as new:


File Description
  • qwdqfqwf
  • Paste Code
  • 05 May-2021
  • 1.37 Kb
You can Share it: