Numerical_Integration 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 +7 -0
- data/lib/Numerical_Integration.rb +59 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e91bf69433aded7895c9b0fb2565a19d33bda467b8ec4ad0f2533e99692b6ca6
|
4
|
+
data.tar.gz: 9863fbb4cafcbce458cb159b44f06fa4ca34e1f86d735a9b52496675be8709f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92c3890554df40bfe8cf64f75b9024961b91f2a7fa2d080f1f336478045b8d41ac4bc3c4e7f82d7bbf5a4982747b5587c0bb809f89ea0ef2bfaf00a44b740f28
|
7
|
+
data.tar.gz: 843e0b1afc2ce913d74075d7d8e1cce58546129f5c3b878c931aedfa8c19d53cf9e2d47319b4934bfc19e458eb546a867d32cf5cf5784f4ab51c299112de9d36
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module NumericalIntegration
|
2
|
+
|
3
|
+
#Метод левых прямоугольников
|
4
|
+
def rectangle_method(function, a, b, n)
|
5
|
+
h = (b - a).to_f / n #Шаг
|
6
|
+
sum = 0.0
|
7
|
+
(0..n).each do |i|
|
8
|
+
x = a + i*h
|
9
|
+
rectangle = function.call(x)
|
10
|
+
sum += rectangle
|
11
|
+
end
|
12
|
+
sum *= h
|
13
|
+
return sum
|
14
|
+
end
|
15
|
+
|
16
|
+
# Метод трапеций
|
17
|
+
def trapezoidal_method(function, a, b, n)
|
18
|
+
h = (b - a).to_f / n
|
19
|
+
sum = 0.0
|
20
|
+
sum += (function.call(a) + function.call(b)) / 2.0
|
21
|
+
(1..(n-1)).each do |i|
|
22
|
+
sum += function.call(a + i*h)
|
23
|
+
end
|
24
|
+
sum *= h
|
25
|
+
return sum
|
26
|
+
end
|
27
|
+
|
28
|
+
# Формула Симпсона
|
29
|
+
def simpsons_method(function, a, b, n)
|
30
|
+
h = (b - a).to_f / n
|
31
|
+
x = Array.new
|
32
|
+
fx = Array.new
|
33
|
+
|
34
|
+
(0..n).each do |i|
|
35
|
+
x.push(a + i*h)
|
36
|
+
fx.push(function.call(x[i]))
|
37
|
+
end
|
38
|
+
|
39
|
+
result = 0.0
|
40
|
+
(0..n).each do |i|
|
41
|
+
if i == 0 or i == n
|
42
|
+
result += fx[i]
|
43
|
+
elsif i % 2 != 0
|
44
|
+
result += 4* fx[i]
|
45
|
+
else
|
46
|
+
result += 2 * fx[i]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result = result * (h / 3)
|
50
|
+
return result
|
51
|
+
end
|
52
|
+
|
53
|
+
def my_exp(x)
|
54
|
+
return Math.exp(x)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
#p rectangle_method(method(:my_exp), 0.0, 1.0, 10000)
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Numerical_Integration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kseniya Chekomasova
|
8
|
+
- Kseniya Mochalova
|
9
|
+
- Elizaveta Chueva
|
10
|
+
- Anastasia Garkusha
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/Numerical_Integration.rb
|
23
|
+
homepage:
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.3.20
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Library with methods for numerical integration
|
45
|
+
test_files: []
|