Hi.I have a code error.

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

Error in rate_eq_program_1 (line 26)

ys(1) = I./(E.*Vp)-(z(1)./tc)-GN.*(z(1)-Ntr).*sigmas.*((abs(z(3)).^2)./Vc);

`%%%%%%%%%%%%%%%%%%%%%%%% constants %%%%%%%%%%%%%%%%%%%%%%%%%`

q = 1.6021766208e-19; c = 2.99792458e8; kk = 1.38e-23; kk_eV = kk/q; T = 300; h = 6.626068e-34; h_eV = h/q; hbar = h/(2*pi); hbar_eV = hbar/q; epsilon0 = 8.854187817e-12; P = -1; rL = 1;rB = 0.2 ;tB = sqrt(1-rB^2);Qt =500;% Qc =180;

Qi = 14300;Qp = 10000;%Qc = 1800;

L = 5e-6;ng = 3.5;sigma = 3;m = 25;A = 0.105e-12; confine = 0.5;Vp = 0.576e-18; Vc = confine*A*L;gN =5e-20;Ntr = 1e24;tc = 0.5e-9; %tc = 0.7e-9;

alphai = 1000;%alpha = 1.5;

alpha =1;confinec = 0.3;vg = c/ng;vgp = c/6/ng;Vpc = 0.22e-18;KD = confinec*vgp*alpha*gN/2; KA = -confinec*vgp*gN/2;lambda0 = 1554e-9;deltalambda = 0.01e-9;lambda_start = 1540e-9;lambda_end = 1560e-9;lambda = lambda_start:deltalambda:lambda_end;omega = 2*pi*c./lambda;omega0 = omega(find(lambda==lambda0));E = hbar_eV.*omega;gamai = omega./2/Qi;gamap = omega./2/Qp;gamat = omega./2/Qt;%gamac = omega./2/Qc;

%gamac = omega./2/Qc;gamac = gamat-gamai-gamap;gama1 = gamac./2;gama2 = gama1;COS2 = 0.5*gama1./gama1.*tB^2/rB-0.5*tB^2/rB-rB;SIN2 = P*tB./(2.*gama1*rB).*sqrt(4.*gama1.*gama1 - tB^2.*(gamac.^2));% CS12 = 1/(1i*tB).*(1i*SIN2 + rB);

GLA = gN*vgp./(E.*Vpc*q);GN = confine*vg*gN;tin = 2*L/vg;M = 0.5*(length(E)-1);Tmin = 0;Tmax = 5e-9;dt = 0.01e-12;Time = Tmin:dt:Tmax;N0 = zeros(1,4);N0(3) = 0.2;%I =2e-3;TA I =12e-3;

I =0.5e-3;Vnc= 0.24e-18;%%%%%%%%%%%%%%%%%%%%%%% main code %%%%%%%%%%%%%%%%%%%%%%%%%%%

Time = Tmin:dt:Tmax; z0 = [0.2,0.2,0.2,0.2]; [t,z] = ode45(@rate_eq_program_1,Time,z0);param_rate_eqfigure(1)plot(t,z(:,1)); % divided to normalize

xlabel('time [ns]','FontSize',14); % size of x label

ylabel('Arbitrary units','FontSize',14); % size of y label

set(gca,'FontSize',14); % size of tick marks on both axis

legend('N', 'Location','SE') % legend inside the plot

figure(2)plot(t,z(:,2)); % divided to normalizexlabel('time [ns]','FontSize',14); % size of x labelylabel('Arbitrary units','FontSize',14); % size of y labelset(gca,'FontSize',14); % size of tick marks on both axislegend('NC', 'Location','SE') % legend inside the plot%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function %%%%%%%%%%%%%%%%%%%%%%%%

function ys = rate_eq_program_1(t,z)param_rate_eq_fanoys=zeros(4,1);%rR=(-p*gamma_c)/(1i*(delta_c)+gamma_T-1/2*(1-1i*henry)*conf_NC*V_g*g_n*(z(2)-N_0));

deltawc=KD.*(z(2))-1i*KA.*(z(2));deltac=omega0+deltawc-omega;rR=(-P.*gamac)./(1i*(deltac)+gamat-(1/2*(1-1i)*confinec*vg*gN).*(z(2)-Ntr));rRS=-P.*gamac./(1i.*(deltac)+gamat);%rRS=rB+(-1i*tB-rB).*gamac./(1i.*(deltac)+gamat);

g=alphai+(1/(2*L)).*log(1./(abs(rRS)).^2);A=(2*epsilon0*n*ng)./(hbar.*omega0);B=(1+(abs(rRS))).*(1-(abs(rRS)));D=((g)-alphai);H=c./(omega0.*n);F=imag(rRS)./abs(rRS);sigmas=A.*((B./D)+(H.*F));ys(1) = I./(E.*Vp)-(z(1)./tc)-GN.*(z(1)-Ntr).*sigmas.*((abs(z(3)).^2)./Vc);ys(2) = (-z(2)./tc)-GLA.*(z(2)-Ntr).*(abs(z(4)).^2)./Vnc;ys(3) = 1/2*(1-1i)*GN.*(z(1)-Nss).*z(3)+(1/tin.*((z(4)./rR)-z(3)));ys(4) =((-1i.*deltawc-gamat).*z(4))-(P.*gamac.*z(3))+(1/2*(1-1i).*confinec*vg*gN.*(z(2)-Ntr).*z(4));ys = ys';end

i tried ys=zeros(4,M) But it's also a mistake.

i tried ys=zeros(4,length(E)) But it's also a mistake.

….

Thanks for helping someone.

## Best Answer