-
Notifications
You must be signed in to change notification settings - Fork 7
/
WG2D_GetHxHyHz_f.m
113 lines (92 loc) · 6.25 KB
/
WG2D_GetHxHyHz_f.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function[Hx,Hy,Hz]=WG2D_GetHxHyHz_f(x,y,Ex,Ey,eps,neff,lambda)
Nx=length(x);
Ny=length(y);
Nxy=Nx*Ny;
dx=x(2)-x(1);
dy=y(2)-y(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c=2.99792458e8; %% m/s
eps0=8.85418782e-12; %% F/m
mu0 = 4*pi*1e-7; %% H/m
k0=2*pi/lambda;
w=c*k0;
Beta=neff^2*k0^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Building of the operators %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
AA=ones(1,Nx*Ny);
BB=ones(1,Nx*Ny-1);
BB(Ny:Ny:end)=0;
DY1=diag(BB,-1)*(-0.5) + diag(BB,1)*(0.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Axy=ones(1,(Nx-1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 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% -1/2 0 0 0 0 | 0 0 0 0 0 |1/2 0 0 0 0 | 0 0 0 0 0 %
% 0 -1/2 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 -1/2 0 0 | 0 0 0 0 0 | 0 0 1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 -1/2| 0 0 0 0 0 | 0 0 0 0 1/2| 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 -1/2 0 0 0 0 | 0 0 0 0 0 |1/2 0 0 0 0 %
% 0 0 0 0 0 | 0 -1/2 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 %
% 0 0 0 0 0 | 0 0 -1/2 0 0 | 0 0 0 0 0 | 0 0 1/2 0 0 %
% 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 1/2 0 %
% 0 0 0 0 0 | 0 0 0 0 -1/2| 0 0 0 0 0 | 0 0 0 0 1/2 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 -1/2| 0 0 0 0 0 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%% First derivative Y %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DY1(Ny=5,Nx=4); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 0 1/2 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% -1/2 0 1/2 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 -1/2 0 1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 -1/2 0 1/2| 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 -1/2 0 1/2 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 -1/2 0 1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 -1/2 0 1/2| 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 1/2| 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 1/2 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 1/2 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 1/2 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%