mathpack 0.4.9 → 0.5.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 +13 -5
- data/.travis.yml +17 -7
- data/README.md +48 -48
- data/lib/mathpack/functions.rb +1 -1
- data/lib/mathpack/statistics.rb +10 -15
- data/lib/mathpack/version.rb +1 -1
- data/mathpack.gemspec +1 -1
- data/spec/sle_spec.rb +3 -3
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDY4OTU2ZDNlZGQwMTAyM2U2M2I3NjA4NzU1MDQ5ZGM4OGY5OGRmOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjRiMjFkYTdmMTc5YjJlZTRhMTk5MzUyZWJkMWJkYmY4OWU0MmVjMg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGJhMzY1N2ViM2ZmZWM3MWM3ZDU2YmVlMDllN2M5NGJiMGQ4YmM4NTdjOTUx
|
10
|
+
MDFjZjc0NWYyNDM4ZGU4ZjA4ZWQ5OTM1NGM1Zjk5ZGNiNzdiZWFjYjFiOGEx
|
11
|
+
OWQ2ZmMzZjNlMWE4ZmI3YzAzOWUzZmI5ZDBmODMxYTM4YjdkNjY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjczOGM0NTJjZTEzMmIzYTUyZjg5OWMxY2IzOTM3ODE4ZjQ2N2MyNTc1MWUx
|
14
|
+
NDQ1OGFmM2M1NTBhNGRkOWU5OTZlYTMzYzEwYjQ1YjVmZGRiNjJmMzg0ODgx
|
15
|
+
MzI0ODMxM2I2ZWZjZGE0ZjY3M2NmZGNmZmJiOWI4ZTM5MWQ3ZWU=
|
data/.travis.yml
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
language:
|
1
|
+
language: ruby
|
2
2
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
script:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.2
|
5
|
+
- 2.1.3
|
6
|
+
- 2.2.0
|
7
|
+
- 2.3.0
|
8
|
+
script: bundle exec rspec
|
9
|
+
before_install:
|
10
|
+
- gem update bundler
|
11
|
+
deploy:
|
12
|
+
provider: rubygems
|
13
|
+
api_key:
|
14
|
+
secure: O7YI3MNFgWH9xrjpTaYu6zvfhgpgQrMQullQebWR9B7sHXUw69XRW4mSy6PdsAHhFddymmfIWBW1rqS5HhiO7I50r/o/S90Oqy2vftQ3Fm8EXhKywc60r6o60EUOiqw/QObnqT/yspX0PpJ4uGlkDpc6XoDY/01QvhvoK13TnS4=
|
15
|
+
gem: mathpack
|
16
|
+
on:
|
17
|
+
branch: master
|
18
|
+
repo: maxmilan/mathpack
|
9
19
|
notifications:
|
10
20
|
email: false
|
data/README.md
CHANGED
@@ -20,16 +20,16 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Information
|
22
22
|
`Mathpack` includes following modules:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
* [SLE](#sle). Solves system of linear equations
|
24
|
+
* [Statistics](#statistics). Provides methods to analyze data samples
|
25
|
+
* [Functions](#functions). Collects mathematical functions
|
26
|
+
* [Approximation](#approximation). Allows to approximate table and analytical functions by polynom
|
27
|
+
* [NonlinearEquations](#nonlinearequations). Solves nonlinear mathematical equations
|
28
|
+
* [IntegralEquations](#integralequations). Solves integral second order Fredholm and Volter equations
|
29
|
+
* [DifferentialEquations](#differentialequations). Solves system of differential equations with left border initial conditions
|
30
|
+
* [Integration](#integration). Integrates functions
|
31
|
+
* [IO](#io). Prints data
|
32
|
+
* [Functional](#functional). Lambda functions
|
33
33
|
|
34
34
|
## Statistics
|
35
35
|
`Statistics` class have following methods
|
@@ -98,14 +98,14 @@ stat.trend(polynom_power: 1) #=> 1.7999999999999996*x - 0.9999999999999987
|
|
98
98
|
#### solve(params = {})
|
99
99
|
returns solution of nonlinear equation.
|
100
100
|
##### Parameters
|
101
|
-
|
102
|
-
|
101
|
+
* ***start*** - point to start iteration process
|
102
|
+
* ***eps*** - calculations accuraccy
|
103
103
|
|
104
104
|
### Usage
|
105
105
|
Now you have no problems solving nonlinear equations. If you want, for example, to solve equation 
|
106
106
|
|
107
107
|
You need to complete the following steps:
|
108
|
-
- Equation should look like 
|
109
109
|
- For our equation 
|
110
110
|
- Choose the calculations accurracy. For example 
|
111
111
|
- Choose some point near the expected root of equation. For example 
|
@@ -124,10 +124,10 @@ Mathpack::NonlinearEquations.solve(start: 0.01, eps: 0.00001){|x| Math.exp(x-2)
|
|
124
124
|
#### solve_system(params = {})
|
125
125
|
returns solution of system of nonlinear equations by *Newton method*
|
126
126
|
##### Parameters
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
* ***start*** - vector to start iteration process
|
128
|
+
* ***eps*** - calculations accuraccy
|
129
|
+
* ***f*** - vector of right part lambdas
|
130
|
+
* ***w_matrix*** - matrix *W* in Newton method
|
131
131
|
|
132
132
|
### Usage
|
133
133
|
If you have system of equations 
|
@@ -155,12 +155,12 @@ Mathpack::NonlinearEquations.solve_system(start: [1, 5], eps: 1e-4, f: f, w_matr
|
|
155
155
|
#### solve_fredholm_2(params={})
|
156
156
|
returns solution of integral equation as a hash of nodes and values arrays.
|
157
157
|
##### Parameters
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
* ***from*** - left border
|
159
|
+
* ***to*** - right border
|
160
|
+
* ***lambda*** - *lambda* parameter
|
161
|
+
* ***k*** - kernel function (2 arguements)
|
162
|
+
* ***f*** - inhomogeneity function (1 arguement)
|
163
|
+
* ***eps*** - accuracy
|
164
164
|
|
165
165
|
### Usage
|
166
166
|
Let we have the following integral equation
|
@@ -178,12 +178,12 @@ Mathpack::IntegralEquations.solve_fredholm_2(from: 1.0, to: 2.0, lambda: 0.5, ep
|
|
178
178
|
#### solve_volter_2(params{})
|
179
179
|
returns solution of integral equation as a hash of nodes and values arrays.
|
180
180
|
##### Parameters
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
* ***from*** - left border
|
182
|
+
* ***to*** - right border
|
183
|
+
* ***lambda*** - *lambda* parameter
|
184
|
+
* ***k*** - kernel function (2 arguements)
|
185
|
+
* ***f*** - inhomogeneity function (1 arguement)
|
186
|
+
* ***eps*** - accuracy
|
187
187
|
|
188
188
|
### Usage
|
189
189
|
Let we have the following integral equation
|
@@ -202,11 +202,11 @@ Mathpack::IntegralEquations.solve_volter_2(from: 0.0, to: 1.0, lambda: 0.5, eps:
|
|
202
202
|
#### solve_cauchie_system(params={})
|
203
203
|
returns solution of differential equations system as a hash of nodes and values arrays for each function. For example, { x: [], u1: [], u2: [], ... }
|
204
204
|
##### Parameters
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
205
|
+
* ***from*** - left border
|
206
|
+
* ***to*** - right border
|
207
|
+
* ***system*** - array of lambdas representing each row of system
|
208
|
+
* ***y0*** - array of values of derivatives on left border. Starts with first derivative
|
209
|
+
* ***eps*** - accuracy
|
210
210
|
|
211
211
|
### Usage
|
212
212
|
Let we have following system of differential equations
|
@@ -228,8 +228,8 @@ Mathpack::DifferentialEquations.solve_cauchie_system(from: 1.0, to: 2.0, eps: 1e
|
|
228
228
|
#### solve(params = {})
|
229
229
|
returns solution of system of linear equations.
|
230
230
|
##### Parameters
|
231
|
-
|
232
|
-
|
231
|
+
* ***matrix*** - system matrix
|
232
|
+
* ***f*** - right part vector
|
233
233
|
|
234
234
|
### Usage
|
235
235
|
Let's solve some system of linear equations. It can be written as
|
@@ -256,16 +256,16 @@ Mathpack::SLE.solve(matrix: a, f: b) #=> Matrix[[-1.0, 2.0, 4.0]]
|
|
256
256
|
#### approximate_by_polynom(params = {})
|
257
257
|
returns array of coefficients of polynom, approximating given function on [from, to] segment.
|
258
258
|
##### Parameters
|
259
|
-
|
260
|
-
|
261
|
-
|
259
|
+
* ***x*** - array of approximation nodes
|
260
|
+
* ***polynom_power*** - power of approximation polynom
|
261
|
+
* ***f*** - functions values in *x* if you have table function
|
262
262
|
|
263
263
|
#### generate_nodes(params = {})
|
264
264
|
returns nodes for approximation with some step.
|
265
265
|
##### Parameters
|
266
|
-
|
267
|
-
|
268
|
-
|
266
|
+
* ***from*** - first node
|
267
|
+
* ***to*** - last node
|
268
|
+
* ***step*** - step between nodes
|
269
269
|
|
270
270
|
#### print_polynom(coefficients)
|
271
271
|
returns a string representing polynom with given coefficients.
|
@@ -297,8 +297,8 @@ Mathpack::Approximation.print_polynom(result) #=> x^2
|
|
297
297
|
#### integrate(params = {})
|
298
298
|
returns integral value.
|
299
299
|
##### Parameters
|
300
|
-
|
301
|
-
|
300
|
+
* ***from*** - start of integration
|
301
|
+
* ***to*** - end of integration
|
302
302
|
|
303
303
|
### Usage
|
304
304
|
Let you have the following integral:
|
@@ -321,10 +321,10 @@ Mathpack::Integration.integrate(from: -Float::INFINITY, to: Float::INFINITY){ |x
|
|
321
321
|
#### print_table_function(params = {})
|
322
322
|
writes table function values to file
|
323
323
|
##### Parameters
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
324
|
+
* ***filename*** - name of output file
|
325
|
+
* ***x*** - arguements array
|
326
|
+
* ***y*** - function values array
|
327
|
+
* ***labels*** - hash of labels names for *x* and *y* column
|
328
328
|
|
329
329
|
#### read_table_function(filename)
|
330
330
|
returns table function values hash, written to **filename**
|
data/lib/mathpack/functions.rb
CHANGED
data/lib/mathpack/statistics.rb
CHANGED
@@ -10,19 +10,19 @@ module Mathpack
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def mean
|
13
|
-
raw_moment(1)
|
13
|
+
@mean ||= raw_moment(1)
|
14
14
|
end
|
15
15
|
|
16
16
|
def variance
|
17
|
-
central_moment(2)
|
17
|
+
@variance ||= central_moment(2)
|
18
18
|
end
|
19
19
|
|
20
20
|
def skewness
|
21
|
-
central_moment(3) / variance**1.5
|
21
|
+
@skewness ||= central_moment(3) / variance**1.5
|
22
22
|
end
|
23
23
|
|
24
24
|
def kurtosis
|
25
|
-
central_moment(4) / variance**2 - 3.0
|
25
|
+
@kurtosis ||= central_moment(4) / variance**2 - 3.0
|
26
26
|
end
|
27
27
|
|
28
28
|
def max
|
@@ -35,25 +35,22 @@ module Mathpack
|
|
35
35
|
|
36
36
|
def raw_moment(power)
|
37
37
|
raw_moment = 0.0
|
38
|
-
@data_set.
|
39
|
-
raw_moment +=
|
38
|
+
@data_set.zip(@frequency).each do |value, frequency|
|
39
|
+
raw_moment += frequency * value**power
|
40
40
|
end
|
41
41
|
raw_moment / number
|
42
42
|
end
|
43
43
|
|
44
44
|
def central_moment(power)
|
45
45
|
central_moment = 0.0
|
46
|
-
|
47
|
-
|
48
|
-
central_moment += @frequency[i] * (@data_set[i] - m)**power
|
46
|
+
@data_set.zip(@frequency).each do |value, frequency|
|
47
|
+
central_moment += frequency * (value - mean)**power
|
49
48
|
end
|
50
49
|
central_moment / number
|
51
50
|
end
|
52
51
|
|
53
52
|
def empirical_cdf(x)
|
54
|
-
|
55
|
-
@series.each { |val| result += Mathpack::Functions.heaviside(x - val) }
|
56
|
-
result / number
|
53
|
+
1.0 / number * @series.count { |value| Mathpack::Functions.heaviside(x - value) > 0 }
|
57
54
|
end
|
58
55
|
|
59
56
|
def print_empirical_cdf(filename)
|
@@ -65,9 +62,7 @@ module Mathpack
|
|
65
62
|
|
66
63
|
def empirical_pdf(x)
|
67
64
|
h = variance**0.5 * number**(-1.0 / 6)
|
68
|
-
|
69
|
-
@series.each { |val| result += (Mathpack::Functions.heaviside(x - val + h) - Mathpack::Functions.heaviside(x - val - h)) / (2 * h) }
|
70
|
-
result / number
|
65
|
+
1.0 / number * @series.inject(0) { |sum, value| sum + (Mathpack::Functions.heaviside(x - value + h) - Mathpack::Functions.heaviside(x - value - h)) / (2 * h) }
|
71
66
|
end
|
72
67
|
|
73
68
|
def print_empirical_pdf(filename)
|
data/lib/mathpack/version.rb
CHANGED
data/mathpack.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/$})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.11.2'
|
22
22
|
spec.add_development_dependency 'rake', '~>0'
|
23
23
|
end
|
data/spec/sle_spec.rb
CHANGED
@@ -13,15 +13,15 @@ describe 'SLE' do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'raises error when matrix is singular' do
|
16
|
-
expect { Mathpack::SLE.solve(matrix: unsolved, f: b) }.to raise_error
|
16
|
+
expect { Mathpack::SLE.solve(matrix: unsolved, f: b) }.to raise_error(RuntimeError)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises error when matrix has incorrect size' do
|
20
20
|
b << 1
|
21
|
-
expect { Mathpack::SLE.solve(matrix: a, f: b) }.to raise_error
|
21
|
+
expect { Mathpack::SLE.solve(matrix: a, f: b) }.to raise_error(RuntimeError)
|
22
22
|
b.pop
|
23
23
|
a << [1, 2, 3, 4]
|
24
|
-
expect { Mathpack::SLE.solve(matrix: a, f: b) }.to raise_error
|
24
|
+
expect { Mathpack::SLE.solve(matrix: a, f: b) }.to raise_error(RuntimeError)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'returns vector if matrix class is given' do
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mathpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxmilan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.11.2
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.11.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Includes collection of mathematical methods
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
-
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE.txt
|
52
52
|
- README.md
|
@@ -84,17 +84,17 @@ require_paths:
|
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ! '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Summary
|