mathpack 0.0.7 → 0.1.0
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/README.md +33 -6
- data/lib/mathpack/equation.rb +14 -0
- data/lib/{statistics.rb → mathpack/statistics.rb} +0 -0
- data/lib/mathpack/version.rb +1 -1
- data/lib/mathpack.rb +2 -1
- data/spec/equation_spec.rb +14 -0
- data/spec/statistics_spec.rb +2 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2feda03bce968d1a492dd5c6cfa99bfe1d8796c
|
4
|
+
data.tar.gz: 6b4908827c465f97ca042c266a393e8fb572ee94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e013b0cb1cb1339ca1b2572593b8d77dea7d4b11f678675a199125595b682f559a651d3d1ab807bb346e42084997b234bb1f969f503434be0ec5f69073adf6aa
|
7
|
+
data.tar.gz: 56d13a5f3c6fea715fa823e21197ef368d4591f5d3b83c250d56174d122d762a1cf81e1446788a9d2a7e054f1e5cc21d300555844d54c265ea506de758e10055
|
data/README.md
CHANGED
@@ -18,7 +18,8 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install mathpack
|
20
20
|
## Information
|
21
|
-
Gem `mathpack` allows to count statistical functions
|
21
|
+
Gem `mathpack` allows to count statistical functions through `Statistics` class, solving nonlinear equations through `Equation` module
|
22
|
+
`solve` method
|
22
23
|
## Statistics
|
23
24
|
`Statistics` class have following methods
|
24
25
|
- **number** - returns a number of elements in series
|
@@ -32,20 +33,20 @@ Gem `mathpack` allows to count statistical functions throught `Statistics` class
|
|
32
33
|
- **central_moment** - returns the *nth* central moment of series
|
33
34
|
- **empirical_cdf** - returns *empirical distribution function* value in some point
|
34
35
|
- **empirical_pdf** - returns *empirical probability density function* value in some point
|
35
|
-
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf
|
36
|
-
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf
|
36
|
+
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf line chart values to `.csv` file with name *filename*
|
37
|
+
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf line chart values to `.csv` file with name *filename*
|
37
38
|
|
38
|
-
|
39
|
+
### Usage
|
39
40
|
```ruby
|
40
41
|
stat = Mathpack::Statistics.new([1, 2, 5, 6])
|
41
42
|
stat.number() #=> 4
|
42
43
|
stat.mean() #=> 3.5
|
43
|
-
stat.variance() #=> 4.25
|
44
|
+
stat.variance() #=> 4.25
|
44
45
|
stat.kurtosis() #=> 1.221453287197232
|
45
46
|
stat.skewness() #=> 0.0
|
46
47
|
stat.min() #=> 1
|
47
48
|
stat.max() #=> 6
|
48
|
-
stat.raw_moment(3) #=> 87.5
|
49
|
+
stat.raw_moment(3) #=> 87.5
|
49
50
|
stat.central_moment(4) #=> 22.0625
|
50
51
|
stat.empirical_cdf(5.5) #=> 0.75
|
51
52
|
stat.empirical_pdf(3) #=> 0.07639393483317147
|
@@ -53,6 +54,32 @@ stat.print_empirical_cdf_to_csv('cdf.csv') #=> nil
|
|
53
54
|
stat.print_empirical_pdf_to_csv('pdf.csv') #=> nil
|
54
55
|
```
|
55
56
|
|
57
|
+
##Equation
|
58
|
+
`Equation` module has only one method
|
59
|
+
- **solve** - method, which allows to solve *nonlinear equations*. Neccessary params are `eps` representing calculations accuraccy and `start` representing point to start root search
|
60
|
+
|
61
|
+
###Usage
|
62
|
+
Now you have no problems solving **nonlinear equations**. If you want, for example, to solve equation 
|
63
|
+
|
64
|
+
You need to complete the following steps:
|
65
|
+
1. Equation should look like
|
66
|
+

|
67
|
+
2. For our equation 
|
68
|
+
3. Choose the calculations accurracy. For example 
|
69
|
+
4. Choose some point near the expected root of equation. For example 
|
70
|
+
|
71
|
+
Then to solve equation you should call
|
72
|
+
```ruby
|
73
|
+
Mathpack::Equation.solve(start: 0, eps: 0.00001){|x| x**2 - Math.sin(x+1)})
|
74
|
+
```
|
75
|
+
Here is some examples of **solve** function usage
|
76
|
+
```ruby
|
77
|
+
Mathpack::Equation.solve(start: 0, eps: 0.00001){|x| x**2 - Math.sin(x+1)})
|
78
|
+
Mathpack::Equation.solve(start: 0.01, eps: 0.00001){|x| 1/x - Math.log(x)})
|
79
|
+
Mathpack::Equation.solve(start: 0.01, eps: 0.00001){|x| x**2 - 2*x + 1})
|
80
|
+
Mathpack::Equation.solve(start: 0.01, eps: 0.00001){|x| Math.exp(x-2) - Math.sin(x)})
|
81
|
+
```
|
82
|
+
|
56
83
|
## Contributing
|
57
84
|
|
58
85
|
1. Fork it ( https://github.com/[my-github-username]/mathpack/fork )
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mathpack
|
2
|
+
module Equation
|
3
|
+
def self.solve(param = {}, &function)
|
4
|
+
derivate_eps = 1e-5
|
5
|
+
xk1 = param[:start]
|
6
|
+
loop do
|
7
|
+
xk = xk1
|
8
|
+
xk1 = xk - function.call(xk)/((function.call(xk + derivate_eps) - function.call(xk - derivate_eps))/(2*derivate_eps))
|
9
|
+
break if (xk1 - xk).abs < param[:eps]
|
10
|
+
end
|
11
|
+
return xk1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
data/lib/mathpack/version.rb
CHANGED
data/lib/mathpack.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
describe 'Equations' do
|
2
|
+
require 'mathpack/equation'
|
3
|
+
|
4
|
+
context 'calculate nonlinear equations' do
|
5
|
+
|
6
|
+
it 'should solve equation' do
|
7
|
+
eps = 0.00001
|
8
|
+
expect(Mathpack::Equation.solve(start: 0, eps: eps){|x| x**2 - Math.sin(x+1)}).to be_between(-0.613763 - eps, -0.613763 + eps)
|
9
|
+
expect(Mathpack::Equation.solve(start: 0.01, eps: eps){|x| 1/x - Math.log(x)}).to be_between(1.76322 - eps, 1.76322 + eps)
|
10
|
+
expect(Mathpack::Equation.solve(start: 0.01, eps: eps){|x| x**2 - 2*x + 1}).to be_between(1.0 - eps, 1.0 + eps)
|
11
|
+
expect(Mathpack::Equation.solve(start: 0.01, eps: eps){|x| Math.exp(x-2) - Math.sin(x)}).to be_between(0.159396 - eps, 0.159396 + eps)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/statistics_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Statistics' do
|
2
|
-
require 'statistics'
|
2
|
+
require 'mathpack/statistics'
|
3
3
|
|
4
|
-
|
4
|
+
describe "calculated statistics functions" do
|
5
5
|
|
6
6
|
let(:data) { [1,5,4,2,3,4,5,7,2,7] }
|
7
7
|
let(:stat) { Mathpack::Statistics.new(data) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mathpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxmilan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,9 +52,11 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- lib/mathpack.rb
|
55
|
+
- lib/mathpack/equation.rb
|
56
|
+
- lib/mathpack/statistics.rb
|
55
57
|
- lib/mathpack/version.rb
|
56
|
-
- lib/statistics.rb
|
57
58
|
- mathpack.gemspec
|
59
|
+
- spec/equation_spec.rb
|
58
60
|
- spec/statistics_spec.rb
|
59
61
|
homepage: ''
|
60
62
|
licenses:
|
@@ -81,4 +83,5 @@ signing_key:
|
|
81
83
|
specification_version: 4
|
82
84
|
summary: Summary
|
83
85
|
test_files:
|
86
|
+
- spec/equation_spec.rb
|
84
87
|
- spec/statistics_spec.rb
|