z0=20 ro=0.3 landa=3 beta=1 c1=0.3 # hazine negahdari c2=0.05 # hazine bazrasi cr=10 B=10 # maximum of k f <- function(x){ lis <- list() for(i in 1:x) { lis[[i]] <-c(0,1) } do.call(expand.grid,lis) } L=function(M,tu){ p=pgamma( z0, landa^(tu), beta)-pgamma( M, landa^(tu), beta) q=1-pgamma( z0, landa^(tu), beta) for(j in 2:B) { a=2^(j-1) xx=f(j-1) ppi=matrix(0,a,j-1) ss1=c() tt1=c() for(i in 1:a) { for(k in 1:(j-1)) { if(xx[i,k]==1) ppi[i,k]=p[k] if(xx[i,k]==0) ppi[i,k]=1-p[k] } x1=which(xx[i,]==1) r=length(x1) w=0 if(r>0) w=ro*x1[r]*tu ss=(pgamma( z0, landa^(j*tu-w), beta)-pgamma(M, landa^(j*tu-w), beta))*prod(ppi[i,]) ss1=c(ss1,ss) tt=(1-pgamma( z0, landa^(j*tu-w), beta))*prod(ppi[i,]) tt1=c(tt1,tt) } p=c(p,sum(ss1)) q=c(q,sum(tt1)) } q=round(q,10) BI=which.max(q) q=q/sum(q[1:BI]) p=p/sum(p[1:BI]) E=function(k){ if(k==1) return(0) else return(sum(sapply(1 :(k-1),function(j) p[j]))) } C=1+sum(sapply(1:BI,function(k) (k*c2+c1*E(k))*q[k])) TT=sum(sapply(1:BI ,function(k) k*tu*q[k])) return(C*cr/TT) } L <- Vectorize(L,"M") L <-Vectorize(L,"tu") #L(c(20,30),c(0.3,0.4)) L1=function(M) L(M,tu) tu=.5 optimize(L1, interval = c(0, z0))
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException()
#3 [internal function]: yii\base\ErrorHandler->handleException()
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(656): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/models/Files.php(696): yii\base\Application->end()
#3 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/controllers/FilesController.php(484): faravaghi\filemanager\models\Files->getFile()
#4 [internal function]: faravaghi\filemanager\controllers\FilesController->actionGetFile()
#5 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#6 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#7 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction()
#8 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#9 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest()
#10 /var/www/html/prof-homepages/frontend/web/index.php(18): yii\base\Application->run()
#11 {main}