Vectors 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 057b69577336c488e83124f9e964953a840a2f5ef0ffca66b6679f6fa3fbdf71
4
- data.tar.gz: 07d6e65221184002e719f666f94362b9b853bf20e7f81863bd3841d01435a32f
3
+ metadata.gz: 1358156ba302ae54353695d3a15073f2b6b12c25cb2e08cbc2fc67c59e149f90
4
+ data.tar.gz: b600d63b7ea6eb72f55f46a6f23e3cb8ca1d9c4022ed365c908b540a956946c0
5
5
  SHA512:
6
- metadata.gz: a36c6f8929dfa96ab6e87a751d464f1da3aba572f523cbc906c0c3019af98f3ca5958495a1129ffe4737e3fa06da0439ace9be1c34c76338a97b2c2682c31b88
7
- data.tar.gz: 778bc0502f69da94e5a32749af1c3d9eda550dd8bb10989162ca17f0f26709302291884b743aafee2ca4bae1d267c9dfefb639818a491141d6c2ffba038fdfd0
6
+ metadata.gz: 3d2ed87e715311f526ca1731b02afbe1d2f6136a1b5e4cdf209c57e511920f4f646038bb9bcd13de02dfa2cc8280968a5d15a09544517fb3047436fe436bb7da
7
+ data.tar.gz: 685dbdd0735803b496295974f0f62e528891a4c622683b117426cbf24f17a87fcef86e17d3c53e8309f572af98553626fa347b8cdcbf4edd57bd9e3520ee9aab
data/README.md CHANGED
@@ -29,27 +29,59 @@ gem install Vectors
29
29
 
30
30
  Determinant Calculation
31
31
 
32
+ Determinant(matrix)
33
+
34
+ input: matrix - Array of arrays size of nxn
35
+
36
+ output: res[Int] - simple Integer
37
+
32
38
  matrix = [
33
39
  [1, 2],
34
40
  [3, 4]
35
41
  ]
42
+
36
43
  result = Vectors.Determinant(matrix)
44
+
37
45
  puts result # Output: -2
38
46
 
39
47
  Scalar Product
40
48
 
49
+ scalar_prod(a, b)
50
+
51
+ input: a[Array], b[Array]- vectors a and b
52
+
53
+ output: res[Int] - simple Integer as a result of scalar prod
54
+
41
55
  a = [1, 2, 3]
56
+
42
57
  b = [4, 5, 6]
58
+
43
59
  result = Vectors.scalar_prod(a, b)
60
+
44
61
  puts result # Output: 32
45
62
 
46
63
  Cross Product
47
64
 
65
+ cross_prod(a, b)
66
+
67
+ input: a[Array], b[Array] - vectors a and b with dimension n = 3;
68
+
69
+ output: res[Array] - vector with the size = 3 (its dimension) as a result of cross prod
70
+
48
71
  a = [1, 2, 3]
72
+
49
73
  b = [4, 5, 6]
74
+
50
75
  result = Vectors.cross_prod(a, b)
76
+
51
77
  puts result.inspect # Output: [-3, 6, -3]
52
78
 
79
+ Help function
80
+
81
+ help()
82
+
83
+ output: String with info about gem funcs
84
+
53
85
 
54
86
  ## Development
55
87
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vectors
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/Vectors.rb CHANGED
@@ -7,25 +7,29 @@ module Vectors
7
7
 
8
8
  extend self
9
9
 
10
- # input: matrix - Array of arrays size of nxn
11
- # output: res[Int] - simple Integer
12
- def Determinant(matrix)
13
- raise TypeError, "Ожидался массив массивов" unless matrix.is_a?(Array)
10
+ def determinant(matrix)
11
+ raise TypeError, "Ожидался массив массивов" unless matrix.is_a?(Array)
14
12
 
15
13
  n = matrix.size
16
14
 
17
15
  if n == 0 || !matrix.all? { |row| row.is_a?(Array) && row.size == n }
18
- raise ArgumentError, "Матрица должна быть квадратной и непустой"
16
+ raise ArgumentError, "Матрица должна быть квадратной и непустой"
19
17
  end
20
18
 
21
19
  matrix.each do |row|
22
- row.each do |el|
23
- unless el.is_a?(Numeric)
24
- raise ArgumentError, "Все элементы матрицы должны быть числовыми"
25
- end
20
+ row.each do |el|
21
+ unless el.is_a?(Numeric)
22
+ raise ArgumentError, "Все элементы матрицы должны быть числовыми"
26
23
  end
24
+ end
27
25
  end
28
26
 
27
+ determinant_help(matrix)
28
+ end
29
+ # input: matrix - Array of arrays size of nxn
30
+ # output: res[Int] - simple Integer
31
+ def determinant_help(matrix)
32
+ n = matrix.size
29
33
  if n == 1
30
34
  return matrix[0][0]
31
35
  elsif n == 2
@@ -36,7 +40,7 @@ module Vectors
36
40
  minor = matrix[1..-1].map do |row|
37
41
  row.reject.with_index { |_, index| index == col}
38
42
  end
39
- det += ((-1) ** col) * element * Determinant(minor)
43
+ det += ((-1) ** col) * element * determinant_help(minor)
40
44
  end
41
45
  return det
42
46
  end
@@ -73,17 +77,17 @@ end
73
77
  raise ArgumentError, "Векторы должны быть трехмерными" unless a.size == 3 && b.size == 3
74
78
  raise TypeError, "Все элементы должны быть числами" unless a.all? { |x| x.is_a?(Numeric) } && b.all? { |x| x.is_a?(Numeric) }
75
79
 
76
- x_component = Determinant([
80
+ x_component = determinant([
77
81
  [a[1], a[2]],
78
82
  [b[1], b[2]]
79
83
  ])
80
84
 
81
- y_component = -Determinant([
85
+ y_component = -determinant([
82
86
  [a[0], a[2]],
83
87
  [b[0], b[2]]
84
88
  ])
85
89
 
86
- z_component = Determinant([
90
+ z_component = determinant([
87
91
  [a[0], a[1]],
88
92
  [b[0], b[1]]
89
93
  ])
@@ -110,7 +114,7 @@ end
110
114
  output: res[Array] - vector with the size = 3 (its dimension) as a result of cross prod
111
115
  HELP
112
116
  end
113
-
117
+
114
118
 
115
119
 
116
120
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Vectors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - inaidE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2025-04-07 00:00:00.000000000 Z
13
+ date: 2025-05-17 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: "A Ruby gem for vector and matrix operations. Provides methods to calculate:\n
16
16
  \ - Matrix determinant:\n\n Determinant(matrix)\n\n input: matrix - Array of