Is it possible to calculate an integral in GAMS?

Hi,

I need to calculate the volume of a tree by integrating the “taper” function below. I did this code in R, and it works well, but now that I am trying to code it in GAMS I cannot find a way of doing that.
How do we calculate integrals in GAMS?
Any suggestions?


midh ← 13.5
midd ← 15.1

taper1 ← function(midh){
taper2 ← function(midd){
tFactorSBD ← 1.3/midh
qFactorSBD ← (0/100)/midh
YFactorSBD ← (1-qFactorSBD^0.5)/(1-tFactorSBD^0.5)
aux1SBD ← 0.6624965*(YFactorSBD^0.1)+ 0.3781478*(qFactorSBD^4)
aux2SBD ← -0.4418430asin(1-sqrt(qFactorSBD))
aux3SBD ← -0.5154988/exp(midd/midh)
aux4SBD ← 0.0197963
midd^YFactorSBD
ExpFactorSBD ← aux1SBD+ aux2SBD+ aux3SBD+ aux4SBD
diam ← 0.8795844*(midd^0.9457765)(midh^0.1061692)(YFactorSBD^ExpFactorSBD)
area<- pi*((diam/2)^2)/10000
}
}

volume<- function(midh){
integrate(taper1(midh), lower = 0,upper = midh)$value
}

Thanks

Ana

hi, i think you should use an analytic integration (if possible) otherwise make a numerical integration (like simpson rule).

Whereas Simpson’s Rule or even the Trapezoid Rule are theoretically preferable to the Left Hand Rule or Right Hand Rule, one can just integrate with a higher granularity (i.e., smaller intervals) and use one of the simpler approaches. A “loop” structure works nicely, incrementally adding the area under the next segment of the function to a scalar.