Unable to perform assignment because the left and right sides have a different number of elements.

1 view (last 30 days)
I dont know what is the issue in this code,
q = 1.6e-19;
E = [-0.5:0.001:0.5]; % [eV]
V = [0:0.001:0.5]; % [V]
mu = 0; % [eV]
kB = 1.38e-23; % [J/K]
kB = kB/q; % [eV/K]
h = 6.626e-34/(44/7); % [J.s]
h = h/q; % [eV.s]
const = (2*q)/h; % [C/eV.s]
T = 300; % [K]
g1 = 0.2; % [eV], gamma1
g2 = 0.2; % [eV], gamma2
g = 0.1;
dE = 0.001; % [eV], delta E
D = zeros(1,length(E));
for i = 1:length(E)
if E(i) >= -0.1
D(i) = 0.5;
else
D(i) = 0;
end
end
mu1 = zeros(1,length(V));
mu2 = zeros(1,length(V));
f1 = zeros(1,length(V));
f2 = zeros(1,length(V));
f = zeros(1,length(V));
F = zeros(1,length(V));
I = zeros(1,length(V));
for i = 1:length(V)
mu1(i) = mu + (q*V(i))/2;
mu2(i) = mu - (q*V(i))/2;
f1(i) = 1 ./ (1+exp((E-mu1(i))/(kB*T)));
f2(i) = 1 ./ (1+exp((E-mu2(i))/(kB*T)));
f(i) = f1(i)-f2(i);
F(i) = D(i)*g*f(i)*dE;
I(i) = const*sum(F(i));
end
disp(I);

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 29 Sep 2020
You can debug your code by setting breakpoint on the line where you are getting error, refer to Set Breakpoints for more information.
In line 37, LHS & RHS have differenent sizes i.e.,
K>> size(f1(i))
ans =
1 1
K>> size(1 ./ (1+exp((E-mu1(i))/(kB*T))))
ans =
1 1001
Hence the assigment fails in line 37.

Community Treasure Hunt

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

Start Hunting!