calculose 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/calculose.gemspec +20 -0
- data/lib/.DS_Store +0 -0
- data/lib/calculose.rb +46 -0
- data/lib/calculose/version.rb +3 -0
- data/spec/calculose_spec.rb +11 -0
- metadata +73 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dan Ruswick
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Calculose
|
2
|
+
|
3
|
+
The Calculose gem implements two methods for estimating the value of an antiderivative over an interval. The gem implements two methods: [Simpsons's Method](http://en.wikipedia.org/wiki/Simpson's_rule) and [Euler's Method](http://en.wikipedia.org/wiki/Euler_method). This gem was the product of frustration at the monotonous nature of summing integrals, and the unwieldily interfaces and UXs on most graphing calculators.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'calculose'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install calculose
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Simpson's can be called thusly:
|
22
|
+
|
23
|
+
Calculose::Calc.simpson(deltaX, startingX, endingX) do |x| f(x) end
|
24
|
+
|
25
|
+
where f(x) is the base function.
|
26
|
+
|
27
|
+
|
28
|
+
Euler's can be called thusly:
|
29
|
+
|
30
|
+
Calculose::Calc.euler(deltaX, startingX, startingY, endingX) do |x,y| f(x) end
|
31
|
+
|
32
|
+
Note that **both x and y** are passed to the block by the function.
|
33
|
+
|
34
|
+
##To do
|
35
|
+
|
36
|
+
* CLI
|
37
|
+
* More algorithms
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/calculose.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'calculose/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "calculose"
|
8
|
+
gem.version = Calculose::VERSION
|
9
|
+
gem.authors = ["Dan Ruswick"]
|
10
|
+
gem.email = ["orzogen@gmail.com"]
|
11
|
+
gem.description = "A handful of algorithms for estimating antiderivative values."
|
12
|
+
gem.homepage = "http://orzogen.github.com/calculose"
|
13
|
+
gem.summary = "Summing algorithms."
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency "rspec", "~> 2.6"
|
20
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/calculose.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "calculose/version"
|
2
|
+
|
3
|
+
module Calculose
|
4
|
+
class Calc
|
5
|
+
def self.euler deltaX, xInit, yInit, xToFind
|
6
|
+
x = xInit
|
7
|
+
y = yInit
|
8
|
+
iterator = 0
|
9
|
+
iterations = ((xToFind - xInit)/ deltaX).round
|
10
|
+
|
11
|
+
while iterator < iterations do
|
12
|
+
y += (deltaX * yield(x,y))
|
13
|
+
x += deltaX
|
14
|
+
iterator += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
return (y * 1000.0).round/1000.0
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.simpson deltaX, xInit, xEnd
|
21
|
+
|
22
|
+
iterations = ((xEnd - xInit)/deltaX).round
|
23
|
+
if iterations % 2 != 0 then iterations += 1 end
|
24
|
+
|
25
|
+
area = 0
|
26
|
+
area =+ yield(xInit)
|
27
|
+
|
28
|
+
(1..iterations-1).each do |x|
|
29
|
+
y = yield(deltaX * x)
|
30
|
+
|
31
|
+
if x.odd?
|
32
|
+
y *= 4
|
33
|
+
else
|
34
|
+
y *= 2
|
35
|
+
end
|
36
|
+
|
37
|
+
area += y
|
38
|
+
end
|
39
|
+
|
40
|
+
area += yield(xEnd)
|
41
|
+
|
42
|
+
return area * deltaX / 3
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "calculose"
|
2
|
+
|
3
|
+
describe Calculose::Calc do
|
4
|
+
it "simpson's computes correctly" do
|
5
|
+
(Calculose::Calc.simpson 0.01, 0, 5 do |x| 2*x end).should eql(25.0)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "euler's computes correctly" do
|
9
|
+
(Calculose::Calc.euler 0.01, 0,0, 5 do |x,y| 2*x end).should eql(24.95)
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: calculose
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Ruswick
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.6'
|
30
|
+
description: A handful of algorithms for estimating antiderivative values.
|
31
|
+
email:
|
32
|
+
- orzogen@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .DS_Store
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- calculose.gemspec
|
44
|
+
- lib/.DS_Store
|
45
|
+
- lib/calculose.rb
|
46
|
+
- lib/calculose/version.rb
|
47
|
+
- spec/calculose_spec.rb
|
48
|
+
homepage: http://orzogen.github.com/calculose
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.24
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Summing algorithms.
|
72
|
+
test_files:
|
73
|
+
- spec/calculose_spec.rb
|