Mercurial > repos > public > sbplib
comparison diracDiscrTest.m @ 651:4ee7d15bd8e6 feature/d1_staggered
Fix roundoff bug in diracDiscr and improve test.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Wed, 15 Nov 2017 14:58:13 -0800 |
parents | 46c40711830f |
children | 5264ce57b573 |
comparison
equal
deleted
inserted
replaced
650:8e55298657b9 | 651:4ee7d15bd8e6 |
---|---|
191 end | 191 end |
192 end | 192 end |
193 end | 193 end |
194 end | 194 end |
195 | 195 |
196 function testAllGP(testCase) | |
197 | |
198 orders = [2, 4, 6]; | |
199 mom_conds = orders; | |
200 | |
201 for o = 1:length(orders) | |
202 order = orders(o); | |
203 mom_cond = mom_conds(o); | |
204 [xl, xr, m, h, x, H, fs] = setupStuff(order, mom_cond); | |
205 | |
206 % Test all grid points | |
207 x0s = x; | |
208 | |
209 for j = 1:length(fs) | |
210 f = fs{j}; | |
211 fx = f(x); | |
212 for i = 1:length(x0s) | |
213 x0 = x0s(i); | |
214 delta = diracDiscr(x0, x, mom_cond, 0, H); | |
215 integral = delta'*H*fx; | |
216 err = abs(integral - f(x0)); | |
217 testCase.verifyLessThan(err, 1e-12); | |
218 end | |
219 end | |
220 end | |
221 end | |
222 | |
196 function [xl, xr, m, h, x, H, fs] = setupStuff(order, mom_cond) | 223 function [xl, xr, m, h, x, H, fs] = setupStuff(order, mom_cond) |
197 | 224 |
198 % Grid | 225 % Grid |
199 xl = -3; | 226 xl = -3; |
200 xr = 2; | 227 xr = 2; |
201 m = 21; | 228 m = 101; |
202 h = (xr-xl)/(m-1); | 229 h = (xr-xl)/(m-1); |
203 g = grid.equidistant(m, {xl, xr}); | 230 g = grid.equidistant(m, {xl, xr}); |
204 x = g.points(); | 231 x = g.points(); |
205 | 232 |
206 % Quadrature | 233 % Quadrature |