solver 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/Rakefile +5 -41
- data/lib/solver.rb +1 -3
- data/lib/solver/tvm.rb +1 -1
- data/lib/solver/version.rb +5 -0
- data/solver.gemspec +23 -69
- data/test/helper.rb +3 -4
- data/test/test_function.rb +6 -6
- data/test/test_psolver.rb +10 -10
- data/test/test_rfsecant.rb +12 -12
- data/test/test_secant.rb +12 -12
- data/test/test_tvm.rb +16 -16
- metadata +98 -77
- data/VERSION +0 -1
- data/test/chk.rb +0 -26
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7e3863747205d299960de14f4f6fb574d435661
|
4
|
+
data.tar.gz: 5d6eacf431b01313d025970c61b0d1dac0a16b13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0d8c29f097fee10546696c1ae8d992286dd96e1c892fec7acdb56a069660bd5c0b539ef04cbdb42e0a6d5c5fe43ca24c0792866604162ae170a6a4aed0c9ed8
|
7
|
+
data.tar.gz: 3778ce82d42956f7df0c02959e5e20264e6095881e480d617917ad53ff9e24d1f7491e4c54597936b99cb9adfc8f9cbffcba749a1834efda11abd64addb74d7f
|
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,23 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "solver"
|
8
|
-
gem.summary = %Q{Numeric solver to exercise the Flt library}
|
9
|
-
gem.description = %Q{This numeric solver is an example of the use of Flt}
|
10
|
-
gem.email = "jgoizueta@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/jgoizueta/solver"
|
12
|
-
gem.authors = ["Javier Goizueta"]
|
13
|
-
gem.add_development_dependency "shoulda"
|
14
|
-
gem.add_dependency "flt", ">= 1.3.0"
|
15
|
-
gem.required_ruby_version = '> 1.9.1'
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
21
2
|
|
22
3
|
require 'rake/testtask'
|
23
4
|
Rake::TestTask.new(:test) do |test|
|
@@ -26,30 +7,13 @@ Rake::TestTask.new(:test) do |test|
|
|
26
7
|
test.verbose = true
|
27
8
|
end
|
28
9
|
|
29
|
-
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/test_*.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
task :test => :check_dependencies
|
43
|
-
|
44
|
-
task :default => :test
|
45
|
-
|
46
|
-
require 'rake/rdoctask'
|
10
|
+
require 'rdoc/task'
|
47
11
|
Rake::RDocTask.new do |rdoc|
|
48
|
-
version = File.exist?('VERSION') ? File.read('VERSION') :
|
12
|
+
version = File.exist?('VERSION') ? File.read('VERSION').strip : Flt::Solver::VERSION
|
49
13
|
|
50
14
|
rdoc.rdoc_dir = 'rdoc'
|
51
|
-
rdoc.
|
52
|
-
rdoc.
|
15
|
+
rdoc.title = "Flt::Solver #{version}"
|
16
|
+
rdoc.main = "README.rdoc"
|
53
17
|
rdoc.rdoc_files.include('README*')
|
54
18
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
19
|
end
|
data/lib/solver.rb
CHANGED
data/lib/solver/tvm.rb
CHANGED
data/solver.gemspec
CHANGED
@@ -1,73 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'solver/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "solver"
|
8
|
+
spec.version = Flt::Solver::VERSION
|
9
|
+
spec.authors = ["Javier Goizueta"]
|
10
|
+
spec.email = ["jgoizueta@gmail.com"]
|
11
|
+
spec.summary = %q{Numeric Solver using Flt}
|
12
|
+
spec.description = %q{This numeric solver is an example of the use of Flt.}
|
13
|
+
spec.homepage = "http://github.com/jgoizueta/solver"
|
14
|
+
spec.license = "MIT"
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.email = %q{jgoizueta@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/solver.rb",
|
27
|
-
"lib/solver/base.rb",
|
28
|
-
"lib/solver/function.rb",
|
29
|
-
"lib/solver/psolver.rb",
|
30
|
-
"lib/solver/rfsecant.rb",
|
31
|
-
"lib/solver/secant.rb",
|
32
|
-
"lib/solver/tvm.rb",
|
33
|
-
"solver.gemspec",
|
34
|
-
"test/helper.rb",
|
35
|
-
"test/test_function.rb",
|
36
|
-
"test/test_psolver.rb",
|
37
|
-
"test/test_rfsecant.rb",
|
38
|
-
"test/test_secant.rb",
|
39
|
-
"test/test_tvm.rb"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/jgoizueta/solver}
|
42
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
-
s.require_paths = ["lib"]
|
44
|
-
s.required_ruby_version = Gem::Requirement.new("> 1.9.1")
|
45
|
-
s.rubygems_version = %q{1.3.7}
|
46
|
-
s.summary = %q{Numeric solver to exercise the Flt library}
|
47
|
-
s.test_files = [
|
48
|
-
"test/chk.rb",
|
49
|
-
"test/helper.rb",
|
50
|
-
"test/test_function.rb",
|
51
|
-
"test/test_psolver.rb",
|
52
|
-
"test/test_rfsecant.rb",
|
53
|
-
"test/test_secant.rb",
|
54
|
-
"test/test_tvm.rb"
|
55
|
-
]
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
56
20
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
s.add_runtime_dependency(%q<flt>, [">= 1.3.0"])
|
64
|
-
else
|
65
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
66
|
-
s.add_dependency(%q<flt>, [">= 1.3.0"])
|
67
|
-
end
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
70
|
-
s.add_dependency(%q<flt>, [">= 1.3.0"])
|
71
|
-
end
|
21
|
+
spec.add_runtime_dependency "flt", '~> 1.3.1'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "shoulda-context"
|
26
|
+
spec.required_ruby_version = '>= 1.9.2'
|
72
27
|
end
|
73
|
-
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'shoulda'
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'shoulda/context'
|
4
3
|
|
5
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
6
|
require 'solver'
|
8
7
|
|
9
|
-
class
|
8
|
+
class MiniTest::Unit::TestCase
|
10
9
|
end
|
data/test/test_function.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestFunction <
|
4
|
-
|
3
|
+
class TestFunction < MiniTest::Unit::TestCase
|
4
|
+
|
5
5
|
should "convert function to use a hash for parameters" do
|
6
6
|
f = Flt::Solver::Function.with_named_parameters(){|x,y,z| "x=#{x} y=#{y} z=#{z}"}
|
7
7
|
assert_equal "x=100 y=200 z=300", f[:x=>100, :y=>200, :z=>300]
|
8
8
|
assert_equal "x=1 y=2 z=3", f[:x=>1, :y=>2, :z=>3]
|
9
|
-
|
9
|
+
|
10
10
|
f = lambda{|x,y,z| "x=#{x} y=#{y} z=#{z}"}
|
11
11
|
g = Flt::Solver::Function[f]
|
12
12
|
assert_equal "x=100 y=200 z=300", g[:x=>100, :y=>200, :z=>300]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should "bind some of a function's parameters" do
|
16
16
|
f = Flt::Solver::Function.bind(:x=>1000,:z=>2000){|x,y,z| "x=#{x} y=#{y} z=#{z}"}
|
17
17
|
assert_equal "x=1000 y=5000 z=2000", f[5000]
|
18
18
|
assert_equal "x=1000 y=6000 z=2000", f[6000]
|
19
|
-
|
19
|
+
|
20
20
|
f = lambda{|x,y,z| "x=#{x} y=#{y} z=#{z}"}
|
21
21
|
f = Flt::Solver::Function[f, :x=>1000, :z=>2000]
|
22
22
|
assert_equal "x=1000 y=5000 z=2000", f[5000]
|
23
23
|
assert_equal "x=1000 y=6000 z=2000", f[6000]
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
data/test/test_psolver.rb
CHANGED
@@ -4,20 +4,20 @@ require 'flt/tolerance'
|
|
4
4
|
|
5
5
|
include Flt
|
6
6
|
|
7
|
-
class TestPSolver <
|
8
|
-
|
7
|
+
class TestPSolver < MiniTest::Unit::TestCase
|
8
|
+
|
9
9
|
context "The PSolver class" do
|
10
|
-
|
10
|
+
|
11
11
|
context "using Float arithmetic" do
|
12
|
-
|
12
|
+
|
13
13
|
setup do
|
14
14
|
@context = Float.context
|
15
15
|
@tolerance = Flt.Tolerance(3,:decimals)
|
16
16
|
@delta = 5E-4
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
context "with a TVM-equation definition" do
|
20
|
-
|
20
|
+
|
21
21
|
setup do
|
22
22
|
@context.class.class_eval do
|
23
23
|
define_method :lnp1 do |x|
|
@@ -35,7 +35,7 @@ class TestPSolver < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
@tvm.default_guesses = 1,2
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
should "solve for :pmt correctly" do
|
40
40
|
solution = @tvm.root :pmt, :t=>240, :m0=>10000, :m=>0, :i=>3, :p=>12 #, :pmt=>[1,2]
|
41
41
|
assert_in_delta @context.Num('-55.45975978539105'), solution, @delta
|
@@ -45,11 +45,11 @@ class TestPSolver < Test::Unit::TestCase
|
|
45
45
|
solution = @tvm.root :t, :pmt=>@context.Num('-55.45975978539105'), :m0=>10000, :m=>0, :i=>3, :p=>12 #, :pmt=>[1,2]
|
46
46
|
assert_in_delta 240, solution, @delta
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
end
|
data/test/test_rfsecant.rb
CHANGED
@@ -4,18 +4,18 @@ require 'flt/tolerance'
|
|
4
4
|
|
5
5
|
include Flt
|
6
6
|
|
7
|
-
class TestRFSecant <
|
8
|
-
|
7
|
+
class TestRFSecant < MiniTest::Unit::TestCase
|
8
|
+
|
9
9
|
context "The Regula-Falsi/Secant Solver" do
|
10
|
-
|
10
|
+
|
11
11
|
context "using Float arithmetic" do
|
12
|
-
|
12
|
+
|
13
13
|
setup do
|
14
14
|
@context = Float.context
|
15
15
|
@tolerance = Flt.Tolerance(3,:decimals)
|
16
16
|
@delta = 5E-4
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should "solve equations" do
|
20
20
|
solver = Flt::Solver::RFSecantSolver.new(@context, [0.0, 100.0], @tolerance) do |x|
|
21
21
|
2*x+11.0
|
@@ -23,7 +23,7 @@ class TestRFSecant < Test::Unit::TestCase
|
|
23
23
|
assert_in_delta -5.5, solver.root, @delta
|
24
24
|
assert_in_delta -5.5, solver.root(5.0), @delta
|
25
25
|
assert_in_delta -5.5, solver.root(6.0), @delta
|
26
|
-
|
26
|
+
|
27
27
|
solver = Flt::Solver::SecantSolver.new(@context, [0.0, 10.0], @tolerance) do |x|
|
28
28
|
y = 2
|
29
29
|
y*exp(x)-10
|
@@ -35,13 +35,13 @@ class TestRFSecant < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context "using DecNum arithmetic" do
|
38
|
-
|
38
|
+
|
39
39
|
setup do
|
40
40
|
@context = Flt::DecNum.context(:precision=>12)
|
41
41
|
@tolerance = Flt.Tolerance(5,:decimals)
|
42
42
|
@delta = @tolerance.value
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should "solve equations" do
|
46
46
|
solver = Flt::Solver::RFSecantSolver.new(@context, [0, 100].map{|v| @context.Num(v)}, @tolerance) do |x|
|
47
47
|
2*x+11
|
@@ -49,7 +49,7 @@ class TestRFSecant < Test::Unit::TestCase
|
|
49
49
|
assert_in_delta @context.Num('-5.5'), solver.root, @delta
|
50
50
|
assert_in_delta @context.Num('-5.5'), solver.root(5), @delta
|
51
51
|
assert_in_delta @context.Num('-5.5'), solver.root(6), @delta
|
52
|
-
|
52
|
+
|
53
53
|
solver = Flt::Solver::SecantSolver.new(@context, [0, 10].map{|v| @context.Num(v)}, @tolerance) do |x|
|
54
54
|
y = 2
|
55
55
|
y*exp(x)-10
|
@@ -58,9 +58,9 @@ class TestRFSecant < Test::Unit::TestCase
|
|
58
58
|
assert_in_delta @context.Num('1.6094389956808506'), solver.root(1), @delta
|
59
59
|
assert_in_delta @context.Num('1.6094389956808506'), solver.root(2), @delta
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
data/test/test_secant.rb
CHANGED
@@ -4,18 +4,18 @@ require 'flt/tolerance'
|
|
4
4
|
|
5
5
|
include Flt
|
6
6
|
|
7
|
-
class TestSecant <
|
8
|
-
|
7
|
+
class TestSecant < MiniTest::Unit::TestCase
|
8
|
+
|
9
9
|
context "The Secant Solver" do
|
10
|
-
|
10
|
+
|
11
11
|
context "using Float arithmetic" do
|
12
|
-
|
12
|
+
|
13
13
|
setup do
|
14
14
|
@context = Float.context
|
15
15
|
@tolerance = Flt.Tolerance(3,:decimals)
|
16
16
|
@delta = 5E-4
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should "solve equations" do
|
20
20
|
solver = Flt::Solver::SecantSolver.new(@context, [0.0, 100.0], @tolerance) do |x|
|
21
21
|
2*x+11.0
|
@@ -23,7 +23,7 @@ class TestSecant < Test::Unit::TestCase
|
|
23
23
|
assert_in_delta -5.5, solver.root, @delta
|
24
24
|
assert_in_delta -5.5, solver.root(5.0), @delta
|
25
25
|
assert_in_delta -5.5, solver.root(6.0), @delta
|
26
|
-
|
26
|
+
|
27
27
|
solver = Flt::Solver::SecantSolver.new(@context, [0.0, 10.0], @tolerance) do |x|
|
28
28
|
y = 2
|
29
29
|
y*exp(x)-10
|
@@ -35,13 +35,13 @@ class TestSecant < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context "using DecNum arithmetic" do
|
38
|
-
|
38
|
+
|
39
39
|
setup do
|
40
40
|
@context = Flt::DecNum.context(:precision=>12)
|
41
41
|
@tolerance = Flt.Tolerance(5,:decimals)
|
42
42
|
@delta = @tolerance.value
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should "solve equations" do
|
46
46
|
solver = Flt::Solver::SecantSolver.new(@context, [0, 100].map{|v| @context.Num(v)}, @tolerance) do |x|
|
47
47
|
2*x+11
|
@@ -49,7 +49,7 @@ class TestSecant < Test::Unit::TestCase
|
|
49
49
|
assert_in_delta @context.Num('-5.5'), solver.root, @delta
|
50
50
|
assert_in_delta @context.Num('-5.5'), solver.root(5), @delta
|
51
51
|
assert_in_delta @context.Num('-5.5'), solver.root(6), @delta
|
52
|
-
|
52
|
+
|
53
53
|
solver = Flt::Solver::SecantSolver.new(@context, [0, 10].map{|v| @context.Num(v)}, @tolerance) do |x|
|
54
54
|
y = 2
|
55
55
|
y*exp(x)-10
|
@@ -58,9 +58,9 @@ class TestSecant < Test::Unit::TestCase
|
|
58
58
|
assert_in_delta @context.Num('1.6094389956808506'), solver.root(1), @delta
|
59
59
|
assert_in_delta @context.Num('1.6094389956808506'), solver.root(2), @delta
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
data/test/test_tvm.rb
CHANGED
@@ -4,19 +4,19 @@ require 'flt/tolerance'
|
|
4
4
|
|
5
5
|
include Flt
|
6
6
|
|
7
|
-
class TestTVM <
|
8
|
-
|
7
|
+
class TestTVM < MiniTest::Unit::TestCase
|
8
|
+
|
9
9
|
context "The TVM class" do
|
10
|
-
|
10
|
+
|
11
11
|
context "using Float arithmetic" do
|
12
|
-
|
12
|
+
|
13
13
|
setup do
|
14
14
|
@context = Float.context
|
15
15
|
@tolerance = Flt.Tolerance(2,:decimals)
|
16
|
-
@delta = 5E-3
|
16
|
+
@delta = 5E-3
|
17
17
|
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
should "solve correclty for :pmt" do
|
21
21
|
sol = @tvm.solve(:t=>240, :m0=>10000, :m=>0, :i=>3, :p=>12)
|
22
22
|
assert_equal [:pmt], sol.keys
|
@@ -28,7 +28,7 @@ class TestTVM < Test::Unit::TestCase
|
|
28
28
|
assert_equal [:t], sol.keys
|
29
29
|
assert_in_delta 240, sol[:t], @delta
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should "solve correclty for :m" do
|
33
33
|
sol = @tvm.solve(:t=>63, :m0=>0, :pmt=>-1000000, :i=>@context.Num('0.00000161')*12, :p=>12)
|
34
34
|
assert_equal [:m], sol.keys
|
@@ -39,17 +39,17 @@ class TestTVM < Test::Unit::TestCase
|
|
39
39
|
assert_equal [:m], sol.keys
|
40
40
|
assert_in_delta @context.Num('331667.006691'), sol[:m], @delta
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
end
|
46
46
|
|
47
47
|
context "using DecNum arithmetic" do
|
48
|
-
|
48
|
+
|
49
49
|
setup do
|
50
50
|
@context = Flt::DecNum.context
|
51
51
|
@tolerance = Flt.Tolerance(3,:decimals)
|
52
|
-
@delta = @context.Num('5E-4')
|
52
|
+
@delta = @context.Num('5E-4')
|
53
53
|
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
54
54
|
end
|
55
55
|
|
@@ -69,20 +69,20 @@ class TestTVM < Test::Unit::TestCase
|
|
69
69
|
sol = @tvm.solve(:t=>63, :m0=>0, :pmt=>-1000000, :i=>@context.Num('0.00000161')*12, :p=>12)
|
70
70
|
assert_equal [:m], sol.keys
|
71
71
|
assert_in_delta @context.Num('63000031.4433'), sol[:m], @delta
|
72
|
-
|
72
|
+
|
73
73
|
n = 31536000
|
74
74
|
sol = @tvm.solve(:t=>n, :m0=>0, :pmt=>-@context.Num('0.01'), :i=>@context.Num(10)/n, :p=>1)
|
75
75
|
assert_equal [:m], sol.keys
|
76
76
|
assert_in_delta @context.Num('331667.006691'), sol[:m], @delta
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
context "and high precision" do
|
80
80
|
setup do
|
81
81
|
@context.precision = 28
|
82
82
|
@tolerance = Tolerance(12, :sig_decimals)
|
83
|
-
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
83
|
+
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
should "solve correclty for :pmt" do
|
87
87
|
sol = @tvm.solve(:t=>240, :m0=>10000, :m=>0, :i=>3, :p=>12)
|
88
88
|
assert_equal [:pmt], sol.keys
|
@@ -109,7 +109,7 @@ class TestTVM < Test::Unit::TestCase
|
|
109
109
|
expected = @context.Num('331667.006691')
|
110
110
|
assert_in_delta expected, sol[:m], @tolerance.value(expected)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
metadata
CHANGED
@@ -1,66 +1,98 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: solver
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Javier Goizueta
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
22
35
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
26
45
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
31
48
|
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: flt
|
35
49
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
39
52
|
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda-context
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This numeric solver is an example of the use of Flt.
|
84
|
+
email:
|
85
|
+
- jgoizueta@gmail.com
|
50
86
|
executables: []
|
51
|
-
|
52
87
|
extensions: []
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
|
58
|
-
- .document
|
59
|
-
- .gitignore
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".document"
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
60
93
|
- LICENSE
|
61
94
|
- README.rdoc
|
62
95
|
- Rakefile
|
63
|
-
- VERSION
|
64
96
|
- lib/solver.rb
|
65
97
|
- lib/solver/base.rb
|
66
98
|
- lib/solver/function.rb
|
@@ -68,6 +100,7 @@ files:
|
|
68
100
|
- lib/solver/rfsecant.rb
|
69
101
|
- lib/solver/secant.rb
|
70
102
|
- lib/solver/tvm.rb
|
103
|
+
- lib/solver/version.rb
|
71
104
|
- solver.gemspec
|
72
105
|
- test/helper.rb
|
73
106
|
- test/test_function.rb
|
@@ -75,43 +108,31 @@ files:
|
|
75
108
|
- test/test_rfsecant.rb
|
76
109
|
- test/test_secant.rb
|
77
110
|
- test/test_tvm.rb
|
78
|
-
- test/chk.rb
|
79
|
-
has_rdoc: true
|
80
111
|
homepage: http://github.com/jgoizueta/solver
|
81
|
-
licenses:
|
82
|
-
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
83
115
|
post_install_message:
|
84
|
-
rdoc_options:
|
85
|
-
|
86
|
-
require_paths:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
87
118
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
- 9
|
96
|
-
- 1
|
97
|
-
version: 1.9.1
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.9.2
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
101
126
|
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
- 0
|
105
|
-
version: "0"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
106
129
|
requirements: []
|
107
|
-
|
108
130
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.2.2
|
110
132
|
signing_key:
|
111
|
-
specification_version:
|
112
|
-
summary: Numeric
|
113
|
-
test_files:
|
114
|
-
- test/chk.rb
|
133
|
+
specification_version: 4
|
134
|
+
summary: Numeric Solver using Flt
|
135
|
+
test_files:
|
115
136
|
- test/helper.rb
|
116
137
|
- test/test_function.rb
|
117
138
|
- test/test_psolver.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.1
|
data/test/chk.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'helper'))
|
2
|
-
require 'flt/float'
|
3
|
-
require 'flt/tolerance'
|
4
|
-
|
5
|
-
include Flt
|
6
|
-
|
7
|
-
@context = Float.context
|
8
|
-
@tolerance = Flt.Tolerance(3,:decimals)
|
9
|
-
@delta = 5E-4
|
10
|
-
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
11
|
-
|
12
|
-
puts "-----------------"
|
13
|
-
|
14
|
-
sol = @tvm.solve(:t=>63, :m0=>0, :pmt=>-1000000, :i=>@context.Num('0.00000161')*12, :p=>12)
|
15
|
-
puts sol.inspect
|
16
|
-
|
17
|
-
puts "-----------------"
|
18
|
-
n = 31536000
|
19
|
-
sol = @tvm.solve(:t=>n, :m0=>0, :pmt=>-@context.Num('0.01'), :i=>@context.Num(10)/n, :p=>1)
|
20
|
-
puts sol.inspect
|
21
|
-
|
22
|
-
puts "-----------------"
|
23
|
-
@tvm = Flt::Solver::TVM.new(@tolerance, @context)
|
24
|
-
n = 31536000
|
25
|
-
sol = @tvm.solve(:t=>n, :m0=>0, :pmt=>-@context.Num('0.01'), :i=>@context.Num(10)/n, :p=>1)
|
26
|
-
puts sol.inspect
|