ode 45 question, error message
Afficher commentaires plus anciens
I'm having trouble with my ode, it says
"Index exceeds the number of array elements (4)."
global p00
tic
a1 = 500;
a2 = 100;
a3 = 10^16.35
CA0 = 0.005; %FeS2
CB0 = 0.250; %O2
CC0 = 0; %Fe2
CD0 = 0.01; %SO4
CE0 = 0.01; %Fe3
CAt = CA0 + CB0 + CC0 + CD0 + CE0;
CEt = CD0 + CC0 + CB0 + CE0
p00 = [a1;a2;a3];
y0(1) = CA0; % Concentration of initial A - [M]
y0(2) = CB0;
y0(3) = 0;
y0(4)= CD0;
yo(5) = CE0;
dt = 1;
t = (0:dt:60)';
tspan = [0 max(t)];
[T,y] = ode45('RK4odes',tspan,y0);
%
% Mass balance
%
y(:,4) = CAt-y(:,1)-y(:,2)-y(:,3)-y(:,5)
y(:,5) = CEt-y(:,2)-y(:,3)-y(:,5)
%
toc
% seperate fxn
function RK4odes1= RK4odes(~,y)
global p00
a1 = p00(1);
a2 = p00(2);
a3 = p00(3);
RK4odes1(1,1) = -a1*(y(1)^0)*y(5)*(y(4)^-1)*10^-7 - a2*y(2)*(y(1)^0)*(y(4)^-1)*10^-7; % CA
RK4odes1(2,1) = -a2*(y(1)^0)*(y(3)^0)*(y(4)^-1)*10^-7 - a3*(y(3)^0)*y(2)*10^-7 % CB O
RK4odes1(3,1) = a2*(y(1)^0)*y(2)*(y(4)^-1)*10^-7 -a3*y(2)*(y(3)^0)*(y(4)^-1); % CC Fe2
RK4odes1(4,1) = a1*(y(1)^0)*y(5)*(y(4)^-1)*10^-7 +a2*y(2)*(y(1)^0)*(y(4)^-1)*10^-7;
RK4odes1(5,1) = -a1*(y(1)^0)*y(5)*(y(4)^-1)*10^-7 +a3*y(2)*(y(3)^0)*(y(4)^-1)
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming 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!