J Gre Posted May 25, 2021 Share Posted May 25, 2021 Hi, I'm trying to manipulate the simplt DCA script to one that does rate vs. cumulative production instead of rate vs. time. I have very little R experience and just tried to remove/replace all the instances of time with cumulative production. This is what I did. #------------------------------------------------------------------------------ Hyp.q.forward.fun = function(Gp, Hyp.qi, Hyp.b, Hyp.Di ){ # Peter Shaw # e.g. SPE 98042 (11a) Hyp.q.theo = Hyp.qi*(1-(Gp/(Hyp.qi*((1-Hyp.b)*Hyp.Di)^(-1))))^(1/(1-Hyp.b)) return(Hyp.q.theo) } #------------------------------------------------------------------------------ residfun = function(x,x.cum,y.prod){ Hyp.qi = x[1] Hyp.b = x[2] Hyp.Di = x[3] q.theo = Hyp.q.forward.fun( Gp=x.cum, Hyp.qi=Hyp.qi, Hyp.b=Hyp.b, Hyp.Di=Hyp.Di) #plot(x.cum,y.prod); lines(x.cum,q.theo) residual = sqrt(sum((q.theo-y.prod)^2)) return(residual) } #------------------------------------------------------------------------------ min.data = 3 result = data.frame( cum.prod = numeric(0), production = numeric(0), theo = numeric(0) ) Hyp.qi =as.numeric(NA) Hyp.b =as.numeric(NA) Hyp.Di =as.numeric(NA) ok = length(col.Production)>0 if(ok) ok = length(col.cumProd) == length(col.Production) if(ok){ u.order = order(col.cumProd) col.cumProd = col.cumProd[u.order] col.Production = col.Production[u.order] u0 = which.max(col.Production) u = u0:length(col.Production) x.cum = col.cumProd y.prod = col.Production x0 = c(y.prod[1]) optim.result = optim( par = x0, fn=residfun, x.cum=x.cum, y.prod=y.prod ) Hyp.qi = optim.result$par[1] Hyp.b = optim.result$par[2] Hyp.Di = optim.result$par[3] result = data.frame( cum.prod = x.cum, production = y.prod ) } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now