LMMC
Lamina Mathematic core
载入中...
搜索中...
未找到
quadrature_gaussian.c
浏览该文件的文档.
2
3#define LMMC_GL_MAX_ORDER 20
4#define LMMC_GL_MIN_ORDER 1
5
6static const lmmc_real_t gl_nodes_1[] = {0.0};
7static const lmmc_real_t gl_weights_1[] = {2.0};
8
9static const lmmc_real_t gl_nodes_2[] = {
10 -0.5773502691896257645, 0.5773502691896257645
11};
12static const lmmc_real_t gl_weights_2[] = {
13 1.0000000000000000000, 1.0000000000000000000
14};
15
16static const lmmc_real_t gl_nodes_3[] = {
17 -0.7745966692414833771, 0.0000000000000000000, 0.7745966692414833771
18};
19static const lmmc_real_t gl_weights_3[] = {
20 0.5555555555555555556, 0.8888888888888888889, 0.5555555555555555556
21};
22
23static const lmmc_real_t gl_nodes_4[] = {
24 -0.8611363115940525752, -0.3399810435848562648,
25 0.3399810435848562648, 0.8611363115940525752
26};
27static const lmmc_real_t gl_weights_4[] = {
28 0.3478548451374538574, 0.6521451548625461426,
29 0.6521451548625461426, 0.3478548451374538574
30};
31
32static const lmmc_real_t gl_nodes_5[] = {
33 -0.9061798459386639928, -0.5384693101056830910, 0.0000000000000000000,
34 0.5384693101056830910, 0.9061798459386639928
35};
36static const lmmc_real_t gl_weights_5[] = {
37 0.2369268850561890875, 0.4786286704993664680, 0.5688888888888888889,
38 0.4786286704993664680, 0.2369268850561890875
39};
40
41static const lmmc_real_t gl_nodes_6[] = {
42 -0.9324695142031520278, -0.6612093864662645137, -0.2386191860831969086,
43 0.2386191860831969086, 0.6612093864662645137, 0.9324695142031520278
44};
45static const lmmc_real_t gl_weights_6[] = {
46 0.1713244923791703450, 0.3607615730481386076, 0.4679139345726910474,
47 0.4679139345726910474, 0.3607615730481386076, 0.1713244923791703450
48};
49
50static const lmmc_real_t gl_nodes_7[] = {
51 -0.9491079123427585245, -0.7415311855993944399, -0.4058451513773971669,
52 0.0000000000000000000, 0.4058451513773971669, 0.7415311855993944399,
53 0.9491079123427585245
54};
55static const lmmc_real_t gl_weights_7[] = {
56 0.1294849661688696932, 0.2797053914892766679, 0.3818300505051189449,
57 0.4179591836734693878, 0.3818300505051189449, 0.2797053914892766679,
58 0.1294849661688696932
59};
60
61static const lmmc_real_t gl_nodes_8[] = {
62 -0.9602898564975362317, -0.7966664774136267396,
63 -0.5255324099163289858, -0.1834346424956498049,
64 0.1834346424956498049, 0.5255324099163289858,
65 0.7966664774136267396, 0.9602898564975362317
66};
67static const lmmc_real_t gl_weights_8[] = {
68 0.1012285362903762591, 0.2223810344533744706,
69 0.3137066458778872874, 0.3626837833783619830,
70 0.3626837833783619830, 0.3137066458778872874,
71 0.2223810344533744706, 0.1012285362903762591
72};
73
74static const lmmc_real_t gl_nodes_9[] = {
75 -0.9681602395076260899, -0.8360311073266357943, -0.6133714327005903973,
76 -0.3242534234038089290, 0.0000000000000000000, 0.3242534234038089290,
77 0.6133714327005903973, 0.8360311073266357943, 0.9681602395076260899
78};
79static const lmmc_real_t gl_weights_9[] = {
80 0.0812743883615744120, 0.1806481606948574041, 0.2606106964029354624,
81 0.3123470770400028401, 0.3302393550012597632, 0.3123470770400028401,
82 0.2606106964029354624, 0.1806481606948574041, 0.0812743883615744120
83};
84
85static const lmmc_real_t gl_nodes_10[] = {
86 -0.9739065285171717200, -0.8650633666889845108, -0.6794095682990244063,
87 -0.4333953941292471908, -0.1488743389816312108, 0.1488743389816312108,
88 0.4333953941292471908, 0.6794095682990244063, 0.8650633666889845108,
89 0.9739065285171717200
90};
91static const lmmc_real_t gl_weights_10[] = {
92 0.0666713443086881376, 0.1494513491505805931, 0.2190863625159820440,
93 0.2692667193099963550, 0.2955242247147528702, 0.2955242247147528702,
94 0.2692667193099963550, 0.2190863625159820440, 0.1494513491505805931,
95 0.0666713443086881376
96};
97
98static const lmmc_real_t gl_nodes_11[] = {
99 -0.9782286581460569928, -0.8870625997680952990, -0.7301520055740493240,
100 -0.5190961292068118160, -0.2695431559523449723, 0.0000000000000000000,
101 0.2695431559523449723, 0.5190961292068118160, 0.7301520055740493240,
102 0.8870625997680952990, 0.9782286581460569928
103};
104static const lmmc_real_t gl_weights_11[] = {
105 0.0556685671161736665, 0.1255803694649046246, 0.1862902109277342514,
106 0.2331937645919904800, 0.2628045445102466622, 0.2729250867779006307,
107 0.2628045445102466622, 0.2331937645919904800, 0.1862902109277342514,
108 0.1255803694649046246, 0.0556685671161736665
109};
110
111static const lmmc_real_t gl_nodes_12[] = {
112 -0.9815606342467192507, -0.9041172563704748567, -0.7699026741943046870,
113 -0.5873179542866174473, -0.3678314989981801938, -0.1252334085114689155,
114 0.1252334085114689155, 0.3678314989981801938, 0.5873179542866174473,
115 0.7699026741943046870, 0.9041172563704748567, 0.9815606342467192507
116};
117static const lmmc_real_t gl_weights_12[] = {
118 0.0471753363865118272, 0.1069393259953184310, 0.1600783285433462264,
119 0.2031674267230659217, 0.2334925365383548088, 0.2491470458134027850,
120 0.2491470458134027850, 0.2334925365383548088, 0.2031674267230659217,
121 0.1600783285433462264, 0.1069393259953184310, 0.0471753363865118272
122};
123
124static const lmmc_real_t gl_nodes_13[] = {
125 -0.9841830547185881494, -0.9175983992229779653, -0.8015780907333099128,
126 -0.6423493394403402206, -0.4484927510364468528, -0.2304583159551347940,
127 0.0000000000000000000, 0.2304583159551347940, 0.4484927510364468528,
128 0.6423493394403402206, 0.8015780907333099128, 0.9175983992229779653,
129 0.9841830547185881494
130};
131static const lmmc_real_t gl_weights_13[] = {
132 0.0404840047653158796, 0.0921214998377284580, 0.1388735102197872385,
133 0.1781459807619457383, 0.2078160475368885023, 0.2262831802628972384,
134 0.2325515532308739102, 0.2262831802628972384, 0.2078160475368885023,
135 0.1781459807619457383, 0.1388735102197872385, 0.0921214998377284580,
136 0.0404840047653158796
137};
138
139static const lmmc_real_t gl_nodes_14[] = {
140 -0.9862838086968123388, -0.9284348836635735173, -0.8272013150697649931,
141 -0.6872929048116854701, -0.5152486363581540919, -0.3191123689278897604,
142 -0.1080549487073436621, 0.1080549487073436621, 0.3191123689278897604,
143 0.5152486363581540919, 0.6872929048116854701, 0.8272013150697649931,
144 0.9284348836635735173, 0.9862838086968123388
145};
146static const lmmc_real_t gl_weights_14[] = {
147 0.0351194603317518630, 0.0801580871597602098, 0.1215185706879031847,
148 0.1572031671581935345, 0.1855383974779378138, 0.2051984637212956040,
149 0.2152638534631577902, 0.2152638534631577902, 0.2051984637212956040,
150 0.1855383974779378138, 0.1572031671581935345, 0.1215185706879031847,
151 0.0801580871597602098, 0.0351194603317518630
152};
153
154static const lmmc_real_t gl_nodes_15[] = {
155 -0.9879925180204854285, -0.9372733924007059044, -0.8482065834104272162,
156 -0.7244177313601700474, -0.5709721726085388475, -0.3941513470775633699,
157 -0.2011940939974345223, 0.0000000000000000000, 0.2011940939974345223,
158 0.3941513470775633699, 0.5709721726085388475, 0.7244177313601700474,
159 0.8482065834104272162, 0.9372733924007059044, 0.9879925180204854285
160};
161static const lmmc_real_t gl_weights_15[] = {
162 0.0307532419961172684, 0.0703660474881081247, 0.1071592204671719350,
163 0.1395706779261543144, 0.1662692058169939336, 0.1861610000155622110,
164 0.1984314853271115765, 0.2025782419255612729, 0.1984314853271115765,
165 0.1861610000155622110, 0.1662692058169939336, 0.1395706779261543144,
166 0.1071592204671719350, 0.0703660474881081247, 0.0307532419961172684
167};
168
169static const lmmc_real_t gl_nodes_16[] = {
170 -0.9894009349916499326, -0.9445750230732326000, -0.8656312023878317439,
171 -0.7554044083550030339, -0.6178762444026437485, -0.4580167776572273863,
172 -0.2816035507792589132, -0.0950125098376374402, 0.0950125098376374402,
173 0.2816035507792589132, 0.4580167776572273863, 0.6178762444026437485,
174 0.7554044083550030339, 0.8656312023878317439, 0.9445750230732326000,
175 0.9894009349916499326
176};
177static const lmmc_real_t gl_weights_16[] = {
178 0.0271524594117540949, 0.0622535239386478929, 0.0951585116824927848,
179 0.1246289712555338721, 0.1495959888165767320, 0.1691565193950025381,
180 0.1826034150449235717, 0.1894506104550684962, 0.1894506104550684962,
181 0.1826034150449235717, 0.1691565193950025381, 0.1495959888165767320,
182 0.1246289712555338721, 0.0951585116824927848, 0.0622535239386478929,
183 0.0271524594117540949
184};
185
186static const lmmc_real_t gl_nodes_17[] = {
187 -0.9905754753144173356, -0.9506755217687677612, -0.8802391537269859021,
188 -0.7815140038968014069, -0.6576711592166907658, -0.5126905370864769678,
189 -0.3512317634538763153, -0.1784841814958478558, 0.0000000000000000000,
190 0.1784841814958478558, 0.3512317634538763153, 0.5126905370864769678,
191 0.6576711592166907658, 0.7815140038968014069, 0.8802391537269859021,
192 0.9506755217687677612, 0.9905754753144173356
193};
194static const lmmc_real_t gl_weights_17[] = {
195 0.0241483028685479319, 0.0554595293739872012, 0.0850361483171791809,
196 0.1118838471934039711, 0.1351363684685254732, 0.1540457610768102880,
197 0.1680041021564500271, 0.1765627053669926463, 0.1794464703562065254,
198 0.1765627053669926463, 0.1680041021564500271, 0.1540457610768102880,
199 0.1351363684685254732, 0.1118838471934039711, 0.0850361483171791809,
200 0.0554595293739872012, 0.0241483028685479319
201};
202
203static const lmmc_real_t gl_nodes_18[] = {
204 -0.9915651684209309160, -0.9558239495713977551, -0.8926024664975557393,
205 -0.8037049589725231156, -0.6916870430603532079, -0.5597708310739475347,
206 -0.4117511614628426460, -0.2518862256915055095, -0.0847750130417353013,
207 0.0847750130417353013, 0.2518862256915055095, 0.4117511614628426460,
208 0.5597708310739475347, 0.6916870430603532079, 0.8037049589725231156,
209 0.8926024664975557393, 0.9558239495713977551, 0.9915651684209309160
210};
211static const lmmc_real_t gl_weights_18[] = {
212 0.0216160135264833103, 0.0497145488949697964, 0.0764257302548890565,
213 0.1009420441062871655, 0.1225552067114784602, 0.1406429146706506512,
214 0.1546846751262652449, 0.1642764837458327229, 0.1691423829631435918,
215 0.1691423829631435918, 0.1642764837458327229, 0.1546846751262652449,
216 0.1406429146706506512, 0.1225552067114784602, 0.1009420441062871655,
217 0.0764257302548890565, 0.0497145488949697964, 0.0216160135264833103
218};
219
220static const lmmc_real_t gl_nodes_19[] = {
221 -0.9924068438435844032, -0.9602081521348300308, -0.9031559036148179016,
222 -0.8227146565371428250, -0.7209661773352293786, -0.6005453046616810235,
223 -0.4645707413759609457, -0.3165640999636298320, -0.1603586456402253758,
224 0.0000000000000000000, 0.1603586456402253758, 0.3165640999636298320,
225 0.4645707413759609457, 0.6005453046616810235, 0.7209661773352293786,
226 0.8227146565371428250, 0.9031559036148179016, 0.9602081521348300308,
227 0.9924068438435844032
228};
229static const lmmc_real_t gl_weights_19[] = {
230 0.0194617882297264771, 0.0448142267656996003, 0.0690445427376412265,
231 0.0914900216224499995, 0.1115666455473339947, 0.1287539625393362276,
232 0.1426067021736066117, 0.1527660420658596667, 0.1589688433939543476,
233 0.1610544498487836959, 0.1589688433939543476, 0.1527660420658596667,
234 0.1426067021736066117, 0.1287539625393362276, 0.1115666455473339947,
235 0.0914900216224499995, 0.0690445427376412265, 0.0448142267656996003,
236 0.0194617882297264771
237};
238
239static const lmmc_real_t gl_nodes_20[] = {
240 -0.9931285991850949247, -0.9639719272779137912, -0.9122344282513259059,
241 -0.8391169718222188234, -0.7463319064601507926, -0.6360536807265150254,
242 -0.5108670019508270980, -0.3737060887154195607, -0.2277858511416450681,
243 -0.0765265211334973338, 0.0765265211334973338, 0.2277858511416450681,
244 0.3737060887154195607, 0.5108670019508270980, 0.6360536807265150254,
245 0.7463319064601507926, 0.8391169718222188234, 0.9122344282513259059,
246 0.9639719272779137912, 0.9931285991850949247
247};
248static const lmmc_real_t gl_weights_20[] = {
249 0.0176140071391521183, 0.0406014298003869413, 0.0626720483341090636,
250 0.0832767415767047487, 0.1019301198172404351, 0.1181945319615184174,
251 0.1316886384491766269, 0.1420961093183820514, 0.1491729864726037467,
252 0.1527533871307258507, 0.1527533871307258507, 0.1491729864726037467,
253 0.1420961093183820514, 0.1316886384491766269, 0.1181945319615184174,
254 0.1019301198172404351, 0.0832767415767047487, 0.0626720483341090636,
255 0.0406014298003869413, 0.0176140071391521183
256};
257
258static const lmmc_real_t* const gl_nodes_table[] = {
259 gl_nodes_1, gl_nodes_2, gl_nodes_3, gl_nodes_4, gl_nodes_5,
260 gl_nodes_6, gl_nodes_7, gl_nodes_8, gl_nodes_9, gl_nodes_10,
261 gl_nodes_11, gl_nodes_12, gl_nodes_13, gl_nodes_14, gl_nodes_15,
262 gl_nodes_16, gl_nodes_17, gl_nodes_18, gl_nodes_19, gl_nodes_20
263};
264
265static const lmmc_real_t* const gl_weights_table[] = {
266 gl_weights_1, gl_weights_2, gl_weights_3, gl_weights_4, gl_weights_5,
267 gl_weights_6, gl_weights_7, gl_weights_8, gl_weights_9, gl_weights_10,
268 gl_weights_11, gl_weights_12, gl_weights_13, gl_weights_14, gl_weights_15,
269 gl_weights_16, gl_weights_17, gl_weights_18, gl_weights_19, gl_weights_20
270};
271
273 lmmc_quad_func_t func,
274 void* user_data,
275 lmmc_real_t a,
276 lmmc_real_t b,
277 size_t order,
278 lmmc_real_t* out_result)
279{
280 const lmmc_real_t* nodes;
281 const lmmc_real_t* weights;
282 lmmc_real_t half_len, midpoint, sum = 0.0;
283 size_t i;
284 if (func == NULL || out_result == NULL ||
285 order < LMMC_GL_MIN_ORDER || order > LMMC_GL_MAX_ORDER || a >= b) {
287 }
288 nodes = gl_nodes_table[order - LMMC_GL_MIN_ORDER];
289 weights = gl_weights_table[order - LMMC_GL_MIN_ORDER];
290 lmmc_quad_center_half_length(a, b, &midpoint, &half_len);
291 if (!lmmc_is_finite(&half_len) || !lmmc_is_finite(&midpoint)) {
293 }
294 for (i = 0; i < order; ++i) {
295 const lmmc_real_t x = fma(half_len, nodes[i], midpoint);
296 lmmc_real_t value = func(x, user_data);
297 if (!lmmc_is_finite(&x) || !lmmc_is_finite(&value)) {
299 }
300 sum += weights[i] * value;
301 if (!lmmc_is_finite(&sum)) {
303 }
304 }
305 *out_result = half_len * sum;
306 return lmmc_is_finite(out_result) ? LMMC_STATUS_OK
308}
double lmmc_real_t
Public and internal LMMC real type.
lmmc_real_t(*) lmmc_quad_func_t(lmmc_real_t x, void *user_data)
被积函数签名 。
lmmc_status_t lmmc_quad_gauss_legendre(lmmc_quad_func_t func, void *user_data, lmmc_real_t a, lmmc_real_t b, size_t order, lmmc_real_t *out_result)
Gauss-Legendre 求积:将 仿射映射到 后使用正交节点。
#define LMMC_GL_MIN_ORDER
#define LMMC_GL_MAX_ORDER
void lmmc_quad_center_half_length(lmmc_real_t a, lmmc_real_t b, lmmc_real_t *center, lmmc_real_t *half_length)
lmmc_status_t
LMMC 库统一返回的状态码.
@ LMMC_STATUS_OK
@ LMMC_STATUS_NUMERICAL_FAILURE
@ LMMC_STATUS_INVALID_ARGUMENT