ODE45 and expr function

조회 수: 1 (최근 30일)
Imene Yed
Imene Yed 2021년 5월 30일
댓글: Imene Yed 2021년 5월 30일
Hi, I have this problem where I get only the last equation that is executed in the program (%N ) (the expr equations) and I want them to all run together and asign to them names like the comments C ,N,O,.
.............
tic,[t,n] = ode45(@(t,n)myequations(t,n,k1,k2,k3,k4,k5,k6....),[0 10e-3],IC)
toc
%Conservation de la masse:
%C:
expr_at_i(:)= n(:,1) + 2*n(:,9)+2*n(:,10)+3*n(:,13)+...
n(:,22)+n(:,26)+n(:,34)+2*n(:,35)+n(:,36)...
+n(:,37)+2*n(:,39)+4*n(:,40)+5*n(:,41)
%O:
expr_at_i(:)= n(:,4)+2*n(:,15)+2*n(:,16)+2*n(:,17)+n(:,22)...
+n(:,24)+ 3*n(:,29)+n(:,30)+2*n(:,32)+2*n(:,34)+...
n(:,36)+n(:,37)+3*n(:,38)+ n(:,39);
%N
expr_at_i(:)= n(:,7)+2*n(:,20)+n(:,24)+n(:;26)+2*n(:,30)+n(:,32)...
+n(:,35)+n(:,36)+n(:,37)+n(:,38)
function dndt=myequations(t,n,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10.....)
dndt=zeros(43,1);
%Chemin C
dndt(1)= k1*n(2)*n(42)+k15*n(5)*n(9)+k16*n(5)*n(26)+k25*n(4)*n(26)...
+k29*n(4)*n(9)+k33*n(4)*n(11)+k39*n(7)*n(26)+k40*n(7)*n(27)...
%Conservation de la masse:
%C:
expr_at_i(:)= n(:,1) + 2*n(:,9)+2*n(:,10)+3*n(:,13)+...
n(:,22)+n(:,26)+n(:,34)+2*n(:,35)+n(:,36)...
+n(:,37)+2*n(:,39)+4*n(:,40)+5*n(:,41)
%O:
expr_at_i(:)= n(:,4)+2*n(:,15)+2*n(:,16)+2*n(:,17)+n(:,22)...
+n(:,24)+ 3*n(:,29)+n(:,30)+2*n(:,32)+2*n(:,34)+...
n(:,36)+n(:,37)+3*n(:,38)+ n(:,39);
%N
expr_at_i(:)= n(:,7)+2*n(:,20)+n(:,24)+n(:;26)+2*n(:,30)+n(:,32)...
+n(:,35)+n(:,36)+n(:,37)+n(:,38)
  댓글 수: 2
Torsten
Torsten 2021년 5월 30일
You overwrite the first two expr_at_i by the third one because you use the same name for three different output variables.
Instead of expr_at_i, use mass_C, mass_O and mass_N in the three places.
Imene Yed
Imene Yed 2021년 5월 30일
@Torsten it is possible to write them in another script (the expr equation) and use the script of ode45 to import the t and n values. Thnk you so much you're helping a lot . With the methode that you mentioned earlier ?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by