Wednesday, 15 January 2014

R: order of calculation -



R: order of calculation -

vn <- function(n,s,y){ if (n < n){ v <- 1/(1+r)*(ptil*vn(n+1,u*s,a*u*s+y)+qtil*vn(n+1,s*d, a*d*s+y)) return(v) } if (n == n){ return(max(c(0,y-k))) } } vn(0,s0, a*s0)

how r calculate this? r first calculate vn(1,us,aus+y), vn(2,us,aus+y), vn(3,us,aus+y),... until vn(n,us,aus+y) , start vn(2,ds,ad*s+y),...? or right order r calculate this? take illustration n = 3.

the general rule r evaluates inside-to-out (lowest nested look highest nested expression), , left-to-right after that. if you're worried things beingness evaluated in wrong order, braces answer, since separate equation you're using distinct expressions.

r order

No comments:

Post a Comment