How to use multiple function's solutions as variables in other functions
조회 수: 3 (최근 30일)
이전 댓글 표시
I am using 8 different functions, all needing eachother in order to work. If I put this in the functions,
tRange = (0:144);
Xf0 = [0.2;0];
[~,XfSol] = ode45(@lipidfreecellgrowthw,tRange, Xf0 );
C0 = [0;0];
[~,CSol] = ode45(@byproductaccumulationsw, tRange, C0);
LE0 = [0;0];
[~,LESol] = ode45(@nonEPAlipidaccumulationsw, tRange, LE0);
E0 = [0;0];
[~, ESol] = ode45 (@EPAaccumulationw, tRange, E0);
S0 = [100;0];
[~,SSol] = ode45(@glucoseconsumptionw,tRange, S0 );
N0 = [5;0];
[~,NSol] = ode45(@nitrogenconsumptionsw,tRange, N0 );
Ncell0 = [1;0];
[~,NcellSol] = ode45(@intcellsstorednitrogenw,tRange, Ncell0 ) ;
V0 =[1;0];
[~,VSol] = ode45(@volumechangew, tRange, V0);
for Xf = 1:numel(XfSol); C = 1:numel(CSol) ; LEf = 1:numel(LESol); E = 1:numel(ESol); S = 1:numel(SSol); N = 1:numel(NSol); Ncell = 1:numel(NcellSol); V = 1:numel(VSol);
they do not work because it has to go through so many iterations. I need XfSol, CSol, LESol, ESol, SSol, NcellSol, and VSol to be callable in the functions themselves so they can be used for variables.
If I put this separately from the function,
tRange = (0:144);
Xf0 = [0.2;0];
[~,XfSol] = ode45(@lipidfreecellgrowthw,tRange, Xf0 );
C0 = [0;0];
[~,CSol] = ode45(@byproductaccumulationsw, tRange, C0);
LE0 = [0;0];
[~,LESol] = ode45(@nonEPAlipidaccumulationsw, tRange, LE0);
E0 = [0;0];
[~, ESol] = ode45 (@EPAaccumulationw, tRange, E0);
S0 = [100;0];
[~,SSol] = ode45(@glucoseconsumptionw,tRange, S0 );
N0 = [5;0];
[~,NSol] = ode45(@nitrogenconsumptionsw,tRange, N0 );
Ncell0 = [1;0];
[~,NcellSol] = ode45(@intcellsstorednitrogenw,tRange, Ncell0 ) ;
V0 =[1;0];
[~,VSol] = ode45(@volumechangew, tRange, V0);
it does not work because it is not in te function. What can I do to be able to call these in the functions themselves?
답변 (1개)
Steven Lord
2021년 7월 28일
If you need to evaluate the solutions of those ODEs at different times than ode45 returned (which is how I'm interpreting "so they can be used for variables") call ode45 with one output and use deval to evaluate that solution at a different time.
format longg
[t,y]=ode45(@vdp1,[0 20],[2 0]);
plot(t, y(:, 1), 'k-+'); % Only plot the first component
hold on
sol = ode45(@vdp1, [0 20], [2 0])
tt = 0:4:20;
yy = deval(sol, tt, 1); % Only interested in the first component for plotting purposes
plot(tt, yy, 'ro')
In some cases the red circles are more or less on a plus symbol, but in other cases they represent the value of the solution of the ODE at a time not in the original t vector (the circles at t = 12 and t = 16 look to be in such a gap.)
댓글 수: 2
Steven Lord
2021년 7월 29일
So it sounds like you don't have a hundred independent ODEs but you have a system of a hundred interdependent ODEs. In that case you can't solve them each on their own. See the "Nonstiff Euler Equations" example on this documentation page for an example involving a system of three interdependent ODEs. The ODE function will be (much) longer with a hundred ODEs but the principle is the same.
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!