`function Untitled% Runge kutta 4th order method`

% dCa/dt = F(Ca,in - Ca)/V -2k(T)Ca^2-----eq.1

% dT/dt = F(Tin - T)/V +(-deltaH/rhoCp)*2*k(T)Ca^2-(T-Tf)UA/VrhoCp----eq.2

clc; clear;%constants

Flowrate = 20;V = 100;U_A = 20000;Cp = 4.2;rho = 1000;delta_H = 596619;Ar = 6.85E+11;E = 76534.704;R = 8.314;T_j = 250;%initial conditions

t_initial(1) = 0;T_initial(1) = 275;Ca_initial(1) = 1;%Arrhenius equation

n = 10 ; for j = 1:n k(j) = Ar*exp(-E/(R*T_initial(j))); if j<n T_initial(j+1) = T_initial(j) +5; endend%Define Function handle

fCa = @(t,Ca,T) Flowrate*(((Ca_initial - Ca)/(V)) -(2*k(j)*Ca*Ca));fT = @(t,Ca,T) Flowrate*(T_initial- T)/V +(-delta_H/(rho*Cp))*2*k(j)*Ca*Ca-(T-T_j)*(U_A/(V*rho*Cp));%step size

h = 10;t_f = 300; % final time

N = (t_f/h);% update loop

for i = 1:N t_initial(i+1) = t_initial(i) + h; K1Ca_initial = fCa (t_initial(i) ,Ca_initial(i) ,T_initial(i) ); K1T_initial = fT (t_initial(i) ,Ca_initial(i) ,T_initial(i) ); K2Ca_initial = fCa (t_initial(i)+ h/2 ,Ca_initial(i)+ h/2*K1Ca_initial ,T_initial(i)+ h/2*K1T_initial); K2T_initial = fT (t_initial(i)+ h/2 ,Ca_initial(i)+ h/2*K1Ca_initial ,T_initial(i)+ h/2*K1T_initial); K3Ca_initial = fCa (t_initial(i)+ h/2 ,Ca_initial(i)+ h/2*K2Ca_initial ,T_initial(i)+ h/2*K2T_initial); K3T_initial = fT (t_initial(i)+ h/2 ,Ca_initial(i)+ h/2*K2Ca_initial ,T_initial(i)+ h/2*K2T_initial); K4Ca_initial = fCa (t_initial(i)+ h ,Ca_initial(i)+ h *K3Ca_initial ,T_initial(i)+ h *K3T_initial); K4T_initial = fT (t_initial(i)+ h ,Ca_initial(i)+ h *K3Ca_initial ,T_initial(i)+ h *K3T_initial); Ca_initial(i+1) = Ca_initial(i) +h/6*(K1Ca_initial + 2*K2Ca_initial + 2*K3Ca_initial + K4Ca_initial); T_initial (i+1) = T_initial(i) +h/6*(K1T_initial + 2*K2T_initial + 2*K3T_initial + K4T_initial );endplot(t_initial,Ca_initial)hold onplot(t_initial,T_initial)xlabel('time')ylabel('Concentration')legend ('Conc.' , 'Temp.')set(gca,'fontsize',16)

———————————————————————

I'm getting error 'T_initial (i+1) = T_initial(i) +h/6*(K1T_initial + 2*K2T_initial + 2*K3T_initial + K4T_initial );' here. It's saying 'nable to perform assignment because the left and right sides have a different number of elements.' where am i going wrong ? Please help

Here k(T) is k is function of T i.e temperature and k is of the arrhenius equation.

## Best Answer