看板 Math 關於我們 聯絡資訊
※ 引述《hina09 (Hina*)》之銘言: : 已知x+2y+4z+u=8 : 求4x+5y+6z+3u的最大值 : 1. 0≦x.y.z.u : 2. 0≦x.y.z.u≦3 : 不知道題目是否有誤 : 煩請版上高手指點,謝謝~ 用個程式硬幹的手法 cvx (convex optimization) 有興趣知道數學背景請參閱 Stanford教授 Stephen Boyd網頁 http://stanford.edu/~boyd/ 敲個程式碼大約1分鐘! 答案26 @.@ cvx_begin variable x(4) maximize(4*x(1)+5*x(2)+6*x(3)+3*x(4)) subject to x(1)+2*x(2)+4*x(3)+x(4)==8 x>=0 x<=3 cvx_end Calling SDPT3 4.0: 8 variables, 3 equality constraints For improved efficiency, SDPT3 is solving the dual problem. ------------------------------------------------------------ num. of constraints = 3 dim. of linear var = 8 ******************************************************************* SDPT3: Infeasible path-following algorithms ******************************************************************* version predcorr gam expon scale_data NT 1 0.000 1 0 it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime ------------------------------------------------------------------- 0|0.000|0.000|7.8e-01|3.7e+00|8.0e+02| 1.200000e+02 0.000000e+00| 0:0:00| chol 1 1 1|1.000|1.000|4.5e-07|4.3e-02|8.8e+01| 8.345473e+01 1.580001e+00| 0:0:00| chol 1 1 2|0.900|1.000|1.2e-07|4.3e-03|8.5e+00| 1.144400e+01 3.019397e+00| 0:0:00| chol 1 1 3|0.927|0.880|2.7e-08|8.9e-04|1.8e+00| 7.495398e+00 5.755842e+00| 0:0:00| chol 1 1 4|0.992|0.927|1.3e-07|1.0e-04|1.1e-01| 6.561668e+00 6.455986e+00| 0:0:00| chol 1 1 5|0.987|0.987|2.3e-09|5.6e-06|1.4e-03| 6.500784e+00 6.499494e+00| 0:0:00| chol 1 1 6|0.989|0.989|2.5e-10|6.2e-08|1.5e-05| 6.500009e+00 6.499994e+00| 0:0:00| chol 1 1 7|0.989|0.989|4.2e-12|7.3e-10|1.7e-07| 6.500000e+00 6.500000e+00| 0:0:00| stop: max(relative gap, infeasibilities) < 1.49e-08 ------------------------------------------------------------------- number of iterations = 7 primal objective value = 6.50000009e+00 dual objective value = 6.49999994e+00 gap := trace(XZ) = 1.66e-07 relative gap = 1.19e-08 actual relative gap = 1.12e-08 rel. primal infeas = 4.25e-12 rel. dual infeas = 7.29e-10 norm(X), norm(y), norm(Z) = 4.3e+00, 3.2e+00, 5.7e+00 norm(A), norm(b), norm(C) = 3.6e+00, 4.5e+00, 6.6e+00 Total CPU time (secs) = 0.14 CPU time per iteration = 0.02 termination code = 0 DIMACS: 5.5e-12 0.0e+00 1.2e-09 0.0e+00 1.1e-08 1.2e-08 ------------------------------------------------------------------- ------------------------------------------------------------ Status: Solved Optimal value (cvx_optval): +26 -- 我康宣今年十八歲,姑蘇人士,身家清白素無過犯,只 為家況清貧,鬻身華相府中充當書僮,身價銀五十兩,自 秋節起暫存帳房,待三年後支取,從此承值書房,每日焚 香掃地洗硯磨墨等事,聽憑使喚,從頭做起,立此為據。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 172.5.42.156 ※ 文章網址: https://www.ptt.cc/bbs/Math/M.1457760290.A.B17.html ※ 編輯: snaredrum (172.5.42.156), 03/12/2016 13:25:50