Trying to fix a problem in a MATLAB code (Array indices must be positive integers or logical values)
Channel: Mathias Magdowski
Date: 23/05/2020

Fixed versions of the programs:


function dXdt = trash(t,X);
global F1 L2 F2 F3 F4 T3 T201 M lambdas F100 C F5 T100 UA2 T200 F200 Q200 P100 ROA Q100 Cp T1 lambda X1 X2 P2 T2 
dL2dt = (F1-F2-F4)/ROA;
dX2dt = (F1*X1-F2*X2)/M;
dP2dt = (F4-F5) /C;
T2 = 0.5616*P2 + 0.3126*X2 + 48.43;
T3 = 0.507*P2 + 55;
F4 = (Q100 - F1*(Cp*(T2-T1)))/lambda;
T100 = 0.1538*P100 + 90.0;
Q100 = 0.16*(F1+F3)*(T100-T2);
F100 = Q100/lambdas;
Q200 = UA2*(T3-T200)/(1+(UA2/(2*Cp*F200)));
T201 = T200 + (Q200/F200*Cp);
F5 = Q200/lambda;
dXdt = [dL2dt;dX2dt;dP2dt];
end


global F1 F2 F3 F4 T3 T201 M lambdas  F100 C F5 T100 UA2 T200 F200 Q200 P100 ROA Q100 Cp T1 lambda X1 X2 P2 T2 
F1=10;ROA=20;M=20;C=4;Cp=0.07;
F2=2;
F3=50;Q200=307.9;UA2=6.84;
F4=8;lambda=38.5;lambdas=36.6;F5=8;T1=40;
X1=5;P100=194.7;T200=25;F200=208;T3=80.6;
P2=2;X2=2;
%fun = @trash;
% %x0 = [0,0,0];
% x = solve(fun,[0 0 0])
tRange = [1 500];
X=[0 0 0];  
[tSol,ySol] = ode45(@trash,tRange,X);
plot(tSol,ySol);