num4inte 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/ext/num4inte/CNum4Inte.c +86 -0
- data/ext/num4inte/CNum4Inte.h +25 -0
- data/ext/num4inte/Rakefile +5 -0
- data/lib/num4inte.rb +55 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 391c7af590564ae676a706c71d1c3d67ba1d8f3c3d01cece8bc5b298d13de1c9
|
4
|
+
data.tar.gz: fae05e502bb9acc4a4456fb285a9cae64d43d895e8822e21b68a7b7b31be7bdd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19add3204882ae70fe3173567f13e1f268da893df1a46f73dd58833191f5ec194d9200cc4769527a4a74995f5a0257a794acf4c1b27692e31763c5254ff4240d
|
7
|
+
data.tar.gz: 9d81760ab9526a4ddc621ba374f1e30ae35d339903f9c301e3aee15bf64b857768044d74f09893011f11e81c38b526fd6f9fe75356475372bcd10f843abd0799
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 siranovel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <assert.h>
|
4
|
+
#include "CNum4Inte.h"
|
5
|
+
|
6
|
+
static double CNum4Inte_doLeftReimannSumMetod(double a, double b, double h, Func func);
|
7
|
+
static double CNum4Inte_doRigtReimannSumMetod(double a, double b, double h, Func func);
|
8
|
+
static double CNum4Inte_doNewtonMethod(double a, double b, double h, Func func);
|
9
|
+
static CNum4Inte _cNum4Inte = {
|
10
|
+
.FP_leftReimannSumMetod = CNum4Inte_doLeftReimannSumMetod,
|
11
|
+
.FP_rigtReimannSumMetod = CNum4Inte_doRigtReimannSumMetod,
|
12
|
+
.FP_newtonMethod = CNum4Inte_doNewtonMethod,
|
13
|
+
};
|
14
|
+
/**************************************/
|
15
|
+
/* InterFface部 */
|
16
|
+
/**************************************/
|
17
|
+
/**************************************/
|
18
|
+
/* Class部 */
|
19
|
+
/**************************************/
|
20
|
+
double CNum4Inte_leftReimannSumMetod(double a, double b, double h, Func func)
|
21
|
+
{
|
22
|
+
assert(func != 0);
|
23
|
+
|
24
|
+
return _cNum4Inte.FP_leftReimannSumMetod(a, b, h, func);
|
25
|
+
}
|
26
|
+
double CNum4Inte_rigtReimannSumMetod(double a, double b, double h, Func func)
|
27
|
+
{
|
28
|
+
assert(func != 0);
|
29
|
+
|
30
|
+
return _cNum4Inte.FP_rigtReimannSumMetod(a, b, h, func);
|
31
|
+
}
|
32
|
+
double CNum4Inte_newtonMethod(double a, double b, double h, Func func)
|
33
|
+
{
|
34
|
+
assert(func != 0);
|
35
|
+
|
36
|
+
return _cNum4Inte.FP_newtonMethod(a, b, h, func);
|
37
|
+
}
|
38
|
+
/**************************************/
|
39
|
+
/* 処理実行部 */
|
40
|
+
/**************************************/
|
41
|
+
/*
|
42
|
+
* 左リーマン和法
|
43
|
+
*/
|
44
|
+
static double CNum4Inte_doLeftReimannSumMetod(double a, double b, double h, Func func)
|
45
|
+
{
|
46
|
+
double rimann = 0.0;
|
47
|
+
double x = 0.0;
|
48
|
+
|
49
|
+
for (x = a; x < b; x += h) {
|
50
|
+
rimann += func(x);
|
51
|
+
}
|
52
|
+
return rimann * h;
|
53
|
+
}
|
54
|
+
/*
|
55
|
+
* 右リーマン和法
|
56
|
+
*/
|
57
|
+
static double CNum4Inte_doRigtReimannSumMetod(double a, double b, double h, Func func)
|
58
|
+
{
|
59
|
+
double rimann = 0.0;
|
60
|
+
double x = 0.0;
|
61
|
+
|
62
|
+
for (x = a; x < b; x += h) {
|
63
|
+
rimann += func(x + h);
|
64
|
+
}
|
65
|
+
return rimann * h;
|
66
|
+
}
|
67
|
+
/*
|
68
|
+
* ニュートン・シンプソン法
|
69
|
+
*/
|
70
|
+
static double CNum4Inte_doNewtonMethod(double a, double b, double h, Func func)
|
71
|
+
{
|
72
|
+
double newton = 0.0;
|
73
|
+
double x = 0.0;
|
74
|
+
double fx = func(a);
|
75
|
+
double fxh = 0.0;
|
76
|
+
|
77
|
+
for (x = a; x < b; x += h) {
|
78
|
+
fxh = func(x + h);
|
79
|
+
newton += (fx + fxh) /2;
|
80
|
+
fx = fxh;
|
81
|
+
}
|
82
|
+
return newton * h;
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#ifndef _CNum4Inte_H_
|
2
|
+
#define _CNum4Inte_H_
|
3
|
+
|
4
|
+
/**************************************/
|
5
|
+
/* 構造体宣言 */
|
6
|
+
/**************************************/
|
7
|
+
typedef struct _CNum4Inte CNum4Inte;
|
8
|
+
typedef double (*Func)(double x);
|
9
|
+
|
10
|
+
struct _CNum4Inte
|
11
|
+
{
|
12
|
+
double (*FP_leftReimannSumMetod)(double a, double b, double h, Func func);
|
13
|
+
double (*FP_rigtReimannSumMetod)(double a, double b, double h, Func func);
|
14
|
+
double (*FP_newtonMethod)(double a, double b, double h, Func func);
|
15
|
+
};
|
16
|
+
/**************************************/
|
17
|
+
/* define宣言 */
|
18
|
+
/**************************************/
|
19
|
+
/**************************************/
|
20
|
+
/* プロトタイプ宣言 */
|
21
|
+
/**************************************/
|
22
|
+
double CNum4Inte_leftReimannSumMetod(double a, double b, double h, Func func);
|
23
|
+
double CNum4Inte_rigtReimannSumMetod(double a, double b, double h, Func func);
|
24
|
+
double CNum4Inte_newtonMethod(double a, double b, double h, Func func);
|
25
|
+
#endif
|
data/lib/num4inte.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'ffi-compiler/loader'
|
3
|
+
|
4
|
+
#
|
5
|
+
# 数値計算による数値積分の解法するライブラリ
|
6
|
+
#
|
7
|
+
module Num4InteLib
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
ffi_lib FFI::Compiler::Loader.find('num4inte')
|
11
|
+
# @overload f(xi)
|
12
|
+
# dy = f(xi)
|
13
|
+
# @yield [x] dy = f(x)
|
14
|
+
# @yieldparam [double] xi xiの値
|
15
|
+
# @return [double] xiに対するyの値
|
16
|
+
callback :f, [:double], :double
|
17
|
+
|
18
|
+
#
|
19
|
+
# 左リーマン和法
|
20
|
+
# @overload leftReimannSumMetod(a, b, h, func)
|
21
|
+
# y = leftReimannSumMetod(a, b, h, func)
|
22
|
+
# @param [double] a aの値
|
23
|
+
# @param [double] b bの値
|
24
|
+
# @param [double] h 刻み幅
|
25
|
+
# @param [callback] func xiに対する傾きを計算する関数
|
26
|
+
# @return [double] [a,b]の間の積分値
|
27
|
+
#
|
28
|
+
attach_function :leftReimannSumMetod,
|
29
|
+
:CNum4Inte_leftReimannSumMetod, [:double, :double, :double, :f], :double
|
30
|
+
#
|
31
|
+
# 右リーマン和法
|
32
|
+
# @overload rigtReimannSumMetod(a, b, h, func)
|
33
|
+
# y = rigtReimannSumMetod(a, b, h, func)
|
34
|
+
# @param [double] a aの値
|
35
|
+
# @param [double] b bの値
|
36
|
+
# @param [double] h 刻み幅
|
37
|
+
# @param [callback] func xiに対する傾きを計算する関数
|
38
|
+
# @return [double] [a,b]の間の積分値
|
39
|
+
#
|
40
|
+
attach_function :rigtReimannSumMetod,
|
41
|
+
:CNum4Inte_rigtReimannSumMetod, [:double, :double, :double, :f], :double
|
42
|
+
#
|
43
|
+
# ニュートン・シンプソン法
|
44
|
+
# @overload newtonMethod(a, b, h, func)
|
45
|
+
# y = newtonMethod(a, b, h, func)
|
46
|
+
# @param [double] a aの値
|
47
|
+
# @param [double] b bの値
|
48
|
+
# @param [double] h 刻み幅
|
49
|
+
# @param [callback] func xiに対する傾きを計算する関数
|
50
|
+
# @return [double] [a,b]の間の積分値
|
51
|
+
#
|
52
|
+
attach_function :newtonMethod,
|
53
|
+
:CNum4Inte_newtonMethod, [:double, :double, :double, :f], :double
|
54
|
+
end
|
55
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: num4inte
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- siranovel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '12.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 12.3.3
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '12.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 12.3.3
|
53
|
+
description: numerical solution for integral
|
54
|
+
email: siranovel@gmail.com
|
55
|
+
executables: []
|
56
|
+
extensions:
|
57
|
+
- ext/num4inte/Rakefile
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- CHANGELOG.md
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- ext/num4inte/CNum4Inte.c
|
64
|
+
- ext/num4inte/CNum4Inte.h
|
65
|
+
- ext/num4inte/Rakefile
|
66
|
+
- lib/num4inte.rb
|
67
|
+
homepage: http://github.com/siranovel/num4integral
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
changelog_uri: http://github.com/siranovel/num4integral/blob/main/CHANGELOG.md
|
72
|
+
documentation_uri: https://rubydoc.info/gems/num4inte/0.0.1
|
73
|
+
homepage_uri: http://github.com/siranovel/num4integral
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: num for integral
|
93
|
+
test_files: []
|