mathpack 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 990d138b20708752c754e294a22627435a3a5ce9
4
- data.tar.gz: dbb63f6b4cea510030e05c819cd2bac9a5c7376a
3
+ metadata.gz: 4ff99464e0f1a06b1ba3c2d3423096577a3649d1
4
+ data.tar.gz: e41163fd0942911d66072c0d1b579d83ba9cec75
5
5
  SHA512:
6
- metadata.gz: 36318534efa67765b74962c5d6b102b7e0e4c4b2e2bbda35a795c443be5d6e7b09f6ec9be97f014ae7e8db88a6831ef710afb42714164ead92322b35f3c9433a
7
- data.tar.gz: 38db3fd63908159911ef2ba99d8b6a0b899ae26010482104db5aa384f42f61f1176dcec6c59672fe664fb342f4f6817a5540a3d3289950cfaf4d382212194338
6
+ metadata.gz: 73f068a79ab03282563afd02416d48e1d54fb70b1f88d8286e0ac918215070ee8f3cc674cb731dc12878073b5fd4b0f1bce9ada7818a4271fb9748209c0c7880
7
+ data.tar.gz: 8287a6d59751b79d6e6ed2df1cebb1fcea04763618f104c838bd747e01c8e835fb657b47e815a246007e1988cf288c87c63690d4e3da6ff32657ee4149e4b75b
@@ -1,5 +1,3 @@
1
- require 'mathpack'
2
-
3
1
  module Mathpack
4
2
  module Approximation
5
3
  def self.basic_fi(x, power)
@@ -57,12 +55,13 @@ module Mathpack
57
55
 
58
56
  def self.generate_nodes(params = {})
59
57
  nodes = []
60
- x = params[:start]
58
+ i = 0
61
59
  loop do
62
- nodes << x
63
- x += params[:step]
64
- break if x > params[:end]
60
+ nodes << params[:start] + i * params[:step]
61
+ i += 1
62
+ break if params[:start] + i * params[:step] > params[:end]
65
63
  end
64
+ nodes << params[:end] if nodes.last != params[:end]
66
65
  nodes
67
66
  end
68
67
 
@@ -1,3 +1,3 @@
1
1
  module Mathpack
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -9,30 +9,35 @@ describe 'Approximation' do
9
9
  let(:values) { Mathpack::Approximation.fill_f(nodes){ |val| val**2 } }
10
10
 
11
11
  it 'should generate nodes' do
12
- expect(nodes.length).to eql(41)
13
- expect(nodes.first).to eql(x_start)
14
- expect(nodes.last).to eql(x_end)
12
+ expect(nodes.length).to eq(41)
13
+ expect(nodes.first).to eq(x_start)
14
+ expect(nodes.last).to eq(x_end)
15
+ end
16
+
17
+ it 'should generate correct nodes' do
18
+ nodes = Mathpack::Approximation.generate_nodes(start: 0, end: 1, step: 0.001)
19
+ expect(nodes.last).to eq(1.0)
15
20
  end
16
21
 
17
22
  it 'should fill function table' do
18
- expect(values.length).to eql(nodes.length)
19
- expect(values.last).to eql(nodes.last**2)
23
+ expect(values.length).to eq(nodes.length)
24
+ expect(values.last).to eq(nodes.last**2)
20
25
  end
21
26
 
22
27
  it 'should print polynoms' do
23
- expect(Mathpack::Approximation.print_polynom([5])).to eql('5')
24
- expect(Mathpack::Approximation.print_polynom([2, 3])).to eql('2*x + 3')
25
- expect(Mathpack::Approximation.print_polynom([1, -1, 1])).to eql('x^2 - x + 1')
26
- expect(Mathpack::Approximation.print_polynom([1, 3, 5])).to eql('x^2 + 3*x + 5')
27
- expect(Mathpack::Approximation.print_polynom([1, -2, 3, -4])).to eql('x^3 - 2*x^2 + 3*x - 4')
28
- expect(Mathpack::Approximation.print_polynom([1, 0, 1])).to eql('x^2 + 1')
28
+ expect(Mathpack::Approximation.print_polynom([5])).to eq('5')
29
+ expect(Mathpack::Approximation.print_polynom([2, 3])).to eq('2*x + 3')
30
+ expect(Mathpack::Approximation.print_polynom([1, -1, 1])).to eq('x^2 - x + 1')
31
+ expect(Mathpack::Approximation.print_polynom([1, 3, 5])).to eq('x^2 + 3*x + 5')
32
+ expect(Mathpack::Approximation.print_polynom([1, -2, 3, -4])).to eq('x^3 - 2*x^2 + 3*x - 4')
33
+ expect(Mathpack::Approximation.print_polynom([1, 0, 1])).to eq('x^2 + 1')
29
34
  end
30
35
 
31
36
  it 'should approximate by polynom' do
32
37
  coefficients = Mathpack::Approximation.approximate_by_polynom(x: nodes, f: values, polynom_power: 2)
33
- expect(coefficients).to eql([1.0, 0.0, 0.0])
38
+ expect(coefficients).to eq([1.0, 0.0, 0.0])
34
39
  coefficients = Mathpack::Approximation.approximate_by_polynom(x: nodes, f: values, polynom_power: 0)
35
- expect(coefficients).to eql([33.75])
40
+ expect(coefficients).to eq([33.75])
36
41
  end
37
42
  end
38
43
  end
data/spec/sle_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe 'SLE' do
9
9
  let(:vector_b) { Matrix.row_vector([15, 30, 15]) }
10
10
 
11
11
  it 'should give correct answer' do
12
- expect(Mathpack::SLE.solve(matrix: a, f: b)).to eql([-1.0, 2.0, 4.0])
12
+ expect(Mathpack::SLE.solve(matrix: a, f: b)).to eq([-1.0, 2.0, 4.0])
13
13
  end
14
14
 
15
15
  it 'should raise error' do
@@ -17,7 +17,7 @@ describe 'SLE' do
17
17
  end
18
18
 
19
19
  it 'should return vector if matrix class is given' do
20
- expect(Mathpack::SLE.solve(matrix: matrix_a, f: vector_b)).to eql(Matrix.row_vector [-1.0, 2.0, 4.0])
20
+ expect(Mathpack::SLE.solve(matrix: matrix_a, f: vector_b)).to eq(Matrix.row_vector [-1.0, 2.0, 4.0])
21
21
  end
22
22
  end
23
23
  end
@@ -7,61 +7,61 @@ describe 'Statistics' do
7
7
  let(:stat) { Mathpack::Statistics.new(data) }
8
8
 
9
9
  it 'should calculate number of elements' do
10
- expect(stat.number).to eql(10)
10
+ expect(stat.number).to eq(10)
11
11
  end
12
12
 
13
13
  it 'should calculate mean' do
14
- expect(stat.mean).to eql(4.0)
14
+ expect(stat.mean).to eq(4.0)
15
15
  end
16
16
 
17
17
  it 'should calculate variance' do
18
- expect(stat.variance).to eql(3.8)
18
+ expect(stat.variance).to eq(3.8)
19
19
  end
20
20
 
21
21
  it 'should calculate skewness' do
22
- expect(stat.skewness).to eql(0.16199658190818222)
22
+ expect(stat.skewness).to eq(0.16199658190818222)
23
23
  end
24
24
 
25
25
  it 'should calculate kurtosis' do
26
- expect(stat.kurtosis).to eql(1.925207756232687)
26
+ expect(stat.kurtosis).to eq(1.925207756232687)
27
27
  end
28
28
 
29
29
  it 'should calculate the minimal element' do
30
- expect(stat.min).to eql(1)
30
+ expect(stat.min).to eq(1)
31
31
  end
32
32
 
33
33
  it 'should calculate the maximal element' do
34
- expect(stat.max).to eql(7)
34
+ expect(stat.max).to eq(7)
35
35
  end
36
36
 
37
37
  it 'should calculate first raw moment equal to mean' do
38
- expect(stat.raw_moment(1)).to eql(stat.mean)
38
+ expect(stat.raw_moment(1)).to eq(stat.mean)
39
39
  end
40
40
 
41
41
  it 'should calculate second central moment equal to variance' do
42
- expect(stat.central_moment(2)).to eql(stat.variance)
42
+ expect(stat.central_moment(2)).to eq(stat.variance)
43
43
  end
44
44
 
45
45
  it 'should calculate raw moments' do
46
- expect(stat.raw_moment(3)).to eql(110.8)
46
+ expect(stat.raw_moment(3)).to eq(110.8)
47
47
  end
48
48
 
49
49
  it 'should calculate central moments' do
50
- expect(stat.central_moment(5)).to eql(18.0)
50
+ expect(stat.central_moment(5)).to eq(18.0)
51
51
  end
52
52
 
53
53
  it 'should calculate empirical cdf values in points' do
54
- expect(stat.empirical_cdf(stat.min - 0.1)).to eql(0.0)
55
- expect(stat.empirical_cdf(stat.max + 0.1)).to eql(1.0)
56
- expect(stat.empirical_cdf(stat.mean)).to eql(0.4)
54
+ expect(stat.empirical_cdf(stat.min - 0.1)).to eq(0.0)
55
+ expect(stat.empirical_cdf(stat.max + 0.1)).to eq(1.0)
56
+ expect(stat.empirical_cdf(stat.mean)).to eq(0.4)
57
57
  end
58
58
 
59
59
  it 'should calculate empirical pdf values in points' do
60
- expect(stat.empirical_pdf(stat.mean)).to eql(0.1882412842233359)
60
+ expect(stat.empirical_pdf(stat.mean)).to eq(0.1882412842233359)
61
61
  end
62
62
 
63
63
  it 'should find trend' do
64
- expect(stat.trend(polynom_power: 2)).to eql('0.0075757575757576055*x^2 + 0.2681818181818179*x + 2.233333333333334')
64
+ expect(stat.trend(polynom_power: 2)).to eq('0.0075757575757576055*x^2 + 0.2681818181818179*x + 2.233333333333334')
65
65
  end
66
66
  end
67
67
  end
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxmilan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-04 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler