annotate +sbp/+implementations/d1_gauss_4.m @ 405:4d9d8064e58b feature/SBPInTimeGauss

Implementation of D1 based on Gauss quadrature formula with 4 nodes.
author Martin Almquist <martin.almquist@it.uu.se>
date Thu, 02 Feb 2017 17:05:43 +0100
parents
children ba73c9c8d1a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
405
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
1 function [D1,H,x,h,e_l,e_r] = d1_gauss_4(N,L)
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
2
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
3 % L: Domain length
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
4 % N: Number of grid points
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
5 if(nargin < 2)
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
6 L = 1;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
7 end
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
8
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
9 if(N~=4)
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
10 error('This operator requires exactly 4 grid points');
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
11 end
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
12
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
13 % Quadrature nodes on interval [-1, 1]
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
14 x = [ -0.8611363115940526; -0.3399810435848563; 0.3399810435848563; 0.8611363115940526];
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
15
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
16 % Shift nodes to [0,L]
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
17 x = (x+1)/2*L;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
18
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
19 % Boundary extrapolation operators
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
20 e_l = [1.5267881254572668; -0.8136324494869273; 0.4007615203116504; -0.1139171962819899];
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
21 e_r = flipud(e_l);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
22 e_l = sparse(e_l);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
23 e_r = sparse(e_r);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
24
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
25 %%%% Compute approximate h %%%%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
26 h = L/(N-1);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
27 %%%%%%%%%%%%%%%%%%%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
28
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
29 %%%% Norm matrix on [-1,1] %%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
30 P = sparse(N,N);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
31 P(1,1) = 0.3478548451374539;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
32 P(2,2) = 0.6521451548625461;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
33 P(3,3) = 0.6521451548625461;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
34 P(4,4) = 0.3478548451374539;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
35 %%%%%%%%%%%%%%%%%%%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
36
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
37 %%%% Norm matrix on [0,L] %%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
38 H = P*L/2;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
39 %%%%%%%%%%%%%%%%%%%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
40
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
41 %%%% D1 on [-1,1] %%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
42 D1 = sparse(N,N);
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
43 D1(1,1) = -3.3320002363522817;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
44 D1(1,2) = 4.8601544156851962;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
45 D1(1,3) = -2.1087823484951789;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
46 D1(1,4) = 0.5806281691622644;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
47
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
48 D1(2,1) = -0.7575576147992339;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
49 D1(2,2) = -0.3844143922232086;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
50 D1(2,3) = 1.4706702312807167;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
51 D1(2,4) = -0.3286982242582743;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
52
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
53 D1(3,1) = 0.3286982242582743;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
54 D1(3,2) = -1.4706702312807167;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
55 D1(3,3) = 0.3844143922232086;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
56 D1(3,4) = 0.7575576147992339;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
57
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
58 D1(4,1) = -0.5806281691622644;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
59 D1(4,2) = 2.1087823484951789;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
60 D1(4,3) = -4.8601544156851962;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
61 D1(4,4) = 3.3320002363522817;
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
62 %%%%%%%%%%%%%%%%%%%%%%%%%
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
63
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
64 % D1 on [0,L]
4d9d8064e58b Implementation of D1 based on Gauss quadrature formula with 4 nodes.
Martin Almquist <martin.almquist@it.uu.se>
parents:
diff changeset
65 D1 = D1*2/L;