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

1 view (last 30 days)
Please help me, this a project in my class but I don't know how to solve the problem
clc
clear
%% Preallocating arrays
r1=zeros(1,30001);
r2=zeros(1,30001);
Tr=zeros(1,30001);
%% Parámetros.
dh1 = -41.8;
dh2 = -83.6;
r = 8.3143;
Cpr = 1;
A = 170;
Dr = 1000;
d= 0.02;
tj=350.5;
Cain=10;
Trin=350;
K01= 4;
K02= 172.2;
E1=20.9;
E2=41.8;
Vr = 10;
%% Cálculo de los valores constantes.
M1= -dh1/(Cpr*Dr);
M2= -dh2/(Cpr*Dr);
M3= d*Cain;
%% Condiciones iniciales
Tr(1)=350;
CA(1)=10;
CB(1)=4.3;
CC(1)=0.4;
r1(1)=1;
r2(1)=1;
%% Método de integración numérica.
tsim=300; % tiempo de simulación.
h =0.1; % paso de integración.% Fórmula de Euler.
for n=1:tsim/h
r1(n+1)=r1(n)+h*(K01*(CA^2)*exp(-(E1./(r*Tr))));
r2(n+1)=r2(n)+h*((K02*CB)*exp(-(E2./(r*Tr))));
end
%% Graficas
tiempo=0:tsim;
figure(1)
plot(tiempo,r1,'LineWidth',2.0)
grid on, grid minor
xlabel('Tiempo,[s]')
ylabel('Velocidad de reaccion,[s]')
figure(2)
plot(tiempo,r2,'LineWidth',2.0)
grid on, grid minor
xlabel('Tiempo,[s]')
ylabel('Velocidad de reacción,[s]')

Answers (1)

David K.
David K. on 18 Sep 2019
The first problem is that Tr is a vector being assigned to a single value of r1, this is fixed as such:
r1(n+1)=r1(n)+h*(K01*(CA^2)*exp(-(E1./(r*Tr(n)))));
r2(n+1)=r2(n)+h*((K02*CB)*exp(-(E2./(r*Tr(n)))));
Then another problem shows itself because in plotting tiempo and r1 are not the same, this is fixed by changing tiempo like this:
tiempo=0:h:tsim;
however h should also probably be changed to 0.01 instead of 0.1.

Tags

Community Treasure Hunt

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

Start Hunting!