silicium 0.0.15 → 0.0.20
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/.codeclimate.yml +4 -0
- data/.gitignore +3 -1
- data/.travis.yml +12 -1
- data/Gemfile +4 -0
- data/Makefile +269 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/docs/Object.html +117 -0
- data/docs/README_md.html +142 -0
- data/docs/Silicium.html +101 -0
- data/docs/Silicium/Combinatorics.html +270 -0
- data/docs/Silicium/Dice.html +99 -0
- data/docs/Silicium/Dice/Polyhedron.html +315 -0
- data/docs/Silicium/Dice/PolyhedronSet.html +321 -0
- data/docs/Silicium/Error.html +106 -0
- data/docs/Silicium/Geometry.html +940 -0
- data/docs/Silicium/Geometry/Line2dCanon.html +243 -0
- data/docs/Silicium/Geometry/VariablesOrderException.html +106 -0
- data/docs/Silicium/Graphs.html +164 -0
- data/docs/Silicium/Graphs/GraphError.html +106 -0
- data/docs/Silicium/Graphs/OrientedGraph.html +775 -0
- data/docs/Silicium/Graphs/UnorientedGraph.html +284 -0
- data/docs/Silicium/IntegralDoesntExistError.html +106 -0
- data/docs/Silicium/NumericalIntegration.html +521 -0
- data/docs/Silicium/Optimization.html +639 -0
- data/docs/Silicium/Plotter.html +186 -0
- data/docs/Silicium/Plotter/Image.html +297 -0
- data/docs/created.rid +9 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +619 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +132 -0
- data/docs/js/darkfish.js +84 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +608 -0
- data/lib/geometry.rb +236 -0
- data/lib/graph.rb +164 -0
- data/lib/numerical_integration.rb +147 -0
- data/lib/optimization.rb +144 -0
- data/lib/plotter.rb +96 -0
- data/lib/silicium.rb +0 -1
- data/lib/silicium/version.rb +1 -1
- data/lib/theory_of_probability.rb +227 -0
- data/silicium.gemspec +4 -2
- metadata +90 -3
@@ -0,0 +1,284 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Silicium::Graphs::UnorientedGraph - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../../";
|
11
|
+
var index_rel_prefix = "../../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../../js/navigation.js" defer></script>
|
15
|
+
<script src="../../js/search.js" defer></script>
|
16
|
+
<script src="../../js/search_index.js" defer></script>
|
17
|
+
<script src="../../js/searcher.js" defer></script>
|
18
|
+
<script src="../../js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="../../css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="../../css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
<body id="top" role="document" class="class">
|
27
|
+
<nav role="navigation">
|
28
|
+
<div id="project-navigation">
|
29
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
30
|
+
<h2>
|
31
|
+
<a href="../../index.html" rel="home">Home</a>
|
32
|
+
</h2>
|
33
|
+
|
34
|
+
<div id="table-of-contents-navigation">
|
35
|
+
<a href="../../table_of_contents.html#pages">Pages</a>
|
36
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
37
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
42
|
+
<form action="#" method="get" accept-charset="utf-8">
|
43
|
+
<div id="search-field-wrapper">
|
44
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
45
|
+
aria-autocomplete="list" aria-controls="search-results"
|
46
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
47
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<ul id="search-results" aria-label="Search Results"
|
51
|
+
aria-busy="false" aria-expanded="false"
|
52
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
53
|
+
</form>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
<div id="class-metadata">
|
61
|
+
|
62
|
+
<div id="parent-class-section" class="nav-section">
|
63
|
+
<h3>Parent</h3>
|
64
|
+
|
65
|
+
|
66
|
+
<p class="link"><a href="OrientedGraph.html">Silicium::Graphs::OrientedGraph</a>
|
67
|
+
|
68
|
+
</div>
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
<!-- Method Quickref -->
|
73
|
+
<div id="method-list-section" class="nav-section">
|
74
|
+
<h3>Methods</h3>
|
75
|
+
|
76
|
+
<ul class="link-list" role="directory">
|
77
|
+
|
78
|
+
<li class="calls-super" ><a href="#method-i-add_edge-21">#add_edge!</a>
|
79
|
+
|
80
|
+
<li class="calls-super" ><a href="#method-i-delete_edge-21">#delete_edge!</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-edge_number">#edge_number</a>
|
83
|
+
|
84
|
+
<li class="calls-super" ><a href="#method-i-label_edge-21">#label_edge!</a>
|
85
|
+
|
86
|
+
</ul>
|
87
|
+
</div>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
</nav>
|
91
|
+
|
92
|
+
<main role="main" aria-labelledby="class-Silicium::Graphs::UnorientedGraph">
|
93
|
+
<h1 id="class-Silicium::Graphs::UnorientedGraph" class="class">
|
94
|
+
class Silicium::Graphs::UnorientedGraph
|
95
|
+
</h1>
|
96
|
+
|
97
|
+
<section class="description">
|
98
|
+
|
99
|
+
</section>
|
100
|
+
|
101
|
+
|
102
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
113
|
+
<header>
|
114
|
+
<h3>Public Instance Methods</h3>
|
115
|
+
</header>
|
116
|
+
|
117
|
+
|
118
|
+
<div id="method-i-add_edge-21" class="method-detail ">
|
119
|
+
|
120
|
+
<div class="method-heading">
|
121
|
+
<span class="method-name">add_edge!</span><span
|
122
|
+
class="method-args">(from, to)</span>
|
123
|
+
|
124
|
+
<span class="method-click-advice">click to toggle source</span>
|
125
|
+
|
126
|
+
</div>
|
127
|
+
|
128
|
+
|
129
|
+
<div class="method-description">
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
<div class="method-calls-super">
|
135
|
+
Calls superclass method
|
136
|
+
<a href="OrientedGraph.html#method-i-add_edge-21"><code>Silicium::Graphs::OrientedGraph#add_edge!</code></a>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<div class="method-source-code" id="add_edge-21-source">
|
142
|
+
<pre><span class="ruby-comment"># File lib/graph.rb, line 135</span>
|
143
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_edge!</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
|
144
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
|
145
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">from</span>)
|
146
|
+
<span class="ruby-keyword">end</span></pre>
|
147
|
+
</div>
|
148
|
+
|
149
|
+
</div>
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
</div>
|
155
|
+
|
156
|
+
|
157
|
+
<div id="method-i-delete_edge-21" class="method-detail ">
|
158
|
+
|
159
|
+
<div class="method-heading">
|
160
|
+
<span class="method-name">delete_edge!</span><span
|
161
|
+
class="method-args">(from, to)</span>
|
162
|
+
|
163
|
+
<span class="method-click-advice">click to toggle source</span>
|
164
|
+
|
165
|
+
</div>
|
166
|
+
|
167
|
+
|
168
|
+
<div class="method-description">
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<div class="method-calls-super">
|
174
|
+
Calls superclass method
|
175
|
+
<a href="OrientedGraph.html#method-i-delete_edge-21"><code>Silicium::Graphs::OrientedGraph#delete_edge!</code></a>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
<div class="method-source-code" id="delete_edge-21-source">
|
181
|
+
<pre><span class="ruby-comment"># File lib/graph.rb, line 145</span>
|
182
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_edge!</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
|
183
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>)
|
184
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">from</span>)
|
185
|
+
<span class="ruby-keyword">end</span></pre>
|
186
|
+
</div>
|
187
|
+
|
188
|
+
</div>
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
</div>
|
194
|
+
|
195
|
+
|
196
|
+
<div id="method-i-edge_number" class="method-detail ">
|
197
|
+
|
198
|
+
<div class="method-heading">
|
199
|
+
<span class="method-name">edge_number</span><span
|
200
|
+
class="method-args">()</span>
|
201
|
+
|
202
|
+
<span class="method-click-advice">click to toggle source</span>
|
203
|
+
|
204
|
+
</div>
|
205
|
+
|
206
|
+
|
207
|
+
<div class="method-description">
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
<div class="method-source-code" id="edge_number-source">
|
215
|
+
<pre><span class="ruby-comment"># File lib/graph.rb, line 150</span>
|
216
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">edge_number</span>
|
217
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-value">0</span>
|
218
|
+
<span class="ruby-ivar">@vertices</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">from</span>, <span class="ruby-identifier">tos</span><span class="ruby-operator">|</span>
|
219
|
+
<span class="ruby-identifier">tos</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">to</span><span class="ruby-operator">|</span> <span class="ruby-identifier">res</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">to</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">from</span> <span class="ruby-operator">?</span> <span class="ruby-value">2</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>)}
|
220
|
+
<span class="ruby-keyword">end</span>
|
221
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span>
|
222
|
+
<span class="ruby-keyword">end</span></pre>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
</div>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
</div>
|
231
|
+
|
232
|
+
|
233
|
+
<div id="method-i-label_edge-21" class="method-detail ">
|
234
|
+
|
235
|
+
<div class="method-heading">
|
236
|
+
<span class="method-name">label_edge!</span><span
|
237
|
+
class="method-args">(from, to, label)</span>
|
238
|
+
|
239
|
+
<span class="method-click-advice">click to toggle source</span>
|
240
|
+
|
241
|
+
</div>
|
242
|
+
|
243
|
+
|
244
|
+
<div class="method-description">
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<div class="method-calls-super">
|
250
|
+
Calls superclass method
|
251
|
+
<a href="OrientedGraph.html#method-i-label_edge-21"><code>Silicium::Graphs::OrientedGraph#label_edge!</code></a>
|
252
|
+
</div>
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
<div class="method-source-code" id="label_edge-21-source">
|
257
|
+
<pre><span class="ruby-comment"># File lib/graph.rb, line 140</span>
|
258
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">label_edge!</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>, <span class="ruby-identifier">label</span>)
|
259
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>, <span class="ruby-identifier">label</span>)
|
260
|
+
<span class="ruby-keyword">super</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">from</span>, <span class="ruby-identifier">label</span>)
|
261
|
+
<span class="ruby-keyword">end</span></pre>
|
262
|
+
</div>
|
263
|
+
|
264
|
+
</div>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
|
272
|
+
</section>
|
273
|
+
|
274
|
+
</section>
|
275
|
+
|
276
|
+
</main>
|
277
|
+
|
278
|
+
|
279
|
+
<footer id="validator-badges" role="contentinfo">
|
280
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
281
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
|
282
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
283
|
+
</footer>
|
284
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Silicium::IntegralDoesntExistError - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
var index_rel_prefix = "../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../js/navigation.js" defer></script>
|
15
|
+
<script src="../js/search.js" defer></script>
|
16
|
+
<script src="../js/search_index.js" defer></script>
|
17
|
+
<script src="../js/searcher.js" defer></script>
|
18
|
+
<script src="../js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
<body id="top" role="document" class="class">
|
27
|
+
<nav role="navigation">
|
28
|
+
<div id="project-navigation">
|
29
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
30
|
+
<h2>
|
31
|
+
<a href="../index.html" rel="home">Home</a>
|
32
|
+
</h2>
|
33
|
+
|
34
|
+
<div id="table-of-contents-navigation">
|
35
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
36
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
37
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
42
|
+
<form action="#" method="get" accept-charset="utf-8">
|
43
|
+
<div id="search-field-wrapper">
|
44
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
45
|
+
aria-autocomplete="list" aria-controls="search-results"
|
46
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
47
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<ul id="search-results" aria-label="Search Results"
|
51
|
+
aria-busy="false" aria-expanded="false"
|
52
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
53
|
+
</form>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
<div id="class-metadata">
|
61
|
+
|
62
|
+
<div id="parent-class-section" class="nav-section">
|
63
|
+
<h3>Parent</h3>
|
64
|
+
|
65
|
+
|
66
|
+
<p class="link">RuntimeError
|
67
|
+
|
68
|
+
</div>
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
</div>
|
74
|
+
</nav>
|
75
|
+
|
76
|
+
<main role="main" aria-labelledby="class-Silicium::IntegralDoesntExistError">
|
77
|
+
<h1 id="class-Silicium::IntegralDoesntExistError" class="class">
|
78
|
+
class Silicium::IntegralDoesntExistError
|
79
|
+
</h1>
|
80
|
+
|
81
|
+
<section class="description">
|
82
|
+
|
83
|
+
</section>
|
84
|
+
|
85
|
+
|
86
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
</section>
|
97
|
+
|
98
|
+
</main>
|
99
|
+
|
100
|
+
|
101
|
+
<footer id="validator-badges" role="contentinfo">
|
102
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
103
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
|
104
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
105
|
+
</footer>
|
106
|
+
|
@@ -0,0 +1,521 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class Silicium::NumericalIntegration - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
var index_rel_prefix = "../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../js/navigation.js" defer></script>
|
15
|
+
<script src="../js/search.js" defer></script>
|
16
|
+
<script src="../js/search_index.js" defer></script>
|
17
|
+
<script src="../js/searcher.js" defer></script>
|
18
|
+
<script src="../js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
<body id="top" role="document" class="class">
|
27
|
+
<nav role="navigation">
|
28
|
+
<div id="project-navigation">
|
29
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
30
|
+
<h2>
|
31
|
+
<a href="../index.html" rel="home">Home</a>
|
32
|
+
</h2>
|
33
|
+
|
34
|
+
<div id="table-of-contents-navigation">
|
35
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
36
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
37
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
42
|
+
<form action="#" method="get" accept-charset="utf-8">
|
43
|
+
<div id="search-field-wrapper">
|
44
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
45
|
+
aria-autocomplete="list" aria-controls="search-results"
|
46
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
47
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<ul id="search-results" aria-label="Search Results"
|
51
|
+
aria-busy="false" aria-expanded="false"
|
52
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
53
|
+
</form>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
<div id="class-metadata">
|
61
|
+
|
62
|
+
<div id="parent-class-section" class="nav-section">
|
63
|
+
<h3>Parent</h3>
|
64
|
+
|
65
|
+
|
66
|
+
<p class="link"><a href="../Object.html">Object</a>
|
67
|
+
|
68
|
+
</div>
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
<!-- Method Quickref -->
|
73
|
+
<div id="method-list-section" class="nav-section">
|
74
|
+
<h3>Methods</h3>
|
75
|
+
|
76
|
+
<ul class="link-list" role="directory">
|
77
|
+
|
78
|
+
<li ><a href="#method-c-left_rect_integration">::left_rect_integration</a>
|
79
|
+
|
80
|
+
<li ><a href="#method-c-left_rect_integration_n">::left_rect_integration_n</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-c-middle_rectangles">::middle_rectangles</a>
|
83
|
+
|
84
|
+
<li ><a href="#method-c-middle_rectangles_with_a_segment">::middle_rectangles_with_a_segment</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-c-simpson_integration">::simpson_integration</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-c-simpson_integration_with_a_segment">::simpson_integration_with_a_segment</a>
|
89
|
+
|
90
|
+
<li ><a href="#method-c-three_eights_integration">::three_eights_integration</a>
|
91
|
+
|
92
|
+
<li ><a href="#method-c-three_eights_integration_n">::three_eights_integration_n</a>
|
93
|
+
|
94
|
+
<li ><a href="#method-c-trapezoid">::trapezoid</a>
|
95
|
+
|
96
|
+
<li ><a href="#method-c-trapezoid_with_a_segment">::trapezoid_with_a_segment</a>
|
97
|
+
|
98
|
+
</ul>
|
99
|
+
</div>
|
100
|
+
|
101
|
+
</div>
|
102
|
+
</nav>
|
103
|
+
|
104
|
+
<main role="main" aria-labelledby="class-Silicium::NumericalIntegration">
|
105
|
+
<h1 id="class-Silicium::NumericalIntegration" class="class">
|
106
|
+
class Silicium::NumericalIntegration
|
107
|
+
</h1>
|
108
|
+
|
109
|
+
<section class="description">
|
110
|
+
|
111
|
+
<p>A class providing numerical integration methods</p>
|
112
|
+
|
113
|
+
</section>
|
114
|
+
|
115
|
+
|
116
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
127
|
+
<header>
|
128
|
+
<h3>Public Class Methods</h3>
|
129
|
+
</header>
|
130
|
+
|
131
|
+
|
132
|
+
<div id="method-c-left_rect_integration" class="method-detail ">
|
133
|
+
|
134
|
+
<div class="method-heading">
|
135
|
+
<span class="method-name">left_rect_integration</span><span
|
136
|
+
class="method-args">(left_p, right_p, eps = 0.0001, &block)</span>
|
137
|
+
|
138
|
+
<span class="method-click-advice">click to toggle source</span>
|
139
|
+
|
140
|
+
</div>
|
141
|
+
|
142
|
+
|
143
|
+
<div class="method-description">
|
144
|
+
|
145
|
+
<p>Left Rectangle Method and Right Rectangle Method</p>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
<div class="method-source-code" id="left_rect_integration-source">
|
151
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 48</span>
|
152
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">left_rect_integration</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.0001</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
153
|
+
<span class="ruby-identifier">splits</span> = <span class="ruby-value">1</span>
|
154
|
+
<span class="ruby-identifier">res1</span> = <span class="ruby-identifier">left_rect_integration_n</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-value">1</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
155
|
+
<span class="ruby-identifier">res2</span> = <span class="ruby-identifier">left_rect_integration_n</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-value">5</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
156
|
+
<span class="ruby-keyword">while</span> (<span class="ruby-identifier">res1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">res2</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">></span> <span class="ruby-identifier">eps</span>
|
157
|
+
<span class="ruby-identifier">res1</span> = <span class="ruby-identifier">left_rect_integration_n</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-identifier">splits</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
158
|
+
<span class="ruby-identifier">splits</span> <span class="ruby-operator">*=</span> <span class="ruby-value">5</span>
|
159
|
+
<span class="ruby-identifier">res2</span> = <span class="ruby-identifier">left_rect_integration_n</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-identifier">splits</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
160
|
+
<span class="ruby-keyword">end</span>
|
161
|
+
(<span class="ruby-identifier">res1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">res2</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>
|
162
|
+
<span class="ruby-keyword">end</span></pre>
|
163
|
+
</div>
|
164
|
+
|
165
|
+
</div>
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
</div>
|
171
|
+
|
172
|
+
|
173
|
+
<div id="method-c-left_rect_integration_n" class="method-detail ">
|
174
|
+
|
175
|
+
<div class="method-heading">
|
176
|
+
<span class="method-name">left_rect_integration_n</span><span
|
177
|
+
class="method-args">(left_p, right_p, splits, &block)</span>
|
178
|
+
|
179
|
+
<span class="method-click-advice">click to toggle source</span>
|
180
|
+
|
181
|
+
</div>
|
182
|
+
|
183
|
+
|
184
|
+
<div class="method-description">
|
185
|
+
|
186
|
+
<p>Left Rectangle Auxiliary Method and Right Rectangle Auxiliary Method</p>
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
<div class="method-source-code" id="left_rect_integration_n-source">
|
192
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 61</span>
|
193
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">left_rect_integration_n</span>(<span class="ruby-identifier">left_p</span>, <span class="ruby-identifier">right_p</span>, <span class="ruby-identifier">splits</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
194
|
+
<span class="ruby-identifier">dx</span> = (<span class="ruby-identifier">right_p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">left_p</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">splits</span>.<span class="ruby-identifier">to_f</span>
|
195
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-value">0</span>
|
196
|
+
<span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
|
197
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">splits</span>
|
198
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">left_p</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>)
|
199
|
+
<span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
200
|
+
<span class="ruby-keyword">end</span>
|
201
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>
|
202
|
+
<span class="ruby-keyword">end</span></pre>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
</div>
|
211
|
+
|
212
|
+
|
213
|
+
<div id="method-c-middle_rectangles" class="method-detail ">
|
214
|
+
|
215
|
+
<div class="method-heading">
|
216
|
+
<span class="method-name">middle_rectangles</span><span
|
217
|
+
class="method-args">(a, b, eps = 0.0001, &block)</span>
|
218
|
+
|
219
|
+
<span class="method-click-advice">click to toggle source</span>
|
220
|
+
|
221
|
+
</div>
|
222
|
+
|
223
|
+
|
224
|
+
<div class="method-description">
|
225
|
+
|
226
|
+
<p>Middle Rectangles Method with specified accuracy</p>
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
<div class="method-source-code" id="middle_rectangles-source">
|
232
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 86</span>
|
233
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">middle_rectangles</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.0001</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
234
|
+
<span class="ruby-identifier">wrapper_method</span>([<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>], <span class="ruby-identifier">eps</span>, <span class="ruby-value">:middle_rectangles_with_a_segment</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
235
|
+
<span class="ruby-keyword">end</span></pre>
|
236
|
+
</div>
|
237
|
+
|
238
|
+
</div>
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
</div>
|
244
|
+
|
245
|
+
|
246
|
+
<div id="method-c-middle_rectangles_with_a_segment" class="method-detail ">
|
247
|
+
|
248
|
+
<div class="method-heading">
|
249
|
+
<span class="method-name">middle_rectangles_with_a_segment</span><span
|
250
|
+
class="method-args">(a, b, n, &block)</span>
|
251
|
+
|
252
|
+
<span class="method-click-advice">click to toggle source</span>
|
253
|
+
|
254
|
+
</div>
|
255
|
+
|
256
|
+
|
257
|
+
<div class="method-description">
|
258
|
+
|
259
|
+
<p>Middle Rectangles Method with a segment</p>
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
<div class="method-source-code" id="middle_rectangles_with_a_segment-source">
|
265
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 74</span>
|
266
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">middle_rectangles_with_a_segment</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">n</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
267
|
+
<span class="ruby-identifier">dx</span> = (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">to_f</span>
|
268
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-value">0</span>
|
269
|
+
<span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
|
270
|
+
<span class="ruby-identifier">n</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span>
|
271
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dx</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span>)) <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>
|
272
|
+
<span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
273
|
+
<span class="ruby-keyword">end</span>
|
274
|
+
<span class="ruby-identifier">result</span>
|
275
|
+
<span class="ruby-keyword">end</span></pre>
|
276
|
+
</div>
|
277
|
+
|
278
|
+
</div>
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
|
286
|
+
<div id="method-c-simpson_integration" class="method-detail ">
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
<span class="method-name">simpson_integration</span><span
|
290
|
+
class="method-args">(a, b, eps = 0.0001, &block)</span>
|
291
|
+
|
292
|
+
<span class="method-click-advice">click to toggle source</span>
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
|
297
|
+
<div class="method-description">
|
298
|
+
|
299
|
+
<p>Simpson integration with specified accuracy</p>
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
<div class="method-source-code" id="simpson_integration-source">
|
305
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 43</span>
|
306
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">simpson_integration</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.0001</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
307
|
+
<span class="ruby-identifier">wrapper_method</span>([<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>], <span class="ruby-identifier">eps</span>, <span class="ruby-value">:simpson_integration_with_a_segment</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
308
|
+
<span class="ruby-keyword">end</span></pre>
|
309
|
+
</div>
|
310
|
+
|
311
|
+
</div>
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
</div>
|
317
|
+
|
318
|
+
|
319
|
+
<div id="method-c-simpson_integration_with_a_segment" class="method-detail ">
|
320
|
+
|
321
|
+
<div class="method-heading">
|
322
|
+
<span class="method-name">simpson_integration_with_a_segment</span><span
|
323
|
+
class="method-args">(a, b, n, &block)</span>
|
324
|
+
|
325
|
+
<span class="method-click-advice">click to toggle source</span>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
|
330
|
+
<div class="method-description">
|
331
|
+
|
332
|
+
<p>Simpson integration with a segment</p>
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
<div class="method-source-code" id="simpson_integration_with_a_segment-source">
|
338
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 30</span>
|
339
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">simpson_integration_with_a_segment</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">n</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
340
|
+
<span class="ruby-identifier">dx</span> = (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">to_f</span>
|
341
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-value">0</span>
|
342
|
+
<span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
|
343
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">n</span>
|
344
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>) <span class="ruby-operator">+</span> <span class="ruby-value">4</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(((<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>) <span class="ruby-operator">+</span>
|
345
|
+
(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>)) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>)) <span class="ruby-operator">/</span> <span class="ruby-value">6.0</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>
|
346
|
+
<span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
347
|
+
<span class="ruby-keyword">end</span>
|
348
|
+
<span class="ruby-identifier">result</span>
|
349
|
+
<span class="ruby-keyword">end</span></pre>
|
350
|
+
</div>
|
351
|
+
|
352
|
+
</div>
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
</div>
|
358
|
+
|
359
|
+
|
360
|
+
<div id="method-c-three_eights_integration" class="method-detail ">
|
361
|
+
|
362
|
+
<div class="method-heading">
|
363
|
+
<span class="method-name">three_eights_integration</span><span
|
364
|
+
class="method-args">(a, b, eps = 0.0001, &block)</span>
|
365
|
+
|
366
|
+
<span class="method-click-advice">click to toggle source</span>
|
367
|
+
|
368
|
+
</div>
|
369
|
+
|
370
|
+
|
371
|
+
<div class="method-description">
|
372
|
+
|
373
|
+
<p>Computes integral from <code>a</code> to <code>b</code> of <code>block</code> with accuracy <code>eps</code></p>
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
<div class="method-source-code" id="three_eights_integration-source">
|
379
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 10</span>
|
380
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">three_eights_integration</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.0001</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
381
|
+
<span class="ruby-identifier">wrapper_method</span>([<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>], <span class="ruby-identifier">eps</span>, <span class="ruby-value">:three_eights_integration_n</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
382
|
+
<span class="ruby-keyword">end</span></pre>
|
383
|
+
</div>
|
384
|
+
|
385
|
+
</div>
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
</div>
|
391
|
+
|
392
|
+
|
393
|
+
<div id="method-c-three_eights_integration_n" class="method-detail ">
|
394
|
+
|
395
|
+
<div class="method-heading">
|
396
|
+
<span class="method-name">three_eights_integration_n</span><span
|
397
|
+
class="method-args">(a, b, n, &block)</span>
|
398
|
+
|
399
|
+
<span class="method-click-advice">click to toggle source</span>
|
400
|
+
|
401
|
+
</div>
|
402
|
+
|
403
|
+
|
404
|
+
<div class="method-description">
|
405
|
+
|
406
|
+
<p>Computes integral from <code>a</code> to <code>b</code> of <code>block</code> with <code>n</code> segmentations</p>
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
<div class="method-source-code" id="three_eights_integration_n-source">
|
412
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 15</span>
|
413
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">three_eights_integration_n</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">n</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
414
|
+
<span class="ruby-identifier">dx</span> = (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">to_f</span>
|
415
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-value">0</span>
|
416
|
+
<span class="ruby-identifier">x</span> = <span class="ruby-identifier">a</span>
|
417
|
+
<span class="ruby-identifier">n</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span>
|
418
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span>
|
419
|
+
(<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span>) <span class="ruby-operator">+</span> <span class="ruby-value">3</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>((<span class="ruby-value">2</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dx</span>) <span class="ruby-operator">/</span> <span class="ruby-value">3.0</span>) <span class="ruby-operator">+</span>
|
420
|
+
<span class="ruby-value">3</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>((<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dx</span>)) <span class="ruby-operator">/</span> <span class="ruby-value">3.0</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dx</span>)) <span class="ruby-operator">/</span> <span class="ruby-value">8.0</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>
|
421
|
+
<span class="ruby-identifier">x</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">dx</span>
|
422
|
+
<span class="ruby-keyword">end</span>
|
423
|
+
<span class="ruby-identifier">result</span>
|
424
|
+
<span class="ruby-keyword">end</span></pre>
|
425
|
+
</div>
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
</div>
|
433
|
+
|
434
|
+
|
435
|
+
<div id="method-c-trapezoid" class="method-detail ">
|
436
|
+
|
437
|
+
<div class="method-heading">
|
438
|
+
<span class="method-name">trapezoid</span><span
|
439
|
+
class="method-args">(a, b, eps = 0.0001, &block)</span>
|
440
|
+
|
441
|
+
<span class="method-click-advice">click to toggle source</span>
|
442
|
+
|
443
|
+
</div>
|
444
|
+
|
445
|
+
|
446
|
+
<div class="method-description">
|
447
|
+
|
448
|
+
<p>Trapezoid Method with specified accuracy</p>
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
<div class="method-source-code" id="trapezoid-source">
|
454
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 105</span>
|
455
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">trapezoid</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.0001</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
456
|
+
<span class="ruby-identifier">wrapper_method</span>([<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>], <span class="ruby-identifier">eps</span>, <span class="ruby-value">:trapezoid_with_a_segment</span> ,<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
457
|
+
<span class="ruby-keyword">end</span></pre>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
</div>
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
</div>
|
466
|
+
|
467
|
+
|
468
|
+
<div id="method-c-trapezoid_with_a_segment" class="method-detail ">
|
469
|
+
|
470
|
+
<div class="method-heading">
|
471
|
+
<span class="method-name">trapezoid_with_a_segment</span><span
|
472
|
+
class="method-args">(a, b, n, &block)</span>
|
473
|
+
|
474
|
+
<span class="method-click-advice">click to toggle source</span>
|
475
|
+
|
476
|
+
</div>
|
477
|
+
|
478
|
+
|
479
|
+
<div class="method-description">
|
480
|
+
|
481
|
+
<p>Trapezoid Method with a segment</p>
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
<div class="method-source-code" id="trapezoid_with_a_segment-source">
|
487
|
+
<pre><span class="ruby-comment"># File lib/numerical_integration.rb, line 92</span>
|
488
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">trapezoid_with_a_segment</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">n</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
489
|
+
<span class="ruby-identifier">dx</span> = (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">to_f</span>
|
490
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-value">0</span>
|
491
|
+
<span class="ruby-identifier">i</span> = <span class="ruby-value">1</span>
|
492
|
+
(<span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span>
|
493
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">i</span>)
|
494
|
+
<span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
495
|
+
<span class="ruby-keyword">end</span>
|
496
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">b</span>)) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>
|
497
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dx</span>
|
498
|
+
<span class="ruby-keyword">end</span></pre>
|
499
|
+
</div>
|
500
|
+
|
501
|
+
</div>
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
</div>
|
507
|
+
|
508
|
+
|
509
|
+
</section>
|
510
|
+
|
511
|
+
</section>
|
512
|
+
|
513
|
+
</main>
|
514
|
+
|
515
|
+
|
516
|
+
<footer id="validator-badges" role="contentinfo">
|
517
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
518
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
|
519
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
520
|
+
</footer>
|
521
|
+
|