Top Banner
東東東 東東 東東東 D2
39

Chap. 6(nakagawa)

Jun 28, 2015

Download

Documents

Kazuya Nishina

モデル勉強会 6章
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chap. 6(nakagawa)

東工大D2 中川 麻悠子

Page 2: Chap. 6(nakagawa)

様々な時間の関数や境界条件を含んだ複雑な微分方程式を Numerical methodで解くNumerical Methods; 時間や空間に関して不連続なステップを連続モデル式に近づけるための近似をする。長所:どんな複雑な問題にも適応できる問題点:新たな誤差を( numerical errors)を生み出す

Page 3: Chap. 6(nakagawa)

多くの Numerical Methodの背景となる重要な数学式。

Fig. 6.2 x+hにおける異なる次数のテイラー展開。A)0次近似、 B)1次近似、 C)2次近似、 D)3次近似。

Page 4: Chap. 6(nakagawa)

Numerical modelテイラー展開のある点で切り捨てを行って進行。この切り捨てにより起こる誤差→ Numerical Errorあるmethodが n 次精度( n 次で切り捨て)→最も大きな各ステップでの切り捨て誤差は hn+1

*何故 Numerical Errorを気にするのか?①エラーは無い方がいい。出来る限り精度の良い結果を得るため。②解の安定性。誤差が打ち消し合う場合と増幅する場合がある。

0 2 4 6 8 10

050

100

150

time

y

true solutionapproximation

A

0 5 10 15 20

0.0

0.5

1.0

1.5

2.0

2.5

3.0

time

y

true solutionapproximation

B

Fig. 6.3 Numerical Errorの例。 A)始めは小さいが徐々に真値から外れてくる。B)近似値が振動する。振動により現実的にはありえない負の値を示すこともある (●)

Page 5: Chap. 6(nakagawa)

力学的な微分式の微分段階はタイムステップ t (一定でなくてもいい)を用いて

Fig. 6.4   Numerical integration methodの構成

テイラー式を用いた最も単純な update formula。

O(t): 切り捨てによる誤差 (i.e. for t =0.01, t2 = 1e−4, t3=1e−6; whereas for t=1, t2 = tn =1)。一次精度

Page 6: Chap. 6(nakagawa)

Euler Integrationの例:単純な algal growth model

二次以降のテイラー級数を切り捨てるため、事実上 t の間速度が一定だと仮定→もしそういう場合でなければ精度はあまり良くない( Fig. 6.5A)。 対策としては t を小さくすることである。モデルの性質が本当に悪いと、何も変化しない位 t を小さくする必要があるかも

Page 7: Chap. 6(nakagawa)

積分法の良し悪しのポイント;精度、安定性、速さ、メモリ必要量①精度離散化誤差(各タイムステップで発生):テイラー展開の結果と比較することで見積もれる。高次のmethodはタイムステップが進むほど高精度になる。

②安定性連続的な solution points間における振動増加をもたらす可能性の大きさ。なるべく精度良く安定である方がいい。

③スピード1)タイムステップの数と t の取り方、 2)t~ t+t での関数計算の数④メモリ必要量繰り返し積分が複雑になればなるほどメモリは多く必要になる。

←毎回のタイムステップで記憶しなければいけない情報量の多さhard-to-integrate type of problemsは’ stiff’ sets of equationsと言われる。

←異なる固有のタイムスケールを持ってモデル化されたプロセスに起きる。例; dynamics of bacterial population dynamics (time scale:

hours~days) + a forcing with a seasonal or year-to-year variation (time scale: months~years)←ほとんどのコンピュータは速いプロセスに合わせてで計算する

Page 8: Chap. 6(nakagawa)

数値解析において常微分方程式の近似解を求める一連の方法。最も良く用いられる 4次の Runge-Kutta methodは各タイムステップ t で 4つの評価を行う。

次の値( Ci+1)は、現在の値( Ci)に間隔( t )と推定された勾配の積を加えたものである。その勾配は次の 4つの勾配の重み付け平均で求める。

4次精度の方法、すなわち全体の切り捨て誤差が t5のオーダーになる←t 一定

Page 9: Chap. 6(nakagawa)
Page 10: Chap. 6(nakagawa)

この方法は 2つの partで構成されている:―実際に積分を行う the stepper routine

―用いられたステップの良し悪しを判断する a quality routine 5th Order Runge-Kutta method; 4次 Runge-Kutta法が持つ構造安定性と flexible time stepの正確さを組み合わせている。 t に推定される誤差 0を適用する。基準エラー 1を二つの Runge-Kutta近似間の差から見積もる。 1つは a large step t1でもう一方は二つの連続的な半分のタイムステップからなる。 4次 Runge-Kutta法のように誤差を t5のオーダーとしてステップサイズを評価する。

Page 11: Chap. 6(nakagawa)

t+t の値を…t における値を元に算出する  (explicit method t+t における値  (implicit method) t と t+t における値を両方とも部分的に含んでいる 

(Semi-implicit method, the Crank-Nicholson scheme)を元に算出。

これまで述べた方法( explicit method)より精度が低いが、とても安定性がある

は通常 0.5

Page 12: Chap. 6(nakagawa)

Method 精度 安定性 メモリ

Explicit 一次 ― ―

Implicit 一次 良い +

Semi-implicit

二次 良い +

より大きなタイムステップを用いることができる (n*n)行列の反転を行う分メモリをくう

Page 13: Chap. 6(nakagawa)

R modelでは信頼性と効率性を達成するようなステップサイズを自動的に選ぶ繰り返し積分法 (ode)が利用できる( pakage deSolve )。より単純な繰り返し積分はスピードに関していくつか問題がある。もし高精度で安定な Euler or 4th order Runge-Kutta methodで用いた t が出力区間と同じかより大きいとしたら、そのmethodはおそらく良い選択である。

← fixed time step methodによって得られた結果が十分に高精度か確かめる前に t が十分に小さいかチェックしなくてはいけない。

<チェック項目>あるタイムステップでまずモデルを走らせるタイムステップを二倍にして二つの run間での違いを検査する。もし違いが顕著なら、有意に変化しなくなるまでタイムステップを半分にする。もし違いが有意でないなら、有意に変化するまでタイムステップを二倍にする。大事を取るため、十分な精度のタイムステップの半分を用いる。

Page 14: Chap. 6(nakagawa)

空間的一次元導関数の数値近似は有限の節目や layerの関数値を計算。これらの微分には空間での位置の経過を慎重に追わなくてはいけない。特に、濃度、表層、フラックスや距離がボックスの中心の値なのか境界の値なのか。

Fig. 6.6 A)空間的導関数は空間定義域を grid cells や boxesの数で再分配することで近似する。位置 (xi) はボックスの中心。B)相対的距離はボックスの中心間の距離(xi,i+1) かボックスの長さ (xi,xi+1,)C)濃度や密度などは grid cellの中心の値D)フラックスはボックスの境界で定義される。

Page 15: Chap. 6(nakagawa)

First step; flux-gradient formで一般的な反応輸送方程式を立てる。 (gは一次成長速度 )

各ボックス iに関して

Ciはボックス iにおける濃度、 xiはボックス iの厚さ、 Aiはボックス iの中心部表面積、 iはボックス i 周りのフラックス勾配を表す。ボックス iにおけるフラックス勾配は次のボックス (i, i+1)と前のボックス (i-1, i)の境界間の違いで定義される:

Page 16: Chap. 6(nakagawa)

連続的な分散フラックスの方程式;

この式では濃度勾配と反対向きにフラックスが定義される。フラックスも濃度勾配もボックスの境界で定義されるので、

と表せる。 Dxi-1,iはボックス中央間距離で’ dispersion distance’である。 Di-1,iは境界における分散係数である。

Page 17: Chap. 6(nakagawa)

移流フラックスは単純に濃度と速度を掛け合わせて表される。

境界における移流フラックスは次式のように表される(’ centred difference’ approximation)

ボックス iと i-1の濃度を反映 → Ci-1が 0でも移流フラックスが発生する。そして次のステップで濃度が負になる。これは現実的ではなく、避けるべき。この現象では値が振動し、解が不安定になる。

ボックス i-1の濃度のみの関数にすることがより安全である( backward approximation)。

Page 18: Chap. 6(nakagawa)

1. フラックスとしての境界条件上部境界フラックスを F として、ボックス 1における濃度変化の近似式

2. 濃度としての境界条件境界濃度をフラックスに変更して flux divergence equationを記述する。

3. 濃度の関数となっているフラックスで境界条件を規定 (Robin or evaporation boundary condition)

Page 19: Chap. 6(nakagawa)

The backward differencing scheme濃度が負にならず、安定。だが一次精度。→ Taylor展開の二次以上の項を無視することで発生する切り捨て誤差( numerical dispersion or numerical dissipation)

実際の現象がシャープな勾配だとしても、なだらかな勾配になることがある。

例)非移動性で一定速度の個体数増加

Fig. 6.7 実際の局所的な分布が、 advection を含んだ growth modelを行うと実線のようになだらかな分布を示す。

Page 20: Chap. 6(nakagawa)

①ほとんどの場合、移流と拡散項が混合しており、数値的分散 (numerical dispersion)はその他の分散に対してごく小さいと考えられる。このような場合、 the backward numerical schemeは十分な精度であると考えるかもしれない。

②より複雑な numerical schemeを用いる  数値的分散は Taylor seriesを高次項まで用いることで抑えられるが、それらの手法は複雑であるため未だにいくつかの問題がある。参考としてGurney and Nisbet (1998)の本が挙げられる。

③大きなボックスに対して特に起こるため、ボックス数を増やす。  しかし、ボックス数を増やせばコンピュータへの負担が大きくなるので限度はある。

④濃度が負になる危険性を無視して centre differencesを用いる。  これはある条件下では最善の解決策。空間軸に対して濃度が増加しない限り、負の濃度が算出されることがない。さらに数値的分散はかなり抑えられる。

例)堆積有機物濃度…堆積物の深度が深くなるほど減少する。→ explicit wayの堆積有機物モデルは移流を centre differenceを用いて記

述する。

Page 21: Chap. 6(nakagawa)

異なる schemeにおける数値的分散の効果を見る。3 種類の scheme①backward differences(=1)②centred differences(=0.5)③a flexible scheme( the Fiadeiro scheme) (=Peclet numberの関数 )同じ大きさのボックスに対して、3つの schemeとも簡単のために一つの方程式でモデル化する。

Pe(Peclet number);分散過程における移流の相対的重要性を表す無次元数。

Page 22: Chap. 6(nakagawa)

require(deSolve) まず deSolveを読み込む

# general parameterstimes <- c(1/365,10/365,30/365,1/4,1/2,1) # y time at which output is required

# General parameters for all runsDD <- 0.1 # cm2/y diffusion coefficient representing bioturbatinu <- 1 # cm/y advection = sedimentation rateinit <- 1000 # n.cm-3 initial density in upper layers 上層の初期密度outtime <- 6 # choose the output time point (as found in 'times') you want to see in the graphs # default outtime=6 will show distribution after 1.0 year# Function to calculate derivativesLumin <-function(t,LUMIN,parameters) 関数 Luminの定義 { with (as.list(c(LUMIN,parameters)), { FluxDiff <- -DD*diff(c(LUMIN[1],LUMIN,LUMIN[numboxes]))/delx 拡散フラックス FluxAdv <- u * (sigma * c(0,LUMIN) + (1-sigma) * 移流フラックス c(0,LUMIN[2:numboxes],LUMIN[numboxes])) 表層、中間、最深層にわける Flux <- FluxDiff + FluxAdv 拡散+移流

dLUMIN <- -diff(Flux)/delx   Flux(i) – Flux(i-1) i=2-numbox list(dLUMIN ) 境界におけるフラックス }) }

Page 23: Chap. 6(nakagawa)

# Function to run the model and produce output

Modelfunc <- function(ltt,diffm,numboxes) 関数Modelfuncの定義{ # complete set of parameters, depending on choices delx <- 3/numboxes # thickness of boxes in cm   x :ボックス長 if (diffm=="back") sigma<-1 if (diffm==“cent”) sigma<-0.5      3パターンの解き方 if (diffm=="fiad") { if (DD>0) { Pe <- u * delx/DD sigma <- (1 + (1/tanh(Pe) - 1/Pe))/2 } if (DD==0) sigma <- 1 } pars<-as.list(c(         関数 Luminの [parameters] numboxes = numboxes, delx = delx, sigma = sigma, DD = DD, u = u ))

Page 24: Chap. 6(nakagawa)

# call  呼び出し state <- c(LUMIN=Ll) 初期値 out <- ode.band(y=state,times,func=Lumin,parms=pars,nspec=1(the number of *species* (components) in the model)) # store output Dl <- out[outtime,2:(numboxes+1)] # output Distance <- seq(from=delx/2, by=delx, length.out=numboxes) # distance of box centres from x=0 if (diffm=="back") ttext<-"Backward Differences“ if (diffm=="cent") ttext<-"Centered Differences" if (diffm=="fiad") ttext<-"Fiadeiro Scheme" if (ltt==1){ #numberbox =300 plot(Dl,Distance,xlim=c(0,max(Dl)),ylim=c(numboxes*delx,0),type="l", main=ttext,xlab="Tracer density",ylab="Depth (cm)") legend(200,2, legend=c("n=300","n=120","n=60","n=30","n=15"), lty=c(1,2,3,4,5),title="no. of boxes",pch=c(-1,-1,-1,-1,-1)) pch=type of symbol } if (ltt>1)lines(Dl,Distance,lty=ltt) #numberbox =120, 60, 30, 15}

ode.band(y, times, func, parms, nspec = NULL, bandup = nspec, banddown = nspec, method = "lsode", ...)Assumes a banded Jacobian matrix, but does not rearrange the state variables (in contrast to ode.1D). Suitable for 1-D models that include transport only between adjacent layers and that model only one species.

Page 25: Chap. 6(nakagawa)

# Run model with number of different options windows() par (mfrow=c(1,3),oma=c(1,1,4,1),mar=c(5, 4, 4, 2)+0.1,mgp=c(3,1,0)) numboxlist <- c(300,120,60,30,15) for (diffm in c("back","cent","fiad")) { for (ltt in 1:5) { numboxes<-numboxlist[ltt] Modelfunc(ltt,diffm,numboxes) } } ttext<-paste("Luminophore distribution at t = ",round(times[outtime],2),"year")mtext(outer=TRUE,side=3,ttext,cex=2)

Page 26: Chap. 6(nakagawa)

小さい Pe: Centred diff.( dispersion-donated)、大きい Pe: backward diff.( advection-donated)に切り替わる。3つの schemeによる計算結果を比較。Backward は数値的分散の効果を大きく反映。ボックス数を多くしても。Centre ではボックス数が少ない場合に結果がずれる。しかし、これは初期条件の影響もある。

ボックス数 30と 300では結果がそれほど変わらない。The Fiadeiro schemeは centre differences より backward differencesに近い( D が低い値なので、 Peが大きい)。 Backwardよりは僅かに良い結果。 dispersion coefficientが増加 又は advectionが減少すれば the Feadeiro schemeは centre differencesに近づくだろう。 最後に、この場合 centred differencesは不安定性を示さなかった。

Page 27: Chap. 6(nakagawa)

R-pakage ‘desolve‘ にいくつかの numerical methodが含まれている。Function ‘ode’ はこの pakageで最も一般的なnumerical integration routine; 連続的な動きをするモデルに対して選択される方法である。不連続な動きをするモデルの場合、いくつかに分けて走らせたほうが良いだろう。

Page 28: Chap. 6(nakagawa)

#----------------------## the model equations: ##----------------------#

model<-function(t,state,parameters){ 関数modelを定義 with(as.list(c(state,parameters)),{ # unpack the state variables, parameters

dD <- -k1*E*D + k2*I dI <- k1*E*D - k2*I - k3*I*F dE <- -k1*E*D + k2*I + k3*I*F dF <- - k3*I*F dG <- k3*I*F list(c(dD,dI,dE,dF,dG)) # the output, packed as a list })}#-----------------------## the model parameters: ##-----------------------# parameters<-c(k1=0.01/24, # parameter values k2=0.1/24, k3=0.1/24)

Page 29: Chap. 6(nakagawa)

#-------------------------## the initial conditions: # 初期濃度  ( D, I, E, F, G)#-------------------------#state <-c(D=100, # state variable initial conditions I=10, E=1, F=1, G=0)#----------------------## RUNNING the model: ##----------------------#times <-seq(0,300,0.5) # time: from 0 to 300 hours, steps of 0.5 hours

# integrate the model require(deSolve) # package with the integration routine:out <-as.data.frame(ode(state,times,model,parameters))#------------------------## PLOTTING model output: ##------------------------##windows()par(mfrow=c(2,2), oma=c(0,0,3,0)) # set number of plots (mfrow) and margin size (oma)

plot (times,out$D,type="l",main="[D]",xlab="time, hours",ylab="mol/m3",lwd=2)plot (times,out$F,type="l",main="[F]",xlab="time, hours",ylab="mol/m3",lwd=2)plot (times,out$E,type="l",main="[E]",xlab="time, hours",ylab="mol/m3",lwd=2)plot (times,out$I,type="l",main="[I]",xlab="time, hours",ylab="mol/m3",lwd=2)mtext(outer=TRUE,side=3,"enzymatic reaction",cex=1.5)#plot (times,out$sum,type="l",col="red")

ode(y, times, func, parms, method = c(“lsoda”, “lsode”, “lsodes”, “lsodar”, “vode”, “daspk”, "euler", "rk4", "ode23", "ode45"), ...)

Page 30: Chap. 6(nakagawa)

Soetaert, K. and P.M.J. Herman. 2009. A practical guide to ecological modelling using R as a simulation platform. Springer.

0 50 100 150 200 250 300

99.0

99.4

99.8

[D]

time, hours

mol

/m3

0 50 100 150 200 250 300

0.0

0.2

0.4

0.6

0.8

1.0

[F]

time, hoursm

ol/m

3

0 50 100 150 200 250 300

1.00

1.10

1.20

1.30

[E]

time, hours

mol

/m3

0 50 100 150 200 250 300

9.65

9.75

9.85

9.95

[I]

time, hours

mol

/m3

enzymatic reaction

Output of the enzymatic reaction model

Page 31: Chap. 6(nakagawa)

入り江には三種(淡水性、汽水性、海水性)の動物プランクトンが生存する。これらの生物が単に物理的移動によって起こるのか、海水性動物プランクトンは入江で増殖できるのかを調べるためモデル計算を行った。( the dynamics of marine zooplankton in the Scheldt estuary (Soetaert and Herman, 1994).海水性動物プランクトン( C )の時間変化は川の流れで海に押し出される項、潮の流れで入江に入ってくる項、生物学的効果の項(正味の成長速度定数 g )で表される。

空間は川(ボックス 1)から海の近く ( ボックス 100)まで (nbox)分ける。ボックスの表面積はシグモイド関数型に 4000~ 80000m2 へ増加する。境界面積(IntArea)とボックス中央部の面積 (Area)を算出し、後者からは体積を計算する(Volume)。

Page 32: Chap. 6(nakagawa)

#-----------------------## the model parameters: ##-----------------------## the model parameters: pars <- c(riverZoo = 0.0, # river zooplankton conc g =-0.05, # /day growth rate meanFlow = 100*3600*24, # m3/d, mean river flow ampFlow = 50*3600*24, # m3/d, amplitude(振幅) phaseFlow = 1.4) # - phase of river flow(位相)#--------------------------## Initialising morphology: ##--------------------------## parameters defining the morphology# cross sectional surface area is a sigmoid function of estuarine distancenbox <- 100 Length <- 100000 # m dx <- Length/nbox # mIntDist <- seq(0,by=dx,length.out=nbox+1) # mDist <- seq(dx/2,by=dx,length.out=nbox) # m↓流路の面積IntArea <- 4000 + 76000 * IntDist^5 /(IntDist^5+50000^5) # m2Area <- 4000 + 76000 * Dist^5 /(Dist^5+50000^5) # m2Volume <- Area*dx # m3#--------------------------## Transport coefficients: ##--------------------------## parameters defining the dispersion coefficients# a linear function of estuarine distanceEriver <- 0 # m2/d Esea <- 350*3600*24 # m2/d E <- Eriver + IntDist/Length * Esea # m2/d 移流定数を一次関数式から求めるEstar <- E * IntArea/dx # m3/d

Page 33: Chap. 6(nakagawa)

#----------------------------------------------------------## estuarine advective-diffusive transport and growth/decay ##----------------------------------------------------------#require(deSolve)Zootran <-function(t,Zoo,pars){ with (as.list(pars),{ Flow <- meanFlow+ampFlow*sin(2*pi*t/365+phaseFlow) 波動関数式から流速を求める seaZoo <- approx(fZooTime, fZooConc, xout=t)$y 線形補間により求める海側境界におけるプランクトン密度 Input <- +Flow * c(riverZoo, Zoo) + -Estar* diff(c(riverZoo, Zoo, seaZoo))   flux divergence equationの A*J dZoo <- -diff(Input)/Volume + g *Zoo     flux divergence equation( C=Zoo) list(dZoo) })} #-----------------------## the forcing function: ##-----------------------## Time and measured value of zooplankton concentration at sea boundary  観測値fZooTime = c(0, 30,60,90,120,150,180,210,240,270,300,340,367)fZooConc = c(20,25,30,70,150,110, 30, 60, 50, 30, 10, 20, 20)

Page 34: Chap. 6(nakagawa)

#----------------------## RUNNING the model: ##----------------------#ZOOP <- rep(0,times=nbox) 反復ボックス 0~ 100の初期値はそれぞれ 0times <- 1:365 タイムスケール 1~365(日)out <- ode.band(times=times,y=ZOOP(初期条件) ,func=Zootran,parms=pars,nspec=1)1~365 日のタイムスケール、初期状態 (0,…,0)で関数 Zootranを計算。パラメータは parsを用いる。解くのは動物プランクトン濃度 (Zoo)に関して。Ode.bandは一次元 reaction-transfer modelの積分方法。#------------------------## PLOTTING model output: ##------------------------## Plot zooplankton; first get the datapar(oma=c(0,0,3,0)) # set margin size (oma)par(oma=c(0,0,3,0)) # set margin sizefilled.contour(x=times,y=Dist/1000,z=out[,-1],  コンターの設定 color= terrain.colors,xlab="time, days", ylab= "Distance, km",main="Zooplankton, mg/m3")mtext(outer=TRUE,side=3,"Marine Zooplankton in the Scheldt",cex=1.5)

Page 35: Chap. 6(nakagawa)
Page 36: Chap. 6(nakagawa)

生物は摂取して呼吸し、成長して生産する( the organisms ingest, respire, grow and reproduce.)。摂取速度はサイズが大きくなるに従い線形的に減少し、食糧量にも制限される(半飽和濃度定数 Ksfoodで表す)。摂取したほんの一部が同化される。同化された食物は①増体( increase of biomass)、②生産( reproduction)、③維持管理(基礎代謝)(respiration)に使われる。 Respirationは基礎代謝であり、個体重量に一次依存する。 同化と呼吸の総和が正ならば増体や繁殖に使われている。 生産は個体重量が生産重量 (reproductive weight)を超えてから始まる。生産 ( 卵の生産)に使われる割合は個体重量と共に大きく (hyperbolically)増加する。最大でも比率は 1 未満である。そうなったら成熟に達していても増体が継続する。 最後に個体重量の変化速度、卵重量、食糧供給量を計算する。後者に関しては培地中の菌体数を考慮する。関数は変化速度と 3つの変数に回帰する。  脱皮中はエネルギー消費により生物重量が減少する。重量減少は体長の相対成長関数で、体長は個体重量の相対成長関数である。 脱皮期間中の個体重量の抑制と定期的な移動のためモデルが不連続的に進行する。 Integrator ode は状態関数の変化に対応できないので必要である。脱皮段階( TimeMolt)と生物を新しい培地に移す段階( TimeTransfer)の経過をおう。 Integratorはどちらかのイベントが起こるまで進行し( TimeOut)、状態関数は各時間にて積算過程の最終状況を再初期化する。 脱皮するなら個体重量を修正し( function Moulitingを用いて)、卵重量は 0にする。そうして脱皮中の計算が行われる。 培地の移動に関して、食糧濃度( FoodInMedium)だけが変化し、Moultingと同様に Transfertimeの計算が行われる。

Page 37: Chap. 6(nakagawa)

動物プランクトン1個体についてその成長と生産を描くモデルモデルには転移培養実験を組み込んでいる。生物がボトル内で離れて育てられていることを意味し、決められた日数で決められた個体数が新しい培地に移動する。モデルでは、生物量は連続的に増加するのではない。温度に依存した脱皮期間、新しい培地への移動は定期的な不連続を成長に及ぼす。

Page 38: Chap. 6(nakagawa)

Growth of a Daphnia individual

# load package with the integration routine:

library(deSolve)

#----------------------## the model equations: ##----------------------#

model<-function(t,state,parameters) { with(as.list(c(state)),{ # unpack the state variables

# ingestion, size-dependent and food limited一個体重量あたりの摂取速度はサイズが大きくなるに従い線形的に減少し、食糧量にも制限される WeightFactor <- (IngestWeight-INDWEIGHT)/(IngestWeight-neonateWeight) MaxIngestion <- maxIngest*WeightFactor # /day Ingestion <- MaxIngestion*INDWEIGHT*FOOD / (FOOD + ksFood)食糧の制限がかけられた摂取量 Respiration <- respirationRate * INDWEIGHT # gC/day 呼吸量  Growth <- Ingestion*assimilEff – Respiration 成長に使われる量

Page 39: Chap. 6(nakagawa)

# Fraction of assimilate allocated to reproduction if (Growth <= 0. | INDWEIGHT<reproductiveWeight) Reproduction <- 0. 生産力は 0 else { # Fraction of growth allocated to reproduction. WeightRatio <- reproductiveWeight/INDWEIGHT 個体重量に対する生産量 Reproduction <- maxReproduction * (1. - WeightRatio^2) } # rate of change dINDWEIGHT <- (1. -Reproduction) * Growth dEGGWEIGHT <- Reproduction * Growth dFOOD <- -Ingestion * numberIndividuals # the output, packed as a list list(c(dINDWEIGHT, dEGGWEIGHT, dFOOD), # the rate of change c(Ingestion = Ingestion, # the ordinary output variables Respiration = Respiration, Reproduction = Reproduction)) }) } # end of model#----------------------## Moulting weight loss ##----------------------#Moulting <- function () { with(as.list(c(state)),{ # unpack the state variables # Relationship moulting loss and length refLoss <- 0.24 # オ gC cLoss <- 3.1 #- # Weight lost during molts depends allometrically on the organism length INDLength <- (INDWEIGHT /3.0)^(1/2.6)

WeightLoss <- refLoss * INDLength^cLoss return(INDWEIGHT - WeightLoss) # New weight }) }