math_root_find 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +0 -0
  2. data/lib/math_root_find.rb +23 -0
  3. metadata +60 -0
data/README ADDED
File without changes
@@ -0,0 +1,23 @@
1
+ module SuperMath
2
+ VERSION = "0.0.1"
3
+
4
+ # optimized version of find_root, performs 10000 roots' calculations per sec on Core 2 Duo 2.67
5
+ def self.find_root(a, b, precision=0.01, allow_oob_roots=false, &blk)
6
+ fa, fb = yield(a).to_f, yield(b).to_f
7
+ sa, sb = fa >= 0 ? 1 : -1, fb >= 0 ? 1 : -1
8
+ while true do
9
+ # puts "f(#{a},#{(a/precision).truncate})=#{fa}, f(#{b},#{(b/precision).truncate})=#{fb}"
10
+ raise "Looking for roots out of bounds" if !allow_oob_roots && sa == sb
11
+ return a if (a-b).abs < precision || fa.abs <= precision
12
+ return b if fb.abs <= precision
13
+ c = (a.to_f + b.to_f) / 2
14
+ fc = yield(c)
15
+ sc = fc >= 0 ? 1 : -1
16
+ if sa != sc
17
+ b, fb, sb = c, fc, sc
18
+ else
19
+ a, fa, sa = c, fc, sc
20
+ end
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: math_root_find
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Kasatenko
9
+ - UNIQ Systems
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-11-10 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &70339107627020 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70339107627020
26
+ description: Simple math extension that performs f(x)==0 equation numerical root calculation.
27
+ Takes a block as an equation and tries to call it the least amount of times.
28
+ email:
29
+ - sky@uniqsystems.ru
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/math_root_find.rb
35
+ - README
36
+ homepage: http://github.com/uniqsys/math_root_find
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.6
54
+ requirements: []
55
+ rubyforge_project: math_root_find
56
+ rubygems_version: 1.8.10
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Simple math extension that performs f(x)==0 equation numerical root calculation
60
+ test_files: []