Mercurial > repos > public > sbplib
annotate diracDiscr.m @ 647:46c40711830f feature/d1_staggered
Add test for diracDiscr.m
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Tue, 14 Nov 2017 15:35:28 -0800 |
parents | 0990765e3e4d |
children | 9e5dd0d3cf60 |
rev | line source |
---|---|
645
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 function ret = diracDiscr(x_0in , x , m_order, s_order, H) |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 fnorm = diag(H); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 eta = abs(x-x_0in); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 h = x(2)-x(1); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
6 tot = m_order+s_order; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 S = []; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 M = []; |
646
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
9 poss = find(tot*h/2 >= eta); |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
10 |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
11 % Ensure that poss is not too long |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
12 if length(poss) == (tot + 2) |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
13 poss = poss(2:end-1); |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
14 elseif length(poss) == (tot + 1) |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
15 poss = poss(1:end-1); |
0990765e3e4d
Fix bug in diracDiscr
Martin Almquist <malmquist@stanford.edu>
parents:
645
diff
changeset
|
16 end |
645
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 % Use first tot grid points |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 if length(poss)<tot && eta(end)>eta(1) |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 index=1:tot; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 pol=(x(1:tot)-x(1))/(x(tot)-x(1)); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 x_0=(x_0in-x(1))/(x(tot)-x(1)); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 norm=fnorm(1:tot)/h; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 % Use last tot grid points |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 elseif length(poss)<tot && eta(end)<eta(1) |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 index = length(x)-tot:tot; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 pol = (x(end-tot:end)-x(end-tot))/(x(end)-x(end-tot)); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 norm = fnorm(end-tot:end)/h; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 x_0 = (x_0in-x(end-tot))/(x(end)-x(end-tot)); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
32 % Interior |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 else |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1))); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1))); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 norm = fnorm(poss)/h; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 index = poss; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 h_pol = pol(2)-pol(1); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 b = zeros(m_order+s_order,1); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 for i = 1:m_order |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 b(i,1) = x_0^(i-1); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 for i = 1:(m_order+s_order) |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 for j = 1:m_order |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 M(j,i) = pol(i)^(j-1)*h_pol*norm(i); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 for i = 1:(m_order+s_order) |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 for j = 1:s_order |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 S(j,i) = (-1)^(i-1)*pol(i)^(j-1); |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 A = [M;S]; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 d = A\b; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 ret = x*0; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 ret(index) = d/h*h_pol; |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 end |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 |
a5307adc6177
Add diracDiscr.m. Noticed bug if source is on grid point.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 |