Comparing SAS and R results after resolving a system of differential equations -


i main objectif obtain same results on sas , on r. somethimes , depending on case, easy. otherwise difficult, specially when want compute more complicated usual.

so, in ored understand case, have following differential equation system :

y' = z

z' = b* y'+c*y

let : b = - 2 , c = - 4, y(0) = 0 , z(0) = 1

in order resolve system, in sas use command proc model :

 data t;      time=0 40;      output;      end;   run;    proc model data=t ;    dependent y 0 z 1;    parm b -2 c -4;      dert.y = z;      dert.z = b * dert.y + c * y;    solve y z / dynamic solveprint out=out1;      run; 

in r, write following solution using lsoda function of desolve package:

library(desolve) b <- -2; c <- -4; rigidode <- function(t, y, parms) { with(as.list(y), { dert.y <- z dert.z <- b * dert.y + c * y list(c(dert.y, dert.z)) }) } yini <- c(y = 0, z = 1) times <- seq(from=0,to=40,by=1) out_ode <- ode (times = times, y = yini, func = rigidode, parms = null) out_lsoda <- lsoda (times = times, y = yini, func = rigidode, parms = null) 

here results : sas enter image description here

r enter image description here

for time t=0,..,10 , obtain similar results. t=10,...,40, start have differences. me, these differences important.

in order correct these differences, fixed on r error truncation term on 1e-9 in stead of 1e-6. verified if numerical integration methods , hypothesis used default same.

do have idea how deal problem?

sincerely yours, mily


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -