Finite Difference Scheme Error

5 views (last 30 days)
DIP
DIP on 7 Apr 2017
Commented: DIP on 20 Apr 2017
Hi, I am trying to plot this equation , i am unable to understand how to debug the matrix error on the equation.
% Solution 1: Chemical Species Concentration as a Function of Axial Distance
clc
clear
% Constants
L = 0.2;
N = 31;
T(1:N) = 700;
delx = L/(N-1);
xspan = 0:delx:0.2;
u = 1.5;
A = 7e4;
Ea = 100000;
Ru = 8.3145;
T = 700;
k = 0.035;
rho = 0.95;
NM=3;
C(1) = 0.21;
C(2) = 0.68;
C(3) = 0.06;
R(1) = -A * (exp(-Ea / (Ru*T))) * C(1)/rho * sqrt(C(2)/rho);
R(2) = 0.5 * R(1);
R(3) = -R(1);
D(1) = 0.166;
D(2) = 0.201;
D(3) = 0.177;
for i=2:N-1
for j=2:NM
C(i,j)=((R(j)*delx.^2)*(rho*D(j)).^(-1))+ C(i+1,j)+C(i-1,j) ;
end
end
% Plots
subplot(2,1,1);
plot(x,C(:,1),'b--o',x,C(:,2),'g--+',x,C(:,3),'r--s')
legend('C_{CO}','C_{O2}','C_{CO2}')
xlabel('Axial (x) Direction [m]')
ylabel('Concentrations [mol/m^3]')
title('Molar Concentration vs Distance')
subplot(2,1,2);
plot(x,T,'b--*')
legend('Gas Temperature')
xlabel('Axial (x) Direction [m]')
ylabel('Gas Temperature [K]')
title('Temperature vs Distance')
Any help is appreciated.
Thank You

Accepted Answer

Torsten
Torsten on 10 Apr 2017
In the calculation of C(i,j), you can't refer to C(i+1,j) because it's not yet defined.
Best wishes
Torsten.

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!