Module: Num4SimDiffLib
- Extended by:
- FFI::Library
- Defined in:
- lib/num4simdiff.rb
Class Method Summary collapse
- .cnvPt2RbAry(n, pt) ⇒ Object
- .cnvRbAry2pt(n, ary) ⇒ Object
- .eulerMethod(yi, x, h, func1, func2) ⇒ Object
- .heunMethod(yi, x, h, func1, func2) ⇒ Object
- .rungeKuttaMethod(yi, x, h, func1, func2) ⇒ Object
Instance Method Summary collapse
-
#f(x, dx) {|x| ... } ⇒ double
dy = f(x, dx).
Class Method Details
.cnvPt2RbAry(n, pt) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/num4simdiff.rb', line 85 def cnvPt2RbAry(n, pt) rbAry = n.times.map { |i| pt.get_double(i * Fiddle::SIZEOF_DOUBLE) } return rbAry end |
.cnvRbAry2pt(n, ary) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/num4simdiff.rb', line 78 def cnvRbAry2pt(n, ary) yi_ptr = FFI::MemoryPointer.new(:double, n) n.times.map { |i| yi_ptr.put_double(i * Fiddle::SIZEOF_DOUBLE, ary[i].to_f) } return yi_ptr end |
.eulerMethod(yi, x, h, func1, func2) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/num4simdiff.rb', line 58 def eulerMethod(yi, x, h, func1, func2) yi_ptr = cnvRbAry2pt(2, yi) yi_1_ptr = eulerMethodFFI(yi_ptr, x, h, func1, func2) yi_1 = cnvPt2RbAry(2, yi_1_ptr) return 1 + yi_1[0] + 0.5 * yi_1[1] end |
.heunMethod(yi, x, h, func1, func2) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/num4simdiff.rb', line 64 def heunMethod(yi, x, h, func1, func2) yi_ptr = cnvRbAry2pt(2, yi) yi_1_ptr = heunMethodFFI(yi_ptr, x, h, func1, func2) yi_1 = cnvPt2RbAry(2, yi_1_ptr) return 1 + yi_1[0] + 0.5 * yi_1[1] end |
.rungeKuttaMethod(yi, x, h, func1, func2) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/num4simdiff.rb', line 70 def rungeKuttaMethod(yi, x, h, func1, func2) yi_ptr = cnvRbAry2pt(2, yi) yi_1_ptr = rungeKuttaMethodFFI(yi_ptr, x, h, func1, func2) yi_1 = cnvPt2RbAry(2, yi_1_ptr) return 1 + yi_1[0] + 0.5 * yi_1[1] end |
Instance Method Details
#f(x, dx) {|x| ... } ⇒ double
16 |
# File 'lib/num4simdiff.rb', line 16 callback :f, [:double, :double], :double |