Mercurial > repos > public > sbplib
comparison diracDiscr1D.m @ 1129:b29892853daf feature/laplace_curvilinear_test
Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Tue, 21 May 2019 18:10:06 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1128:3a9262c045d0 | 1129:b29892853daf |
---|---|
1 % Generates discrete 1D delta function | |
2 function ret = diracDiscr1D(x_0in , x , m_order, s_order, H) | |
3 | |
4 m = length(x); | |
5 | |
6 % Return zeros if x0 is outside grid | |
7 if(x_0in < x(1) || x_0in > x(end) ) | |
8 | |
9 ret = zeros(size(x)); | |
10 | |
11 else | |
12 | |
13 fnorm = diag(H); | |
14 eta = abs(x-x_0in); | |
15 tot = m_order+s_order; | |
16 S = []; | |
17 M = []; | |
18 | |
19 % Get interior grid spacing | |
20 middle = floor(m/2); | |
21 h = x(middle+1) - x(middle); | |
22 | |
23 poss = find(tot*h/2 >= eta); | |
24 | |
25 % Ensure that poss is not too long | |
26 if length(poss) == (tot + 2) | |
27 poss = poss(2:end-1); | |
28 elseif length(poss) == (tot + 1) | |
29 poss = poss(1:end-1); | |
30 end | |
31 | |
32 % Use first tot grid points | |
33 if length(poss)<tot && x_0in < x(1) + ceil(tot/2)*h; | |
34 index=1:tot; | |
35 pol=(x(1:tot)-x(1))/(x(tot)-x(1)); | |
36 x_0=(x_0in-x(1))/(x(tot)-x(1)); | |
37 norm=fnorm(1:tot)/h; | |
38 | |
39 % Use last tot grid points | |
40 elseif length(poss)<tot && x_0in > x(end) - ceil(tot/2)*h; | |
41 index = length(x)-tot+1:length(x); | |
42 pol = (x(end-tot+1:end)-x(end-tot+1))/(x(end)-x(end-tot+1)); | |
43 norm = fnorm(end-tot+1:end)/h; | |
44 x_0 = (x_0in-x(end-tot+1))/(x(end)-x(end-tot+1)); | |
45 | |
46 % Interior, compensate for round-off errors. | |
47 elseif length(poss) < tot | |
48 if poss(end)<m | |
49 poss = [poss; poss(end)+1]; | |
50 else | |
51 poss = [poss(1)-1; poss]; | |
52 end | |
53 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
54 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
55 norm = fnorm(poss)/h; | |
56 index = poss; | |
57 | |
58 % Interior | |
59 else | |
60 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
61 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
62 norm = fnorm(poss)/h; | |
63 index = poss; | |
64 end | |
65 | |
66 h_pol = pol(2)-pol(1); | |
67 b = zeros(m_order+s_order,1); | |
68 | |
69 for i = 1:m_order | |
70 b(i,1) = x_0^(i-1); | |
71 end | |
72 | |
73 for i = 1:(m_order+s_order) | |
74 for j = 1:m_order | |
75 M(j,i) = pol(i)^(j-1)*h_pol*norm(i); | |
76 end | |
77 end | |
78 | |
79 for i = 1:(m_order+s_order) | |
80 for j = 1:s_order | |
81 S(j,i) = (-1)^(i-1)*pol(i)^(j-1); | |
82 end | |
83 end | |
84 | |
85 A = [M;S]; | |
86 | |
87 d = A\b; | |
88 ret = x*0; | |
89 ret(index) = d/h*h_pol; | |
90 end | |
91 | |
92 end |