Index exceeds the number of array elements (1).
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
madhan ravi
2018-11-11
编辑:madhan ravi
2018-11-11
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!