Hi: On Wed, Feb 9, 2011 at 6:29 AM, Claudio Carneiro < claudio_carneiro...@hotmail.com> wrote:
> > Hi, all > > I'm trying to solve an optimization problem with two > variables, in wich Iuse the following functions(they all are working > perfectly): > > fxx1=function(x){ > calc=((2.5/3)*((x/3)^(2.5-1))*exp(-(x/3)^2.5)) > return(calc)} > > fxx2=function(x){ > calc1=((5.3/19.3)*((x/19.3)^(5.3-1))*exp(-(x/19.3)^5.3)) > return(calc1)} > > fxMixed=function(x){ > calc2=(0.12*fxx1(x)+((1-0.12)*fxx2(x))) > return(calc2)} > > > FxMixed=function(x){ > calc3=integrate(fxMixed,0,x) > return(calc3$value)} > > RxMixed=function(x){ > calc4=(1-FxMixed(x)) > return(calc4)} > > SUM=function(x){ > T1=x[1] > M1=x[2] > n=M1-1 > calc5=1:n > for (i in 0:n){ > calc5[i]=RxMixed(i*T1)} > sum(calc5)} > > V=function(x){ > T1=x[1] > M1=x[2] > y=T1*M1 > calc6=T1*SUM(x)+0.001*RxMixed(y)+0.00463*FxMixed(y) > return(calc6)} > > However, when I try to use the function U, there is an error message and I > don't understand what's wrong with my code: > > U=function(x){ > T1=x[1] > M1=x[2] > y=M1*T1 > calc7=integrate(RxMixed,0,y) > return(calc7$value)} > > U(c(2,5)) > Error in integrate(RxMixed, 0, y) : > evaluation of function gave a result of wrong length > > > > I think that this might happen becouse my fucntion RxMixed is already an > previous integration of the function fxMixed. > I concur. RxMixed is a number, not a function - integrate() requires the latter. It appears that RxMixed is the survival function of a mixture distribution - you need to either get a symbolic representation of that function or generate a function numerically by computing RxMixed over a suitable range of x values and then using something like approxfun() or splinefun() to estimate the survival function. You could then integrate the resulting function in U. HTH, Dennis > > Any help will be welcome! > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.