symbolic 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README +25 -1
- data/Rakefile +1 -1
- data/lib/symbolic.rb +2 -1
- metadata +1 -1
data/.gitignore
CHANGED
data/README
CHANGED
@@ -1 +1,25 @@
|
|
1
|
-
Symbolic math for ruby.
|
1
|
+
Symbolic math for ruby.
|
2
|
+
|
3
|
+
Available as gem from gemcutter: gem install symbolic
|
4
|
+
|
5
|
+
Simple example:
|
6
|
+
|
7
|
+
Symbolic.enabled = true
|
8
|
+
|
9
|
+
x = var :name => 'x'
|
10
|
+
y = var :name => 'y'
|
11
|
+
|
12
|
+
f = (4 - 2*(-x) + y*(-1.0))*x - 0*y + 0 - 2
|
13
|
+
g = Math.cos(y)
|
14
|
+
|
15
|
+
puts f # => (4+2*x-y)*x-2
|
16
|
+
|
17
|
+
p f.undefined_variables.map &:name # => ["x", "y"]
|
18
|
+
x.value = 2
|
19
|
+
y.value = 4
|
20
|
+
|
21
|
+
puts f.value # => 6
|
22
|
+
|
23
|
+
puts g # => cos(y)
|
24
|
+
y.value = 0
|
25
|
+
puts g.value # => 1.0
|
data/Rakefile
CHANGED
data/lib/symbolic.rb
CHANGED
@@ -176,7 +176,7 @@ module Symbolic
|
|
176
176
|
end
|
177
177
|
|
178
178
|
class Variable < Operatable
|
179
|
-
attr_accessor :value
|
179
|
+
attr_accessor :value, :name
|
180
180
|
|
181
181
|
@@index = 0
|
182
182
|
|
@@ -200,6 +200,7 @@ module Symbolic
|
|
200
200
|
|
201
201
|
class Expression < Operatable
|
202
202
|
def initialize(var1, var2, operation)
|
203
|
+
var1, var2 = var2, var1 if operation == '*' && var2.is_a?(Numeric)
|
203
204
|
@var1, @var2, @operation = var1, var2, operation
|
204
205
|
end
|
205
206
|
|