What to do if I want make parameters a vector in a ODE23?
6 ビュー (過去 30 日間)
古いコメントを表示
Im trying to model prey/predator population dynamics with a range of parameters.
I have 3 scripts
(1) script with my parameters named 'preypredator_Parameters'
p.r = 0.1 ;
p.a = 0.01 ;
p.c = 0.9 ;
p.m = 0.03 ;
p.tSpan = [0 1000];
(2) script with my function named 'preypredator_ODE'
function dNdt = preypredator_ODE(t, N)
preypredator_Parameters ;
prey = N(1) ;
pred = N(2) ;
dNdt = [p.r * prey - p.a * prey * pred ; ...
p.c * p.a * prey * pred - p.m * pred] ;
(3) driver to run my ODE named 'preypredator_ODEdriver'
preypredator_Parameters ;
N0 = [10 10] ;
[t, N] = ode23s(@preypredator_ODE, p.tSpan, N0);
plot(t, N)
I would like to run the ODE with two of my parameters lets say p.m being a vector with a range of values (p.m = [0.03 0.05 0.07 0.09]) and p.r being a vector (p.r = [0.01 0.02 0.03 0.04]). As a final result I would like to produce 4 population dynamics graphs each using a different value of p.m and p.r while my other parameters stay constant, for example my first graph would use p.r(1) = 0.1, p.a = 0.01, p.c = 0.9, p.m(1) = 0.03, p.tSpan = [0 1000]; my second graph would use p.r(2) = 0.2, p.a = 0.01, p.c = 0.9, p.m(2) = 0.05, p.tSpan = [0 1000].
I know that if I was to just change the parameters to vectors there would be a 'Error using vertcat Dimensions of arrays being concatenated are not consistent.'. Im also not sure how to even produce the 4 graphs afterwards either.
In reality I have a lot more p.m and p.r values, so writing each value as a seperate parameter and creating a new ODEs each with a different set of parameters isnt too ideal.
Ive looked at several other discussions that appear to ask and answer a similar question to mine, however with my lack of experience with matlab, I cant seem to implement their sollutions to my situation.
Thanks in advance for any sort of help.
0 件のコメント
回答 (1 件)
Steven Lord
2019 年 11 月 20 日
There's an example on the ode23s documentation page (open this by typing doc ode23s in the MATLAB Command Window) for how to pass additional parameters into your ODE function. Write your ODE function in that style, so it accepts the parameters over which you want to sweep as additional inputs, then just call ode23 in a loop (or a pair of loops) passing in the appropriate elements of your vectors of additional parameters.
参考
カテゴリ
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!