MATLAB: My code is wrong and I don’t know why

non lineal ecuationnumerical methodunknow problem

Hi everybody, my name is Fernando Pinto, I am from Chile so I apologize for my English.
Here is the thing, I have model a non-lineal model, whit a numeric method, but when i finished the code it doesn't run. The code give me a problem that i don't understand at all and I can't find where I'm wrong. Here is my code:
if true
% K_1=250; K_2=1350; K_3=3400; K_4=3400; K_5=1600;
Y=[250,1350,3400,3400,1600];
beta=[1, 0.75, 0.5, 0.25, 0];
liquidez=[0.9, 0.75, 0.5, 0.25, 0.1];
L=liquidez;
I_1=[0,0,0.25,0.05,0];
I_2=[0,0,0.45,0.1,0];
I_3=[0,0,0,0.2,0];
I_4=[0,0,0,0,0.4];
I_5=[0,0,0,0,0];
O_1=0.5;
O_2=0.35;
O_3=0.15;
b_1_j=(sum(beta)+sum(L))*O_1;
b_2_j=(sum(beta)+sum(L))*O_2;
b_3_j=(sum(beta)+sum(L))*O_3;
r=beta.*L;
h=0.5;
a=0;
b=10;
m=(b-a)/h;
X_11=zeros(1, m+1); X_21=zeros(1, m+1); X_31=zeros(1, m+1);
X_12=zeros(1, m+1); X_22=zeros(1, m+1); X_32=zeros(1, m+1);
X_13=zeros(1, m+1); X_23=zeros(1, m+1); X_33=zeros(1, m+1);
X_14=zeros(1, m+1); X_24=zeros(1, m+1); X_34=zeros(1, m+1);
X_15=zeros(1, m+1); X_25=zeros(1, m+1); X_35=zeros(1, m+1);
X_11(1)=150; X_21(1)=75; X_31(1)=25;
X_12(1)=750; X_22(1)=500; X_32(1)=100;
X_13(1)=2500; X_23(1)=700; X_33(1)=200;
X_14(1)=2000; X_24(1)=1000; X_34(1)=400;
X_15(1)=800; X_25(1)=500; X_35(1)=300;
t=a:h:b;
for i=1:m
X_11(i+1)= X_11(i)+ h*(X_11(i)*(1-X_11(i)/K_1) + ((b_1_j-b_2_j)*X_11(i)*X_21(i)...
+((b_1_j-b_3_j)*X_11(i)*X_31(i)) + X_11*Y(1)*b_1_j + sum(I_1.*Y)*Y(1)+sum(r.*Y.*(beta+L))*O_1));
X_21(i+1)= X_21(i)+ h*(X_21(i)*(1-X_21(i)/K_1) + ((b_2_j-b_1_j)*X_21(i)*X_11(i)...
+((b_2_j-b_3_j)*X_21(i)*X_31(i))+ X_21*Y(1)*b_2_j + sum(I_1.*Y)*Y(1)+sum(r.*Y.*(beta+L))*O_2));
X_31(i+1)= X_31(i)+ h*(X_31(i)*(1-X_31(i)/K_1) + ((b_3_j-b_2_j)*X_31(i)*X_21(i)...
+((b_3_j-b_1_j)*X_31(i)*X_11(i)) + X_31*Y(1)*b_3_j + sum(I_1.*Y)*Y(1)+sum(r.*Y.*(beta+L))*O_3));
X_12(i+1)= X_12(i)+ h*(X_12(i)*(1-X_12(i)/K_2) + ((b_1_j-b_2_j)*X_12(i)*X_22(i)...
+((b_1_j-b_3_j)*X_12(i)*X_32(i)) + X_12*Y(2)*b_1_j + sum(I_1.*Y)*Y(2)+sum(r.*Y.*(beta+L))*O_1));
X_22(i+1)= X_22(i)+ h*(X_22(i)*(1-X_22(i)/K_2) + ((b_2_j-b_3_j)*X_22(i)*X_32(i)...
+((b_2_j-b_1_j)*X_22(i)*X_12(i)) + X_22*Y(2)*b_2_j + sum(I_1.*Y)*Y(2)+sum(r.*Y.*(beta+L))*O_2));
X_32(i+1)= X_32(i)+ h*(X_32(i)*(1-X_32(i)/K_2) + ((b_3_j-b_2_j)*X_32(i)*X_22(i)...
+((b_3_j-b_1_j)*X_32(i)*X_12(i)) + X_32*Y(2)*b_3_j + sum(I_1.*Y)*Y(2)+sum(r.*Y.*(beta+L))*O_3));
X_13(i+1)= X_13(i)+ h*(X_13(i)*(1-X_13(i)/K_3) + ((b_1_j-b_2_j)*X_13(i)*X_23(i)...
+((b_1_j-b_3_j)*X_13(i)*X_33(i)) + X_13*Y(3)*b_1_j + sum(I_1.*Y)*Y(3)+sum(r.*Y.*(beta+L))*O_1));
X_23(i+1)= X_23(i)+ h*(X_23(i)*(1-X_23(i)/K_3) + ((b_2_j-b_3_j)*X_23(i)*X_33(i)...
+((b_2_j-b_1_j)*X_23(i)*X_13(i)) + X_23*Y(3)*b_2_j + sum(I_1.*Y)*Y(3)+sum(r.*Y.*(beta+L))*O_2));
X_33(i+1)= X_33(i)+ h*(X_33(i)*(1-X_33(i)/K_3) + ((b_3_j-b_2_j)*X_33(i)*X_23(i)...
+((b_3_j-b_1_j)*X_33(i)*X_13(i)) + X_33*Y(3)*b_3_j + sum(I_1.*Y)*Y(3)+sum(r.*Y.*(beta+L))*O_3));
X_14(i+1)= X_14(i)+ h*(X_14(i)*(1-X_14(i)/K_4) + ((b_1_j-b_2_j)*X_14(i)*X_24(i)...
+((b_1_j-b_3_j)*X_14(i)*X_34(i)) + X_14*Y(4)*b_1_j + sum(I_1.*Y)*Y(4)+sum(r.*Y.*(beta+L))*O_1));
X_24(i+1)= X_24(i)+ h*(X_24(i)*(1-X_24(i)/K_4) + ((b_2_j-b_3_j)*X_24(i)*X_34(i)...
+((b_2_j-b_1_j)*X_24(i)*X_14(i)) + X_24*Y(4)*b_2_j + sum(I_1.*Y)*Y(4)+sum(r.*Y.*(beta+L))*O_2));
X_34(i+1)= X_34(i)+ h*(X_34(i)*(1-X_34(i)/K_4) + ((b_3_j-b_2_j)*X_34(i)*X_24(i)...
+((b_3_j-b_1_j)*X_34(i)*X_14(i)) + X_34*Y(4)*b_3_j + sum(I_1.*Y)*Y(4)+sum(r.*Y.*(beta+L))*O_3));
X_15(i+1)= X_15(i)+ h*(X_15(i)*(1-X_15(i)/K_5) + ((b_1_j-b_2_j)*X_15(i)*X_25(i)...
+((b_1_j-b_3_j)*X_15(i)*X_35(i)) + X_15*Y(5)*b_1_j + sum(I_1.*Y)*Y(5)+sum(r.*Y.*(beta+L))*O_1));
X_25(i+1)= X_25(i)+ h*(X_25(i)*(1-X_25(i)/K_5) + ((b_2_j-b_3_j)*X_25(i)*X_35(i)...
+((b_2_j-b_1_j)*X_25(i)*X_15(i)) + X_25*Y(5)*b_2_j + sum(I_1.*Y)*Y(5)+sum(r.*Y.*(beta+L))*O_2));
X_35(i+1)= X_35(i)+ h*(X_35(i)*(1-X_35(i)/K_5) + ((b_3_j-b_2_j)*X_35(i)*X_25(i)...
+((b_3_j-b_1_j)*X_35(i)*X_15(i)) + X_35*Y(5)*b_3_j + sum(I_1.*Y)*Y(5)+sum(r.*Y.*(beta+L))*O_3));
end
plot(t, X_11), xlabel( 'Time' ), ylabel( 'X_11' ) end
I don't know how works the button to put my code so I apologize again for that.
The code is kind of tricky, because it is not a problem that I can write with words, the problem requires that I have to make suposicions, but the thing is that i must plot this and every X_1j must be in a graphic and X_2j in another and X_3j too. The problem that the code give me is this: "In an assignment A(I) = B, the number of elements in B and I must be the same."
I understand that it's a problem with the size of my X(i+1), but how can i fix it? I need to use a Numerical method to solve this problem and I must plot this so please help me I can't get the problem and I try to figure out with just one line of code but that give me the same problem.
I hope someone can help me I will be waiting for answers and the help you can give me. Gretings!

Best Answer

When you try to define X_11(i+1), there is X_11(X_11*Y(1)*b_1_j) on the right side. You have to change X_11 to X_11(i) or some other element instead of an array or matrix. Likewise, other definition also needs revision.