最大化向量的按列乘法

时间:2019-05-06 09:56:39

标签: r matrix

给出矩阵 webView.setWebViewClient(new WebViewClient() { public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { //HANDLE HERE THE ERROR!!! ... } ... });

M

如何找到向量M <- structure(c(0.0700078597292304, -0.0136474068276584, 0.328056303784251, -0.459178164601326, -0.586918574757874, 0.791669885627925, -0.877064344473183, 0.882802148349583, 0.421708580106497, -0.110332333017141, -0.287893873639405, 0.00899101700633764, -0.705056414008141, -0.897502972278744, 0.0145046846009791, -0.409322344232351, 0.622156938537955, 0.941861041355878, 0.622148288879544, 0.741163543891162, 0.695223031565547, 0.514508185908198, -0.297026146668941, -0.930878807790577, 0.72842172626406, 0.899442498106509, -0.0246643857099116, 0.993599037639797, 0.150956830941141, 0.341335460077971 ), .Dim = c(10L, 3L)) # [,1] [,2] [,3] # [1,] 0.07000786 -0.287893874 0.69522303 # [2,] -0.01364741 0.008991017 0.51450819 # [3,] 0.32805630 -0.705056414 -0.29702615 # [4,] -0.45917816 -0.897502972 -0.93087881 # [5,] -0.58691857 0.014504685 0.72842173 # [6,] 0.79166989 -0.409322344 0.89944250 # [7,] -0.87706434 0.622156939 -0.02466439 # [8,] 0.88280215 0.941861041 0.99359904 # [9,] 0.42170858 0.622148289 0.15095683 # [10,] -0.11033233 0.741163544 0.34133546 (单位间隔中w的每个元素),该向量最大化ww的列乘积之和(以miximize M)?

1 个答案:

答案 0 :(得分:1)

只需定义您的目标函数:

fn <- function(w) sum(M %*% w)

然后优化:

optim(rep(0, 3), fn, lower = 0, upper = 1, method = "L-BFGS-B", control = list(fnscale = -1))
#$par
#[1] 1 1 1
#
#$value
#[1] 4.169071
#
#$counts
#function gradient 
#       4        4 
#
#$convergence
#[1] 0
#
#$message
#[1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL"