Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem regarding Matlab code for n no of quantum well

  1. Dec 21, 2011 #1
    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.
     
  2. jcsd
  3. Dec 22, 2011 #2

    Cthugha

    User Avatar
    Science Advisor

    Your matrix dimensions do not match.
    You defined:
    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
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem regarding Matlab code for n no of quantum well
  1. Quantum well? (Replies: 4)

  2. LaTeX code for Quantum (Replies: 1)

Loading...