Index exceeds the number of array elements (1).
조회 수: 1 (최근 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
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!