Attempted to access C2(3); index out of bounds because numel(C2)=2.
Afficher commentaires plus anciens
Dear Sir
I am trying to solve this code for the last few days but getting different kinds of errors. Now when I run this code I got error message 'Attempted to access C2(3); index out of bounds because numel(C2)=2.'. Please help me for solving this problem.
global Vl asl Vm Da K h Ksl n V v
clc
clear all
n = 100;
Lt = 4; % Length(cm)
rt = 1; % radius(cm)
Vl = 3.14*rt^2*Lt; % Volume(cm3)
asl = 880; % Specific surface area(cm2/g)
Vm = 1;
D = 7.2*10^-5;
por = 0.3;
Da =D*por^0.5;
V=5;
v=20;
Ea = 61000; % Activation Energy(J/mol)
R = 8.314; % Universal gas constant( J/mol/K)
T = 303.15;
K = 0.19*exp(-Ea/(R*T)); %%rate constant
h = Lt/(n-1); %%grid spacing or distance
Ksl = 10^-5; %%coeff.(cm/s)
C2=[0;0.3*ones(n,1);0.3];
C1=[0;10^-4*ones(n,1);10^-4];
C=[C1;C2];
[t,C1]=ode45(@tube_fun_ode_f,[0 10^5],[10^-4,0.3]);
function dC = tube_fun_ode_f(t,C)
global h K Da Ksl Vl asl Vm n v
C1=[0;10^-4*ones(n,1);10^-4];
C2=[0;0.3*ones(n,1);0.3];
C=[C1;C2];
for i=1
dC(1)=[10^-5; Vm*(Ksl*K*asl/(Ksl*asl-Vl*K))*C1(i)];
end
for i=2:length(C)-1
dC(i)=[(C2(i+1)*Da/h^2-C2(i)*v(i)/2*h)*C1(i+1)-(C2(i+1)*Da/h^2+C2(i)*Da/h^2)*C1(i)+(C2(i)*Da/h^2+C2(i)*v(i)/2*h)*C1(i-1)+C2(i)*K*C1(i); Vm*(Ksl*K*asl/(Ksl*asl-Vl*K))*C1(i)];
end
for i=length(C)
dC(end)=[dC(end-1); Vm*(Ksl*K*asl/(Ksl*asl-Vl*K))*C1(i)];
end
here is my original problem which I want to solve after discretization.
dC1/dt=d/dx(De*C2*(dC1/dx))-V*(dC1/dx)+(Ksl*asl/(Ksl*asl-Vl*K))*C1*C2
dC2/dt=Vm*( Ksl*asl/(Ksl*asl-Vl*K))*C1
t=0 C1=0 all x
t>0 C1=0 at x=0
T>0 dC1/dx=0 at x=L
at t=0 C2=0
--
Shashikant
Réponses (1)
David Sanchez
le 18 Juin 2013
I think you problem ( at least one of them ) lies on:
dC(1)=[10^-5; Vm*(Ksl*K*asl/(Ksl*asl-Vl*K))*C1(i)];
inside your tube_fun_ode_f function. Why do you use a for_loop if you only have one value ( for i=1 ). You are assigning a 2D array to dC(1). What's the point of your semicolon ( ; )?
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!