Mercurial > repos > public > sbplib
comparison diracDiscr.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 | 3a9262c045d0 |
children |
comparison
equal
deleted
inserted
replaced
1128:3a9262c045d0 | 1129:b29892853daf |
---|---|
24 % Perform outer product, transpose, and then turn into column vector | 24 % Perform outer product, transpose, and then turn into column vector |
25 d = (d_1D{i}*d')'; | 25 d = (d_1D{i}*d')'; |
26 d = d(:); | 26 d = d(:); |
27 end | 27 end |
28 end | 28 end |
29 | |
30 end | |
31 | |
32 | |
33 % Helper function for 1D delta functions | |
34 function ret = diracDiscr1D(x_0in , x , m_order, s_order, H) | |
35 | |
36 m = length(x); | |
37 | |
38 % Return zeros if x0 is outside grid | |
39 if(x_0in < x(1) || x_0in > x(end) ) | |
40 | |
41 ret = zeros(size(x)); | |
42 | |
43 else | |
44 | |
45 fnorm = diag(H); | |
46 eta = abs(x-x_0in); | |
47 tot = m_order+s_order; | |
48 S = []; | |
49 M = []; | |
50 | |
51 % Get interior grid spacing | |
52 middle = floor(m/2); | |
53 h = x(middle+1) - x(middle); | |
54 | |
55 poss = find(tot*h/2 >= eta); | |
56 | |
57 % Ensure that poss is not too long | |
58 if length(poss) == (tot + 2) | |
59 poss = poss(2:end-1); | |
60 elseif length(poss) == (tot + 1) | |
61 poss = poss(1:end-1); | |
62 end | |
63 | |
64 % Use first tot grid points | |
65 if length(poss)<tot && x_0in < x(1) + ceil(tot/2)*h; | |
66 index=1:tot; | |
67 pol=(x(1:tot)-x(1))/(x(tot)-x(1)); | |
68 x_0=(x_0in-x(1))/(x(tot)-x(1)); | |
69 norm=fnorm(1:tot)/h; | |
70 | |
71 % Use last tot grid points | |
72 elseif length(poss)<tot && x_0in > x(end) - ceil(tot/2)*h; | |
73 index = length(x)-tot+1:length(x); | |
74 pol = (x(end-tot+1:end)-x(end-tot+1))/(x(end)-x(end-tot+1)); | |
75 norm = fnorm(end-tot+1:end)/h; | |
76 x_0 = (x_0in-x(end-tot+1))/(x(end)-x(end-tot+1)); | |
77 | |
78 % Interior, compensate for round-off errors. | |
79 elseif length(poss) < tot | |
80 if poss(end)<m | |
81 poss = [poss; poss(end)+1]; | |
82 else | |
83 poss = [poss(1)-1; poss]; | |
84 end | |
85 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
86 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
87 norm = fnorm(poss)/h; | |
88 index = poss; | |
89 | |
90 % Interior | |
91 else | |
92 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
93 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1))); | |
94 norm = fnorm(poss)/h; | |
95 index = poss; | |
96 end | |
97 | |
98 h_pol = pol(2)-pol(1); | |
99 b = zeros(m_order+s_order,1); | |
100 | |
101 for i = 1:m_order | |
102 b(i,1) = x_0^(i-1); | |
103 end | |
104 | |
105 for i = 1:(m_order+s_order) | |
106 for j = 1:m_order | |
107 M(j,i) = pol(i)^(j-1)*h_pol*norm(i); | |
108 end | |
109 end | |
110 | |
111 for i = 1:(m_order+s_order) | |
112 for j = 1:s_order | |
113 S(j,i) = (-1)^(i-1)*pol(i)^(j-1); | |
114 end | |
115 end | |
116 | |
117 A = [M;S]; | |
118 | |
119 d = A\b; | |
120 ret = x*0; | |
121 ret(index) = d/h*h_pol; | |
122 end | |
123 | |
124 end | 29 end |
125 | 30 |
126 | 31 |
127 | 32 |
128 | 33 |