Borrar filtros
Borrar filtros

Index exceeds the number of array elements (1).

3 visualizaciones (últimos 30 días)
Guilherme Lopes de Campos
Guilherme Lopes de Campos el 11 de Nov. de 2018
Comentada: madhan ravi el 11 de Nov. de 2018
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 comentarios
madhan ravi
madhan ravi el 11 de Nov. de 2018
See my answer below
Guilherme Lopes de Campos
Guilherme Lopes de Campos el 11 de Nov. de 2018
Thank you very much Community, for help!

Iniciar sesión para comentar.

Respuesta aceptada

madhan ravi
madhan ravi el 11 de Nov. de 2018
Editada: madhan ravi el 11 de Nov. de 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
  2 comentarios
Guilherme Lopes de Campos
Guilherme Lopes de Campos el 11 de Nov. de 2018
Thank you very much Madhan!
madhan ravi
madhan ravi el 11 de Nov. de 2018
Anytime :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by