Mercurial > octave
comparison scripts/general/integral2.m @ 24149:1a3229a2f1ab
integral2.m, integral3.m: Clean up BIST tests.
* integral2.m, integral3.m: Clean up BIST tests.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 16 Oct 2017 11:58:34 -0700 |
parents | 2e64bed0bb3a |
children | eec262017c6a |
comparison
equal
deleted
inserted
replaced
24148:2e64bed0bb3a | 24149:1a3229a2f1ab |
---|---|
255 %!assert (integral2 (f, 0, 1, 0, 1, "method", "auto"), 0.25, 1e-10) | 255 %!assert (integral2 (f, 0, 1, 0, 1, "method", "auto"), 0.25, 1e-10) |
256 | 256 |
257 ## vectorized = false test | 257 ## vectorized = false test |
258 %!test | 258 %!test |
259 %! f = @(x, y) x * y; | 259 %! f = @(x, y) x * y; |
260 %! assert (integral2 (f, 0, 1, 0, 1, "vectorized", false), 0.25, 1e-10); | 260 %!assert (integral2 (f, 0, 1, 0, 1, "vectorized", false), 0.25, 1e-10) |
261 | 261 |
262 ## tolerance tests | 262 ## tolerance tests |
263 %!shared f | 263 %!test |
264 %! f = @(x, y) 9 * x.^2 + 15 * y.^2; | 264 %! f = @(x, y) 9 * x.^2 + 15 * y.^2; |
265 | |
266 %!assert (integral2 (f, 0, 5, -5, 0, "AbsTol", 1e-9), 5000, 1e-9) | 265 %!assert (integral2 (f, 0, 5, -5, 0, "AbsTol", 1e-9), 5000, 1e-9) |
267 %!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-5), 5000, -1e-5) | 266 %!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-5), 5000, -1e-5) |
268 %!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-6, "AbsTol", 1e-9), | 267 %!assert (integral2 (f, 0, 5, -5, 0, "RelTol", 1e-6, "AbsTol", 1e-9), 5000, 1e-9) |
269 %! 5000, 1e-9) | |
270 | 268 |
271 ## tests from dblquad | 269 ## tests from dblquad |
272 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "AbsTol", 1e-7), | 270 %!test |
273 %! 2*log (2), 1e-7) | 271 %! f = @(x, y) 1 ./ (x+y); |
274 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "RelTol", 1e-5), | 272 %!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-7), 2*log (2), 1e-7) |
275 %! 2*log (2), -1e-5) | 273 %!assert (integral2 (f, 0, 1, 0, 1, "RelTol", 1e-5), 2*log (2), -1e-5) |
276 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, "AbsTol", 1e-8, | 274 %!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-8, "RelTol", 1e-6), |
277 %! "RelTol", 1e-6), | |
278 %! 2*log (2), -1e-6) | 275 %! 2*log (2), -1e-6) |
276 %!assert (integral2 (f, 0, 1, 0, @(x) 1 - x), 1, -1e-6) | |
277 | |
279 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1), | 278 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1), |
280 %! pi * erf (1).^2, 1e-10) | 279 %! pi * erf (1).^2, 1e-10) |
281 | 280 |
282 %!assert (integral2 (@plus, 1, 2, 3, 4), 5, 1e-10) | 281 %!assert (integral2 (@plus, 1, 2, 3, 4), 5, 1e-10) |
283 %!assert (integral2 (@(x,y) 1 ./ (x + y), 0, 1, 0, @(x) 1 - x), 1, -1e-6) | |
284 | 282 |
285 ## tests from dblquad w/method specified | 283 ## tests from dblquad w/method specified |
286 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, | 284 %!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-7, "method", "iterated"), |
287 %! "AbsTol", 1e-7, "method", "iterated"), | |
288 %! 2*log (2), 1e-7) | 285 %! 2*log (2), 1e-7) |
289 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, | 286 %!assert (integral2 (f, 0, 1, 0, 1, "RelTol", 1e-5, "method", "iterated"), |
290 %! "RelTol", 1e-5, "method", "iterated"), | |
291 %! 2*log (2), -1e-5) | 287 %! 2*log (2), -1e-5) |
292 %!assert (integral2 (@(x, y) 1 ./ (x+y), 0, 1, 0, 1, | 288 %!assert (integral2 (f, 0, 1, 0, 1, "AbsTol", 1e-8, "RelTol", 1e-6, |
293 %! "AbsTol", 1e-8, "RelTol", 1e-6, "method", "iterated"), | 289 %! "Method", "iterated"), |
294 %! 2*log (2), -1e-6) | 290 %! 2*log (2), -1e-6) |
291 %!assert (integral2 (f, 0, 1, 0, @(x) 1 - x, "Method", "iterated"), 1, -1e-6) | |
295 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1, | 292 %!assert (integral2 (@(x, y) exp (-x.^2 - y.^2) , -1, 1, -1, 1, |
296 %! "method", "iterated"), | 293 %! "Method", "iterated"), |
297 %! pi * erf (1).^2, 1e-10) | 294 %! pi * erf (1).^2, 1e-10) |
298 | 295 |
299 %!assert (integral2 (@plus, 1, 2, 3, 4, "method", "iterated"), 5, 1e-10) | 296 %!assert (integral2 (@plus, 1, 2, 3, 4, "method", "iterated"), 5, 1e-10) |
300 %!assert (integral2 (@(x,y) 1 ./ (x + y), 0, 1, 0, @(x) 1 - x, | |
301 %! "method", "iterated"), | |
302 %! 1, -1e-6) | |
303 | 297 |
304 ## Test input validation | 298 ## Test input validation |
305 %!error integral2 () | 299 %!error integral2 () |
306 %!error integral2 (@plus) | 300 %!error integral2 (@plus) |
307 %!error integral2 (@plus, 1) | 301 %!error integral2 (@plus, 1) |