Index exceeds the number of array elements (1).

1 view (last 30 days)
Hi community Matlab, My programme is generating the following error,
if true
function dxdt = semibrx(t,x,k,Kc,V0,v0,Cb0)
% x(1)= Ca, x(2) = Cb, x(3) = Cc, x(4) = Cd;
rA = -k*(x(1)*x(2)-(1/Kc)*x(3)*x(4));
V = V0+v0*t;
dxdt = [
rA-(v0/V)*x(1);
rA + (v0/V)*(Cb0-x(2));
-rA-(v0/V)*x(3);
-rA-(v0/V)*x(4)
]
end
if true
clear all;
k = 9e-5; v0= 0.05 ; V0 = 200; Cb0 = 10.93; Ca0= 7.72;
Kc = 1.08;
x0 = [Ca0 0 0 0 ]; tspan = [0 1e2];
[t x] = ode45(@equilibrio,tspan,Kc,x0,[],k,v0,V0,Cb0);
Ca = x(:,1);
Cb = x(:,2);
Cc = x(:,3);
Cd = x(:,4) ;
V = V0 + v0*t; Xa = (Ca0*V0-Ca.*V)/(Ca0*V0); rA = -k*(x(1)*x(2)-(1/Kc)*(x(3)*x(4)));
%subplot(1,2),
plot(t,Ca,t,Cb,':',t,Cc,'.-',t,Cd,'--');
xlabel('t(s)'),ylabel('Concentration(mol/dm^3)'), legend ('C_A','C_B','C_C','C_D')
%subplot(1,2),
%plot(t,rA), xlabel('t(s)'),ylabel ('Reaction rate (mol/dm^3s)')
%plot(t,Xa),xlabel('t(s)'),ylabel('Conversão')
end
end
The program shows error: Index exceeds the number of array elements(1).
Would you help me please?
Thanks,
Guilherme Lopes de Campos
  5 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 11 Nov 2018
Edited: madhan ravi on 11 Nov 2018
clear all;
Ca0= 7.72;
x0 = [Ca0 0 0 0 ]; tspan = [0 1e2];
[t x] = ode45(@equilibrio,tspan,x0); %FUNCTION CALLING
Ca = x(:,1);
Cb = x(:,2);
Cc = x(:,3);
Cd = x(:,4) ;
figure
plot(t,Ca)
xlabel('t(s)')
ylabel('Concentration(mol/dm^3)')
legend ('C_A')
figure
plot(t,Cb,':')
xlabel('t(s)')
ylabel('Concentration(mol/dm^3)')
legend('C_B')
figure
plot(t,Cc,'.-')
xlabel('t(s)')
ylabel('Concentration(mol/dm^3)')
legend ('C_C')
figure
plot(t,Cd,'--')
xlabel('t(s)')
ylabel('Concentration(mol/dm^3)')
legend ('C_D')
function dxdt = equilibrio(t,x)
k = 9e-5; v0= 0.05 ; V0 = 200; Cb0 = 10.93;
Kc = 1.08;rA = -k*(x(1)*x(2)-(1/Kc)*x(3)*x(4));
V = V0+v0*t;
dxdt = [rA-(v0/V)*x(1);
rA + (v0/V)*(Cb0-x(2));
-rA-(v0/V)*x(3);
-rA-(v0/V)*x(4)]
end

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!