ChebyRuby 0.0.2.pre → 0.0.3.pre
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.
- checksums.yaml +4 -4
- data/lib/chebyruby/expression.rb +43 -0
- data/lib/chebyruby/univariate_function.rb +2 -1
- data/lib/chebyruby/variable.rb +64 -0
- data/test/test_integration.rb +16 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a3b71091027ccab487114bd6bbdeb2dd47dddce
|
4
|
+
data.tar.gz: 9545f1e34a6e515bdb9343e893852a1acb3b1b10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de743407a61d1199cea8a825a94a8f83f29c78bb34419cbb07195c74fc37faf74293432d7d13c50106921d4e8266d368cdb372a1e3061bb89fb27c477583be6
|
7
|
+
data.tar.gz: a509277ec4e7dec53edd9d78fe3d9b8bfe4df9d3a3516147d419f9832166f891d3e1e1dc10bb7b8dd411f6367430d48d9c546529b60e153b35005191b027273c
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# require_relative 'univariate_function'
|
2
|
+
|
3
|
+
class Expression
|
4
|
+
attr_accessor :left, :op, :right
|
5
|
+
|
6
|
+
def initialize(left, op, right)
|
7
|
+
@left = left
|
8
|
+
@op = op
|
9
|
+
@right = right
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method, *args)
|
13
|
+
Expression.new(self, method, Variable.new(args[0]))
|
14
|
+
end
|
15
|
+
|
16
|
+
def vars
|
17
|
+
a = []
|
18
|
+
nested?[:left] ? a << left.vars : a << left.x
|
19
|
+
nested?[:right] ? a << right.vars : a << right.x
|
20
|
+
a.flatten
|
21
|
+
end
|
22
|
+
|
23
|
+
def nested?
|
24
|
+
{:right => (Expression === right),
|
25
|
+
:left => (Expression === left)}
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
if nested?[:left]
|
30
|
+
s = "#{left.to_s} #{op}"
|
31
|
+
else
|
32
|
+
s = "#{left} #{op}"
|
33
|
+
end
|
34
|
+
case right
|
35
|
+
when Variable then "#{s} #{right.x}".strip
|
36
|
+
when Expression then "#{s} #{right.to_s}".strip
|
37
|
+
else "#{s} #{right}".strip
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_func
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative 'expression'
|
2
|
+
|
3
|
+
class Variable
|
4
|
+
attr_accessor :x, :neg
|
5
|
+
|
6
|
+
def initialize(x)
|
7
|
+
@x = x
|
8
|
+
@neg = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args)
|
12
|
+
Expression.new(self, method, Variable.new(args[0]))
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_a
|
16
|
+
if x.class == Array
|
17
|
+
x
|
18
|
+
else
|
19
|
+
[x]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def -@
|
24
|
+
@neg = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_enum
|
28
|
+
Array.new(to_ary).to_enum
|
29
|
+
end
|
30
|
+
|
31
|
+
def right
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
"#{x}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def parseable
|
40
|
+
to_enum.map do |i|
|
41
|
+
if Array === i
|
42
|
+
i.parseable
|
43
|
+
elsif Symbol === i
|
44
|
+
i
|
45
|
+
else
|
46
|
+
i.x
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
alias to_ary to_a
|
52
|
+
end
|
53
|
+
|
54
|
+
class Array
|
55
|
+
def parseable
|
56
|
+
Variable.new(self).parseable
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Symbol
|
61
|
+
def parseable
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'chebyruby'
|
3
|
+
|
4
|
+
class TestIntegration < Minitest::Test
|
5
|
+
include ChebyRuby::Integration
|
6
|
+
def setup
|
7
|
+
@sin = ChebyRuby::UnivariateFunction.new {|x| Math.sin(x)}
|
8
|
+
@exp = ChebyRuby::UnivariateFunction.new {|x| Math.exp(x)}
|
9
|
+
@pol = ChebyRuby::UnivariateFunction.new {|x| x**2 + 2*x + 1}
|
10
|
+
@x = ChebyRuby::UnivariateFunction.new {|x| x}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_integration
|
14
|
+
assert_in_delta 0, trap_integrate(@sin, 0, Math::PI * 2), 1e-8
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ChebyRuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Sadoff
|
@@ -20,12 +20,15 @@ files:
|
|
20
20
|
- bin/chebyruby
|
21
21
|
- lib/chebyruby.rb
|
22
22
|
- lib/chebyruby/differentiation.rb
|
23
|
+
- lib/chebyruby/expression.rb
|
23
24
|
- lib/chebyruby/finite_differencing.rb
|
24
25
|
- lib/chebyruby/integration.rb
|
25
26
|
- lib/chebyruby/romberg_integration.rb
|
26
27
|
- lib/chebyruby/simpsons_integration.rb
|
27
28
|
- lib/chebyruby/univariate_function.rb
|
29
|
+
- lib/chebyruby/variable.rb
|
28
30
|
- test/test_function.rb
|
31
|
+
- test/test_integration.rb
|
29
32
|
homepage: https://github.com/snood1205/chebyruby
|
30
33
|
licenses:
|
31
34
|
- MIT
|
@@ -46,10 +49,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
49
|
version: '0'
|
47
50
|
requirements: []
|
48
51
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
52
|
+
rubygems_version: 2.6.6
|
50
53
|
signing_key:
|
51
54
|
specification_version: 4
|
52
55
|
summary: A gem for numerical analysis and scientific computing.This is a pre-release
|
53
56
|
so beware.
|
54
57
|
test_files:
|
55
58
|
- test/test_function.rb
|
59
|
+
- test/test_integration.rb
|