Problem regarding Matlab code for n no of quantum well

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
Rajat Karmaka
Messages
1
Reaction score
0
I have written a code which is something like that

clc
X = input('Molefraction of Al in system:');
n=input('no of well:');

width=zeros(1,50);
for j=1:(2*n+1)
width(j,:)=input('length of areas:');
end

del_eg=1.247*X;
V1=0.6*del_eg;
V=zeros(1,100);
for j=1:n
V(2*j,:)=0;
V(((2*j)+1),:)=0.6*del_eg;
V(1)=0.6*del_eg;
end

y=1;

hbar = 1.055e-34; %hbar in ev*m
m0 = 9.11e-31; %Rest mass of the electron in eV
q = 1.602e-19;

Xi=0;
L=zeros(1,100);
for j=1:(2*n-1)
L(j,:) =Xi+width(j+1);
Xi=L(j);
end

Y=0;
x=zeros(1,1000);
for j=1:n
x(((2*j)-1),:)=Y;
x(2*j,:)=L((2*j)-1);
Y=L(2*j);
end

meff=zeros(1,1000);
for j=1:n
meff(2*j,:)=0.067*m0;
meff(((2*j)+1),:)=0.08*m0;
meff(1)=0.08*m0;
end

for E = 0.0001:0.0001:(V1-0.0001);

k=zeros(1,1000);
for j=1:n
k(2*j,:)=sqrt((2*meff(2*j)*(E - V(2*j))*q)/(hbar^2));
k(((2*j)+1),:)=sqrt((2*meff((2*j)+1)*(E - V((2*j)+1))*q)/(hbar^2));
k(1)=sqrt((2*meff(1)*(E - V(1))*q)/(hbar^2));
end

m1=zeros(1,4);
m2=zeros(1,4);
m3=zeros(1,4);
m4=zeros(1,4);
M=repmat(0,2,2);

for j=1:(2*n)
m1(j,:) = ((1/2)*((1 + ((k(j)*meff(j+1))/(k(j+1)*meff(j))))*exp(1i*(x(j)*(k(j) - k(j+1))))));
m2(j,:) = ((1/2)*((1 - ((k(j)*meff(j+1))/(k(j+1)*meff(j))))*exp(-(1i*(x(j)*(k(j) + k(j+1)))))));
m3(j,:) = ((1/2)*((1 - ((k(j)*meff(j+1))/(k(j+1)*meff(j))))*exp(1i*(x(j)*(k(j) + k(j+1))))));
m4(j,:) = ((1/2)*((1 + ((k(j)*meff(j+1))/(k(j+1)*meff(j))))*exp(-(1i*(x(j)*(k(j) - k(j+1)))))));

M(j,:) = [m1(j),m2(j);m3(j),m4(j)];

end

d=repmat(1,2,2);
Mf=repmat(0,2,2);
for j=1:n
Mf(j,:)=M((2*j)-1)*M(2*j)*d;
d=Mf(j);
end

J22=d(2,2);

z = y;
y = real(J22);

if z*y < 0

disp(E)

end

end

now there is an error-

?? Subscripted assignment dimension mismatch.

Error in ==> kihobekejane at 68
M(j,:) = [m1(j),m2(j);m3(j),m4(j)];

how can i remove this problem? please help me.
 
Physics news on Phys.org
Your matrix dimensions do not match.
You defined:
Rajat Karmaka said:
m1=zeros(1,4);
m2=zeros(1,4);
m3=zeros(1,4);
m4=zeros(1,4);
M=repmat(0,2,2);

So m1 to m4 are matrices that look like
0 0 0 0
and M looks like
0 0
0 0

Then you try to assign
Rajat Karmaka said:
M(j,:) = [m1(j),m2(j);m3(j),m4(j)];

M(j,:) is the jth row of matrix M and looks like
0 0.
Now you try to assign a matrix of 2x2 values to a 1x2 matrix which cannot work.
Also, your loop over j goes from 1 to 2n while M is statically defined to be a 2x2 matrix. This will also cause problems.