-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergy_test.m
43 lines (30 loc) · 840 Bytes
/
energy_test.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
function [Error,R,T] = energy_test(H,geo,pd,dens,Lp,Lm,dLp,dLm)
L = pd.L;
Nx = 100;h= L/Nx;
x0 = -L/2 +(0:Nx-1)*h;
u = evaluate_field_super_cell(x0,[-H H],pd,geo,dens,Lp,Lm,dLp,dLm,'s');
beta = abs(pd.beta);
S = 0.0;
R = 0;
% T = 1;
for j=1:numel(pd.beta_n)
alpha_n = pd.alpha_n(j);
beta_n = pd.beta_n(j);
apn = h/L*exp(-1i*alpha_n*x0)*u(2,:).';
Bp = exp(-1i*beta_n*H)*apn;
amn = h/L*exp(-1i*alpha_n*x0)*u(1,:).';
Bm = exp(-1i*beta_n*H)*amn;
if pd.prop_modes(j)==0
B0 = Bm;
end
S = S + beta_n/beta*(abs(Bp)^2+abs(Bm)^2);
R = R + beta_n/beta*abs(Bp)^2;
% T = T + beta_n/beta*abs(Bm)^2;
% R = R + abs(Bp)^2;
% T = T + abs(Bm)^2;
end
Error = abs(2*real(B0)+S);
% T = T+2*real(B0);
T=1+2*real(B0)+S-R;
% R = R/2/real(B0);
% T = T/2/real(B0);