필터 지우기
필터 지우기

Solving System of ODEs using for cycles to reproduce summing

조회 수: 3 (최근 30일)
rantunes
rantunes 2015년 2월 11일
댓글: rantunes 2015년 2월 15일
Dear all,
Thank you first all for your attention reading this post.
I am a kind of new in Matlab so it might be that the answer to my question is really easy but I don't see the solution for the moment.
I want to solve a system of coupled differential equations that in mathematical form are presented below.
I am creating a function for this system that looks like
function dXdz = coupled_ODE(z,X,y,n,alpha,beta,J,Pf,uf)
m = length(X); % Defines the number of elements of the independent variable
dXdz = zeros(m,1); % Initializes the column vector of the elements to the left of the ODE
for i = 1:n
dXdz(1) = dXdz(1) - alpha*J(i)*(Pf*X(i+1) - X(m)*y(i));
end
for i = 1:n
dXdz(i+1) = (-1/X(1))*(X(i+1)*dXdz(1) + alpha*J(i)*(Pf*X(i+1) - X(m)*y(i)));
end
dXdz(m) = beta*(uf - X(1))/X(m);
where the parameters from y to uf are given as inputs, since after each iteration in the main code those are updated. Notice also that alpha and beta are constants.
This function is called in the main body as
[Z, Xout] = ode45(@coupled_ODE,zspan,Xin,[],yi,num_species,alpha,beta,J,Pf,uf);
I am getting problems in the results I obtain. They are not at all what I expect. The output of this ode45 is always the same at each iteration, indicating that no numerical integration of the ODEs is being performed at all.
I don't see where the problem can be. I might suspect that is coming from this for cycles I introduced to reproduce the summings, but I am not sure. Any idea?
Hopefully, you can see the error (and I would be not surprised if it is an amateur mistake).
Thank you all! Greetings
  댓글 수: 1
rantunes
rantunes 2015년 2월 11일
편집: rantunes 2015년 2월 11일
I just want to add that the input vector X is a sex-elements column vector, with the elements
X = [u xi p]';
where xi is a vector of 4 elements. This explains why I used "X(i+1)", for instance.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2015년 2월 11일
Change the call to ODE45 to
[Z,Xout]=ode45(@(z,X)coupled_ODE(z,X,yi,num_species,alpha,beta,J,Pf,uf),zspan,Xin);
Best wishes
Torsten.
  댓글 수: 15
Torsten
Torsten 2015년 2월 11일
Don't think in iterations, think in states.
If the parameters yi,.... can be calculated from the states of u, xi and p (which are given variables in coupled_ODE), you can calculate dXdz.
Best wishes
Torsten.
rantunes
rantunes 2015년 2월 15일
Finally I figured out what was the problem. It was a value that I was considering wrong in terms of units that were providing very low dXdz and thus no "visible" integration.
The implementation above was always correct.
Thanks. Rodrigo

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by