comparison +sbp/+implementations/d1_noneq_minimal_4.m @ 261:6009f2712d13 operator_remake

Moved and renamned all implementations.
author Martin Almquist <martin.almquist@it.uu.se>
date Thu, 08 Sep 2016 15:35:45 +0200
parents
children bfa130b7abf6
comparison
equal deleted inserted replaced
260:b4116ce49ac4 261:6009f2712d13
1 function [D1,H,x,h] = d1_noneq_minimal_4(N,L)
2
3 % L: Domain length
4 % N: Number of grid points
5 if(nargin < 2)
6 L = 1;
7 end
8
9 % BP: Number of boundary points
10 % m: Number of nonequidistant spacings
11 % order: Accuracy of interior stencil
12 BP = 3;
13 m = 1;
14 order = 4;
15
16 %%%% Non-equidistant grid points %%%%%
17 x0 = 0.0000000000000e+00;
18 x1 = 7.7122987842562e-01;
19 x2 = 1.7712298784256e+00;
20 x3 = 2.7712298784256e+00;
21
22 xb = zeros(m+1,1);
23 for i = 0:m
24 xb(i+1) = eval(['x' num2str(i)]);
25 end
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 %%%% Compute h %%%%%%%%%%
29 h = L/(2*xb(end) + N-1-2*m);
30 %%%%%%%%%%%%%%%%%%%%%%%%%
31
32 %%%% Define grid %%%%%%%%
33 x = h*[xb; linspace(xb(end)+1,L/h-xb(end)-1,N-2*(m+1))'; L/h-flip(xb) ];
34 %%%%%%%%%%%%%%%%%%%%%%%%%
35
36 %%%% Norm matrix %%%%%%%%
37 P = zeros(BP,1);
38 %#ok<*NASGU>
39 P0 = 2.6864248295847e-01;
40 P1 = 1.0094667153500e+00;
41 P2 = 9.9312068011715e-01;
42
43 for i = 0:BP-1
44 P(i+1) = eval(['P' num2str(i)]);
45 end
46
47 H = ones(N,1);
48 H(1:BP) = P;
49 H(end-BP+1:end) = flip(P);
50 H = spdiags(h*H,0,N,N);
51 %%%%%%%%%%%%%%%%%%%%%%%%%
52
53 %%%% Q matrix %%%%%%%%%%%
54
55 % interior stencil
56 switch order
57 case 2
58 d = [-1/2,0,1/2];
59 case 4
60 d = [1/12,-2/3,0,2/3,-1/12];
61 case 6
62 d = [-1/60,3/20,-3/4,0,3/4,-3/20,1/60];
63 case 8
64 d = [1/280,-4/105,1/5,-4/5,0,4/5,-1/5,4/105,-1/280];
65 case 10
66 d = [-1/1260,5/504,-5/84,5/21,-5/6,0,5/6,-5/21,5/84,-5/504,1/1260];
67 case 12
68 d = [1/5544,-1/385,1/56,-5/63,15/56,-6/7,0,6/7,-15/56,5/63,-1/56,1/385,-1/5544];
69 end
70 d = repmat(d,N,1);
71 Q = spdiags(d,-order/2:order/2,N,N);
72
73 % Boundaries
74 Q0_0 = -5.0000000000000e-01;
75 Q0_1 = 6.1697245625434e-01;
76 Q0_2 = -1.1697245625434e-01;
77 Q0_3 = 0.0000000000000e+00;
78 Q0_4 = 0.0000000000000e+00;
79 Q1_0 = -6.1697245625434e-01;
80 Q1_1 = 0.0000000000000e+00;
81 Q1_2 = 7.0030578958767e-01;
82 Q1_3 = -8.3333333333333e-02;
83 Q1_4 = 0.0000000000000e+00;
84 Q2_0 = 1.1697245625434e-01;
85 Q2_1 = -7.0030578958767e-01;
86 Q2_2 = 0.0000000000000e+00;
87 Q2_3 = 6.6666666666667e-01;
88 Q2_4 = -8.3333333333333e-02;
89 for i = 1:BP
90 for j = 1:BP
91 Q(i,j) = eval(['Q' num2str(i-1) '_' num2str(j-1)]);
92 Q(N+1-i,N+1-j) = -eval(['Q' num2str(i-1) '_' num2str(j-1)]);
93 end
94 end
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 %%%% Difference operator %%
98 D1 = H\Q;
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%