You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_experimental_quadrature.md
+36-14
Original file line number
Diff line number
Diff line change
@@ -76,26 +76,26 @@ program demo_trapz_weights
76
76
real :: x(5) = [0., 1., 2., 3., 4.]
77
77
real :: y(5) = x**2
78
78
real :: w(5)
79
-
w = trapz_weight(x)
80
-
print *, dot_product(w, y)
79
+
w = trapz_weights(x)
80
+
print *, sum(w*y)
81
81
! 22.0
82
82
end program demo_trapz_weights
83
83
84
84
```
85
85
86
-
## `simps` - integrate sampled values using Simpson's rule (to be implemented)
86
+
## `simps` - integrate sampled values using Simpson's rule
87
87
88
88
### Description
89
89
90
90
Returns the Simpson's rule integral of an array `y` representing discrete samples of a function. The integral is computed assuming either equidistant abscissas with spacing `dx` or arbitary abscissas `x`.
91
91
92
-
Simpson's rule is defined for odd-length arrays only. For even-length arrays, an optional argument `even` may be used to specify at which index to replace Simpson's rule with Simpson's 3/8 rule. The 3/8 rule will be used for the array section `y(even:even+4)` and the ordinary Simpon's rule will be used elsewhere.
92
+
Simpson's ordinary ("1/3") rule is used for odd-length arrays. For even-length arrays, Simpson's 3/8 rule is also utilized in a way that depends on the value of `even`. If `even` is negative (positive), the 3/8 rule is used at the beginning (end) of the array. If `even` is zero or not present, the result is as if the 3/8 rule were first used at the beginning of the array, then at the end of the array, and these two results were averaged.
93
93
94
94
### Syntax
95
95
96
-
`result = simps(y, x [, even])`
96
+
`result = [[stdlib_experimental_quadrature(module):simps(interface)]](y, x [, even])`
@@ -105,37 +105,48 @@ Simpson's rule is defined for odd-length arrays only. For even-length arrays, an
105
105
106
106
`dx`: Shall be a scalar of type `real` having the same kind as `y`.
107
107
108
-
`even`: (Optional) Shall be a scalar integer of defaultkind. Its default value is `1`.
108
+
`even`: (Optional) Shall be a default-kind`integer`.
109
109
110
110
### Return value
111
111
112
112
The result is a scalar of type `real` having the same kind as `y`.
113
113
114
114
If the size of `y` is zero or one, the result is zero.
115
115
116
-
If the size of `y` is two, the result is the same as if `trapz` had been called instead, regardless of the value of `even`.
116
+
If the size of `y` is two, the result is the same as if `trapz` had been called instead.
117
117
118
118
### Example
119
119
120
-
TBD
120
+
```fortran
121
+
program demo_simps
122
+
use stdlib_experimental_quadrature, only: simps
123
+
implicit none
124
+
real :: x(5) = [0., 1., 2., 3., 4.]
125
+
real :: y(5) = 3.*x**2
126
+
print *, simps(y, x)
127
+
! 64.0
128
+
print *, simps(y, 0.5)
129
+
! 32.0
130
+
end program demo_simps
131
+
```
121
132
122
-
## `simps_weights` - Simpson's rule weights for given abscissas (to be implemented)
133
+
## `simps_weights` - Simpson's rule weights for given abscissas
123
134
124
135
### Description
125
136
126
137
Given an array of abscissas `x`, computes the array of weights `w` such that if `y` represented function values tabulated at `x`, then `sum(w*y)` produces a Simpson's rule approximation to the integral.
127
138
128
-
Simpson's rule is defined for odd-length arrays only. For even-length arrays, an optional argument `even` may be used to specify at which index to replace Simpson's rule with Simpson's 3/8 rule. The 3/8 rule will be used for the array section `x(even:even+4)` and the ordinary Simpon's rule will be used elsewhere.
139
+
Simpson's ordinary ("1/3") rule is used for odd-length arrays. For even-length arrays, Simpson's 3/8 rule is also utilized in a way that depends on the value of `even`. If `even` is negative (positive), the 3/8 rule is used at the beginning (end) of the array and the 1/3 rule used elsewhere. If `even` is zero or not present, the result is as if the 3/8 rule were first used at the beginning of the array, then at the end of the array, and then these two results were averaged.
0 commit comments