CVX is a Matlab-based modeling system for convex optimization. CVX turns Matlab into a modeling language, allowing constraints and objectives to be specified using standard Matlab expression syntax.
我們從最新版本cvx 3.0的安裝、注冊和實例講起,對自己最新文章中的一個算法進行驗證。
1、CVX 3.0 安裝
CVX 3.0 beta是最新版本,支持多個平台,附下載地址。
注意3.0版本和2.X版本不兼容,只能下載安裝其一,如果已安裝任意版本均需要卸載才能安裝新版本。
(1)下載zip文件后,解壓縮至任意地址,如D:\Download\cvx-w64
(2)打開matlab將當前文件位置改到D:\Download\cvx-w64\cvx
(3)matlab 命令行中輸入命令
cvx_setup
- 1
安裝正常后信息顯示如下
>> cvx_setup --------------------------------------------------------------------------- CVX: Software for Disciplined Convex Programming (c)2014 CVX Research Version 2.1, Build 1110 (66e9a9c) Wed Jun 10 21:43:38 2015 --------------------------------------------------------------------------- Installation info: Path: D:\Download\cvx-w64\cvx MATLAB version: 8.3 (R2014a) OS: Windows 7 amd64 version 6.1 Java version: 1.7.0_11 Verfying CVX directory contents: No missing files. Preferences: none found; defaults loaded. License host: Username: user Host ID: 64006a58e9ad (eth3) Installed license: No license installed. No valid licenses found. Click here to fill out an academic license request for the username and first hostid listed above. --------------------------------------------------------------------------- Setting CVX paths...done. Saving updated path...done. Searching for solvers...5 shims found. 2 solvers initialized (* = default): * SDPT3 4.0 {cvx}\sdpt3 SeDuMi 1.34 {cvx}\sedumi 3 solvers skipped: GLPK Could not find a GLPK installation. Gurobi {cvx}\gurobi\w64 No valid Gurobi license was found. (Please note that this license is *not the same* as the CVX license; it must be obtained directly from Gurobi Optimization.) If you do have a Gurobi license, the the Gurobi MEX file could not find it. Please consult the Gurobi documentation for assistance. Mosek unknown {cvx}\mosek\w64 A CVX Professional license is required. Saving updated preferences...done. Testing with a simple model...done! --------------------------------------------------------------------------- To change the default solver, type "cvx_solver <solver_name>". To save this change for future sessions, type "cvx_save_prefs". Please consult the users' guide for more information. ---------------------------------------------------------------------------
(4)敲入
cvx_version
可看到還沒完成注冊
>> cvx_version --------------------------------------------------------------------------- CVX: Software for Disciplined Convex Programming (c)2014 CVX Research Version 2.1, Build 1110 (66e9a9c) Wed Jun 10 21:43:38 2015 --------------------------------------------------------------------------- Installation info: Path: D:\Download\cvx-w64\cvx MATLAB version: 8.3 (R2014a) OS: Windows 7 amd64 version 6.1 Java version: 1.7.0_11 Verfying CVX directory contents: No missing files. Preferences: Path: C:\Users\user\AppData\Roaming\MathWorks\MATLAB\cvx_prefs.mat License host: Username: user Host ID: 64006a58e9ad (eth3) Installed license: No license installed. No valid licenses found. Click here to fill out an academic license request for the username and first hostid listed above. ---------------------------------------------------------------------------
2、CVX 3.0 注冊
(1)在此地址進行注冊申請注冊,如果有高效郵箱是可以申請免費試用的。
以“Academic license request”為例,填寫一些很基本的信息,其中需要在此部分
中填寫剛才上一個代碼段的信息
License host:
Username: user
Host ID: 64006a58e9ad (eth3)
- 1
- 2
- 3
(2)然后在自己郵箱中接收郵件,將附件cvx_license隨意另存個位置,如D:\Download\cvx_license.dat
(3)matlab命令行中輸入
cvx_setup D:/Download/cvx_license.dat
- 1
順利注冊后的信息如下
>> cvx_setup D:/Download/cvx_license.dat --------------------------------------------------------------------------- CVX: Software for Disciplined Convex Programming (c)2014 CVX Research Version 2.1, Build 1110 (66e9a9c) Wed Jun 10 21:43:38 2015 --------------------------------------------------------------------------- Installation info: Path: D:\Download\cvx-w64\cvx MATLAB version: 8.3 (R2014a) OS: Windows 7 amd64 version 6.1 Java version: 1.7.0_11 Verfying CVX directory contents: No missing files. Preferences: Path: C:\Users\user\AppData\Roaming\MathWorks\MATLAB\cvx_prefs.mat License host: Username: user Host ID: 64006a58e9ad (eth3) Installed license: No license installed. Installing license: File: D:/Download/cvx_license.dat Organization: ******** university, P.R.China Contact: ** **** (********@***.edu.cn) License type: academic Named user: user Host ID: 64006a58e9ad Expiration: 2017-05-17 (364 days remaining) Status: verified --------------------------------------------------------------------------- Setting CVX paths...already set! Searching for solvers...5 shims found. 3 solvers initialized (* = default): Mosek 7.1.0.12 {cvx}\mosek\w64 * SDPT3 4.0 {cvx}\sdpt3 SeDuMi 1.34 {cvx}\sedumi 2 solvers skipped: GLPK Could not find a GLPK installation. Gurobi {cvx}\gurobi\w64 No valid Gurobi license was found. (Please note that this license is *not the same* as the CVX license; it must be obtained directly from Gurobi Optimization.) If you do have a Gurobi license, the the Gurobi MEX file could not find it. Please consult the Gurobi documentation for assistance. Saving updated preferences...done. Testing with a simple model...done! --------------------------------------------------------------------------- To change the default solver, type "cvx_solver <solver_name>". To save this change for future sessions, type "cvx_save_prefs". Please consult the users' guide for more information. ---------------------------------------------------------------------------
3、例程
官網上有個很簡單的小案例
4、備注
最后特別提醒下,cvx工具箱只能解決特定形式的問題,如對於包含除號的目標函數,就無能為力了,即使你證明了這個OP是凸的,這時可以考慮使用fmincon函數。