Error message with code

I am trying to write a code that plots TE waves for band structure showing allowed and forbidden bands. Below is what I have been able to come up with but it doesn't work! I am trying to tell matlab to plot a graph when the condition that m = or grater than + or -1 is met. In the work space when I run the code, m gives 1x300 which is definetely not correct! I want it to show 300X300.
Again, I get the error message "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2."
Your help would be highly appreciated.
clear all
n1=3.0; %refractive index of medium 1
n2=2.2; %refractive index of medium 2
a=0.5; %thickness of medium 1 in microns
b=0.5; %thickness of medium 2 in microns
c=300000000; %speed of light in vacuum;
Lambda= a+b; %period of the structure
M=300; N=M;
omega=linspace(1e-3,1,N); %angular frequency;
beta=linspace(1e-3,1,M);
m =[];
for j=1:N
for k=1:M
w=omega(k);
B=beta(j);
B=(w./c); %propagation constant
b1=((w./c).*n1).^2;
k1=sqrt(b1-B.^2);
b2=((w./c).*n2).^2;
k2=sqrt(b2-B.^2);
A(j,k)=exp(-1i.*k1.*a).*(cos(k2.*b)-(1i/2).*(k2./k1+k1./k2).*sin(k2.*b));
D(j,k)=exp(1i.*k1.*a).*(cos(k2.*b)+(1i/2).*(k2./k1+k1./k2).*sin(k2.*b));
m(j,k)=acos((A+D)./2); %m is a function of beta and omega
K=(1./Lambda).*m; %K is a function of beta and omega
end
end
[x,y]=meshgrid(omega,beta);
L=abs(m')>=1;
yte=y(L);
scatter(L,yte)

4 Commenti

Try this code below after some corrections. you will now get size of m as you wanted or specified 300x300. It does not show assignment or any errors now
clear all
n1=3.0; %refractive index of medium 1
n2=2.2; %refractive index of medium 2
a=0.5; %thickness of medium 1 in microns
b=0.5; %thickness of medium 2 in microns
c=300000000; %speed of light in vacuum;
Lambda= a+b; %period of the structure
M=300; N=M;
omega=linspace(1e-3,1,N); %angular frequency;
beta=linspace(1e-3,1,M);
m =[];
for j=1:N
for k=1:M
w=omega(j);
B=beta(k);
B=(w/c); %propagation constant
b1=((w/c)*n1)^2;
k1=sqrt(b1-B^2);
b2=((w/c)*n2)^2;
k2=sqrt(b2-B^2);
A(j,k)=exp(-1i*k1*a)*(cos(k2*b)-(1i/2)*(k2/k1+k1/k2)*sin(k2*b));
D(j,k)=exp(1i*k1*a)*(cos(k2*b)+(1i/2)*(k2/k1+k1/k2)*sin(k2*b));
m(j,k)=acos((A(j,k)+D(j,k))/2); %m is a function of beta and omega
K(j,k)=(1/Lambda)*m(j,k); %K is a function of beta and omega
end
end
% [x,y]=meshgrid(omega,beta);
% L=abs(m')>=1;
% yte=y(L);
% scatter(L,yte)
Emma K.
Emma K. il 10 Ott 2020
Thanks! Now it runs without errors but the graph is empty. What’s wrong? Could someone help out? Thank you
Emma K.
Emma K. il 10 Ott 2020
The graph I am trying to get is fig. 3 in “electromagnetic propagation in periodic stratified media.I General theory” by Pochi Yeh et al,1977. Thank you
Sudhakar Shinde
Sudhakar Shinde il 10 Ott 2020
As you stated 'm' is a function of beta and omega. This 'm' variable now contains values less than or equal to 1 only and to plot on the values at last you used:
L=abs(m')>=1;
As there is no any values greater than 1 available in m variable, result is empty.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Richiesto:

il 10 Ott 2020

Commentato:

il 10 Ott 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by