Problem regarding Matlab code for n no of quantum well

In summary, your code is trying to assign matrices of different dimensions to each other which cannot work. You need to make sure that the dimensions of the matrices you are assigning are compatible.
  • #1
Rajat Karmaka
1
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
  • #2
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.
 

1. How do I define the number of quantum wells in my Matlab code?

The number of quantum wells in a Matlab code can be defined by using the "for" loop to iterate through the desired number of wells. Each iteration will create a new well with unique properties.

2. What is the best way to visualize the quantum wells in my code?

One way to visualize the quantum wells in your Matlab code is by using the "plot" function to create a graph of the potential energy profile. You can also use the "surf" function to create a 3D visualization of the wells.

3. How can I calculate the energy levels of the quantum wells in my code?

The energy levels of the quantum wells can be calculated using the Schrodinger equation and the properties of the wells such as their width and depth. You can also use the "eig" function in Matlab to calculate the eigenvalues of the Hamiltonian matrix.

4. Can I add additional parameters to my quantum well code?

Yes, you can add additional parameters to your quantum well code by defining them as variables and using them in your calculations. This can allow for more customization and flexibility in your code.

5. How can I optimize my quantum well code for faster computation?

One way to optimize your quantum well code for faster computation is by vectorizing your calculations. This means using array operations instead of looping through each element, which can significantly improve the speed of your code. You can also consider using parallel computing techniques or optimizing your algorithm for better efficiency.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • Programming and Computer Science
Replies
4
Views
622
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
933
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Replies
1
Views
1K
Back
Top