Finite Difference Scheme Error

조회 수: 1 (최근 30일)
DIP
DIP 2017년 4월 7일
댓글: DIP 2017년 4월 20일
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

채택된 답변

Torsten
Torsten 2017년 4월 10일
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.
  댓글 수: 1
DIP
DIP 2017년 4월 20일
Thanks Torsten , got it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Chemistry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by