Using for loop with ODE solver
이전 댓글 표시
Hello MATLAB central!
I have written a function that reads Arrhenius equation and uses different parameters in different temperature ranges, like so:
function dxdT_MSK =MSK_pyrolysis(T_MSK,x_MSK)
for k = 1:421
if T_MSK(k,1) < 500
dxdT_MSK(k,1) = A_MSK(1).*exp(-E_MSK(1)./(R.*T_MSK(k,1))).*(1-x_MSK(k,1))^n_MSK(1);
elseif (T_MSK(k,1) >= 500) && (T_MSK(k,1) <620)
dxdT_MSK(k,1) = A_MSK(2).*exp(-E_MSK(2)./(R.*T_MSK(k,1))).*(1-x_MSK(k,1))^n_MSK(2);
elseif (T_MSK(k,1) >= 620) && (T_MSK(k,1) <690)
dxdT_MSK(k,1)=A_MSK(3).*exp(-E_MSK(3)./(R.*T_MSK(k,1))).*(1-x_MSK(k,1))^n_MSK(3);
elseif T_MSK(k,1) >=690
dxdT_MSK(k,1)=0;
end
end
end
I would like to solve it with an ODE solver. I have attempted to do it by using this command:
T_span_MSK = linspace(460,860)';
E_MSK = []; %matrix of acitvation energies for pure MSK (primary, secondary, and teriary degradations respectively)
n_MSK = []; %matrix of reaction orders for pure MSK
A_MSK =[]; %matrix of preexponential factors for pure MSK
E_MSK(1) = 8.309;
n_MSK(1) =3;
A_MSK(1) = 9.76*10^(-2);
E_MSK(2) = 37.832;
n_MSK(2) = 0.9;
A_MSK(2) = 3.64*10^2;
E_MSK(3)=14.99;
n_MSK(3) = 1;
A_MSK(3) = 1.61;
[T_MSK,x_MSK] = ode45(@MSK_pyrolysis, T_span_MSK,0);
When I attempt to do so, I get this error message:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in MSK_pyrolysis (line 6)
if T_MSK(k,1) < 500
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled2 (line 13)
[T_MSK,x_MSK] = ode45(@MSK_pyrolysis, T_span_MSK,0);
I would really appreciate some pointers as to what I could improve or change in my code. I know it would be possible to just do it seperately for each temperature range and then use "brute force" to combine them together, but obviously there must be some more sleek way of doing it.
KInd regards.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!