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 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 11 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 13 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9 13.9];
p=zeros(1,199);
k=(2.*pi./lmda);
bet=sqrt(k^2-(pi/a)^2);
x0=input ('enter x0:');
w=input ('enter w:');
d=(pi*x0)/a;
f=(pi*w)/a;
x11=zeros(1,199);
x22=zeros(1,199);
for n=1:1:10
for m=1:1:8
y=sqrt(((m.*pi./a)).^2+((n.*pi./b)).^2-k.^2);
end
end
xx1=zeros(1,199);
xx2=zeros(1,199);
for n=1:1:9
for m=1:1:8
x11=x11+(((-em(n)*bet*cos(n*pi)^2)).*x22);
x22=(em(m)*(((cos(m*d)/(cos(d)))^2)*(((sin(m*f)/(m*f))/(sin(f)/f))^2)));
end
end
x1=x11.*x22.*(0.5*(1+exp(-2*y*l))-cos(k*l).*(2*(exp(-y.*l))-cos(k*l)+(y/k)*sin(k*l))/(2*a*b*y*((k.^2)+(y.^2))*(cos(bet*l)-cos(k*l)).^2));
d1=(pi*x0)/b;
f1=(pi*w)/b;
for n=1:1:9
for m=1:1:8
xx1=xx1+((([sin(n*pi/2)]^2)*[((cos(n*pi*l/a)-cos(k*l)).^2)/((k^2)-((n*pi/a)^2))]).*xx2);
xx2=(xx2+(((cos(m*d1)/cos(d))^2)*bet*((sin(m*f1))/(m*f1))/(sin(f)/f)^2));
end
end
xx3=1./(a*b*y*(cos(bet*l)-cos(k*l)).*(cos(bet*l)-cos(k*l)));
x2=xx1.*xx2.*xx3;
for n=1:1:9
for m=1:1:8
z0=377;
x=x1+x2;
end
end
%p= sqrt(((pi/(2.*l))^2)-(k^2));
t=1.27;
c=10*((log(4./(9*ones(1,199)+(4.*(x.*x)))))-(8.686*p*t));
if l > 14
c = -50
end
% plot(l,c);
% %axis([2 18 -100 0])
% xlabel('slot length in mm')
% ylabel('coupling in dB')
for i=1:7
p= sqrt((pi/(2.*l(i))^2)-(k^2));
end
% -(8.686*p*t;
c1=[-40.1102 -41.1102 -42.1102 -43.1102 -44.1102 -45.1102 -46.1102 -47.1102 -48.1102];
c1=c1+21+10-32-16+17+8;
c=[c c1];
l=[l 13.9 14 15 16 17 18 19 20 21];
plot(l,c);
axis([2 22 -100 0])
xlabel('slot length in mm')
ylabel('coupling in dB')