How to describe loop for my ODE equations?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I am trying to solve a set of ODE equations with MATLAB ode solver but I do ot know how to define the Loop for my equations. If any one could help me I would be thankful.
These are the ODE equations:
O, I, and S are the molar consentration of components
(N= 100) and (j = 1:100)

채택된 답변
Bjorn Gustavsson
2023년 2월 8일
편집: Bjorn Gustavsson
2023년 2월 8일
Write a function for these coupled ODEs. Inside that function you can use all the normal programmig tools and tricks you can think of. Something like this should work:
function dOISdt = your_chemistry_ode(t,OIS,kP,kD)
O = OIS(1:end-2);
I = OIS(end-1);
S = OIS(end);
dSdt = kD*I;
dIdt = kP*sum(O(1:end-1)) - kD*I;
dOdt = zeros(size(O(:)))
dOdt(1) = -kP*O(1); % Not exactly clear how you want to treat the first spieces in O
for i1 = 2:numel(O)
dOdt(i1) = kP*(O(i1-1)-kP*O(i1));
end
dOISdt = [dOdt;dIdt;dSdt];
end
Then it should be rather straightforward to integrate this with any of the odeNN-functions:
%% Initial conditions
% I just mock something up, completely without ideas about what chain of
% 100 species decaying towards I and S you model
O0 = [100;rand(99,1)];
I0 = pi;
S0 = 0;
OIS0 = [O0;I0;S0];
kP = 1e6; % reaction-rate, no idea about time-constants either
kD = 1e4;
t_span = linspace(0,1,1e6+1); % same again, steps of ms for 1 s...
[tOut,OISout] = ode45(@(t,IOS) your_chemistry_ode(t,OIS,kP,kD),t_span,OIS0);
HTH
댓글 수: 9
Thank you veru much for your great help. :)
It seems that it works properly.
Good that it helps!
If the answer solves your problem, then accept it so that other contributors wont waste time looking to answer it.
Thank you again.
I did it.
Sorry for bothering you again.
One question: would you please explain this "O0 = [100;rand(99,1)];" to me?
I want to define initial condition values for O species from j=1 to j=100 in a vector like this O0 = [0.5 0.5 0.5 ... 0.5].
How can I define that vector without writnig 0.5 for 100 times?
Ok, my
O0 = [100;rand(99,1)];
was just to make a [100 x 1] array with 100 in the first element and 99 random numbers between 0 and one for the last 99 elements (because I ought to cook up some initial conditions for the example).
If you want 0.5 in all 100 elements you can do something like this:
O0 = 0.5*ones(100,1);
From this question it appears as if you are new to matlab-programming, and as far as I understand the on-ramp material is designed to get people up to speed as effectively as possible, you might consider browsing through that material as you see fit. It helped me increadibly when I realized that matlab has a vast range of handy functions for many tasts from the most trivial to the most specialized, this cuts down programming-time significantly.
Hi again,
yes, I am a beginer somehow.
I tried O0 = 0.5*ones(100,1); but I have a problem. It does not take initial conditions for I and S species. Of course I made some changes in code in terms of chemical point of view.
I want the initial conditions to be 0.38 for all of P species and I0 = 0.19 and S0 = 0.17
function dPISdt = Poly_ode(t,PIS,kpeel,kD,DP)
P = PIS(1:198);
I = PIS(199);
S = PIS(200);
dPdt = zeros(size(P(:)));
dPdt(1) = -kpeel*P(1); % the first spieces at i1=1 (P(0)=does not exist)
for i1 = 2:DP-2
dPdt(i1) = kpeel*P(i1-1)-kpeel*P(i1);
end
dIdt = kpeel*sum(P(1:end-1)) - kD*I;
dSdt = kD*I;
dPISdt = [dPdt;dIdt;dSdt];
end
%%%% and here is the ode solver:
DP = 200;
PIS0 = [0.38*ones(1,198) 0.19 0.17];
% reaction-rates [1/min]
kpeel = 0.001;
kD = 0.001;
% time [min]
t_exp = [
48
63
78
93
108
123
138
153
168
181.00
240
300.00
];
[t,PIS] = ode45(@(t,PIS) Poly_ode(t,PIS,kpeel,kD,DP),t_exp,PIS0);
plot (t_exp,PIS(:,1),t_exp,PIS(:,2),t_exp,PIS(:,3));
legend('Polysac','ISA','SHA');
xlabel('time (min)');
ylabel('Concentration [mol/L]');
@Bjorn Gustavsson thank you very much for your tip. I will definitely use this on-ramp materials to improve my programming skils.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
