How to solve an ODE with an array using ODE45?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have an ODE, udY/dx=S , where Y and S are arrays , how do I solve it using ODE45 ???
댓글 수: 3
Jan
2017년 2월 20일
@DIP: Please provide more details. "velocity" does not help, because Matlab does not care about the physical meaning of variables. Post the function you want to integrate, preferrably in valid Matlab code. If it is written correctly, all you have to do is calling ode45.
채택된 답변
추가 답변 (2개)
Jan
2017년 2월 20일
편집: Jan
2017년 2월 21일
ode45 works with vectors, therefor if Y is a vector, the provided examples in the docs should help: https://www.mathworks.com/help/matlab/ref/ode45.html#examples . If not, please post more details by editing the question.
[EDITED, Considering your comments] Perhaps you mean this:
function main
% Initial Conditions
Cco(1) = 0.52; %Y1
Co2(1) = 0.99; %Y2
Ch2o(1) = 0; %Y3
L = 0.12;
N = 39;
delx = L/(N-1);
x = 0:delx:0.12;
C0 = [Cco; Co2; Ch2o];
[x,C] = ode45(@DiffEQ, x, C0);
plot (x,C)
end
function dC = DiffEQ(x, C)
u = 1.5;
A = 2.2e10;
Ea = 130;
Ru = 8.3145;
T = 750;
Cco = C(1);
Co2 = C(2);
Ch2o = C(3);
Rco = -A * (exp(-Ea / (Ru*T))) * Cco * sqrt(Co2); %S1
Ro2 = 0.5 * Rco; %S2
Rh2o = -Rco; %S3
dC = [Rco; Ro2; Rh2o] / u;
end
This needs a lot of processing time. Using ode15s was successful in less than a second (are you sure the system is not stiff). The diagram looks nicer, if you define:
x = [0, 0.12];
댓글 수: 10
Jan
2017년 2월 21일
@DIP: @(x,C) R/u is constant. Changes in the coordinates are not considered, because all calls of "R/u" reply the same value. Better use a normal function instead of a anonymous function. I've showed you already, how to do this.
Concerning:
documentation for the last line of your main function
do you mean "plot(x,C)"?
Star Strider
2017년 2월 20일
You will have to adapt it to your data and differential equations. The essential design should work.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!