版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、優(yōu)化方法上機(jī)大作業(yè)院系:化工與環(huán)境生命學(xué)部姓名:李翔宇學(xué)號(hào): 31607007指導(dǎo)老師 :肖現(xiàn)濤第一題:1. 最速下降法源程序如下:function x_star =zsxj x0,eps gk = gradx0;res = normgk; k = 0;while res eps & k f0 + 0.0001*ak*slope ak = ak/2;xk = x0 + ak*dk; f1 = funxk; endk = k+1; x0 = xk;gk = gradxk;res = normgk;fprintf-the %d-th iter, the residual is %fn,k,res;
2、endx_star = xk; endfunction f = funxf = 1-x12 + 100*x2-x122;endfunction g = gradx g = zeros2,1;g1=2*x1-1+400*x1*x12-x2; g2 = 200*x2-x12;end運(yùn)行結(jié)果: x0=0,0; esp=1e-4; xk= zsxj x0,eps-the 1-th iter, the residual is 13.372079-the 2-th iter, the residual is 12.079876-the 3-th iter, the residual is 11.05410
3、5-the 9144-th iter, the residual is 0.000105-the 9145-th iter, the residual is 0.000102-the 9146-th iter, the residual is 0.000100 xk =0.99990.9998matlab截屏:2. 牛頓法源程序如下:function x_star =newton x0,eps gk = gradx0;bk = grad2x0-1;res = normgk; k = 0;while res eps & k x0=0,0;eps=1e-4; xk= newton x0,eps-t
4、he 1-th iter, the residual is 447.213595-the 2-th iter, the residual is 0.000000 xk =1.00001.0000matalb截屏 ;3. bfgs 方法源程序如下:function x_star =bfgs x0,eps g0 = gradx0;gk=g0;res = normgk;hk=eye2;k = 0;while res eps & k f0 + 0.1*ak*slope ak = ak/2;xk = x0 + ak*dk; f1 = funxk; endk = k+1; fa0=xk-x0; x0 =
5、xk; g0=gk;gk = gradxk; y0=gk-g0;hk=eye2-fa0*y0/fa0*y0*eye2-y0*fa0/fa0*y0+fa0*fa0/fa0*y0; res = normgk;fprintf-the %d-th iter, the residual is %fn,k,res; endx_star = xk;endfunction f=funxf=1-x12 + 100*x2-x122;endfunction g = gradx g = zeros2,1;g1=2*x1-1+400*x1*x12-x2;g2 = 200*x2-x12;end運(yùn)行結(jié)果: x0=0,0;
6、esp=1e-4; xk= bfgs x0,eps-the 1-th iter, the residual is 3.271712-the 2-th iter, the residual is 2.381565-the 3-th iter, the residual is 3.448742-the 1516-th iter, the residual is 0.000368-the 1517-th iter, the residual is 0.000099 xk =1.00011.0002matlab截屏:4. 共軛梯度法源程序如下:function x_star =conj x0,eps
7、gk = gradx0;res = normgk;k = 0;dk = -gk;while res eps & k f0 + 0.1*ak*slopeak = ak/2;xk = x0 + ak*dk; f1 = funxk; end d0=dk;g0=gk; k=k+1;x0=xk;gk=gradxk;f=normgk/normg02; res=normgk;dk=-gk+f*d0;fprintf-the %d-th iter, the residual is %fn,k,res;endx_star = xk; endfunction f=funxf=1-x12+100*x2-x122;en
8、dfunction g=gradx g=zeros2,1;g1=400*x13-400*x1*x2+2*x1-2; g2=-200*x12+200*x2;end運(yùn)行結(jié)果: x0=0,0; eps=1e-4; xk=conjx0,eps-the 1-th iter, the residual is 3.271712-the 2-th iter, the residual is 1.380542-the 3-th iter, the residual is 4.527780-the 4-th iter, the residual is 0.850596-the 73-th iter, the re
9、sidual is 0.001532-the 74-th iter, the residual is 0.000402-the 75-th iter, the residual is 0.000134-the 76-th iter, the residual is 0.000057 xk =0.99990.9999matlab截屏:其次題:解 :目標(biāo)函數(shù)文件 f1.m function f=f1xf=4*x1-x22-12;等式約束函數(shù)文件h1.m function he=h1xhe=25-x12-x22;不等式約束函數(shù)文件g1.m function gi=g1xgi=10*x1-x12+10
10、*x2-x22-34;目標(biāo)函數(shù)的梯度文件df1.m function g=df1xg = 4, 2.0*x2;等式約束(向量)函數(shù)的jacobi 矩陣(轉(zhuǎn)置)文件dh1.m function dhe=dh1xdhe = -2*x1, -2*x2;不等式約束(向量)函數(shù)的jacobi 矩陣(轉(zhuǎn)置)文件dg1.m function dgi=dg1xdgi = 10-2*x1, 10-2*x2;然后在 matlab命令窗口輸入如下命令: x0=0,0;x,mu,lambda,output=multphrf1,h1,g1,df1,dh1,dg1,x0;得到如下輸出 :x =4.898717426488
11、211.00128197198571算法編程利用程序調(diào)用格式第三題:1. 解:將目標(biāo)函數(shù)改寫(xiě)為向量形式:x*a*x-b*x程序代碼:n=2; a=0.5,0;0,1; b=2 4;c=1 1;cvx_begin variable xnminimize x*a*x-b*xsubject to c * x =0cvx_end運(yùn)算結(jié)果 :calling sdpt3 4.0: 7 variables, 3 equality constraintsfor improved efficiency, sdpt3 is solving the dual problem.num. of constraints
12、= 3dim. of socpvar = 4,num. of socp blk = 1 dim. of linear var = 3*sdpt3: infeasible path-following algorithms* version predcorr gam expon scale_datant10.00010it pstep dstep pinfeas dinfeas gapprim-objdual-objcputime0|0.000|0.000|8.0e-001|6.5e+000|3.1e+002| 1.000000e+001 0.000000e+000| 0:0:00| chol
13、1 11|1.000|0.987|4.3e-007|1.5e-001|1.6e+001| 9.043148e+000 -2.714056e-001| 0:0:01| chol 1 12|1.000|1.000|2.6e-007|7.6e-003|1.4e+000| 1.234938e+000 -5.011630e-002| 0:0:01| chol 1 13|1.000|1.000|2.4e-007|7.6e-004|3.0e-001| 4.166959e-0011.181563e-001| 0:0:01| chol114|0.892|0.877|6.4e-008|1.6e-004|5.2e-
14、002| 2.773022e-0012.265122e-001| 0:0:01| chol115|1.000|1.000|1.0e-008|7.6e-006|1.5e-002| 2.579468e-0012.427203e-001| 0:0:01| chol116|0.905|0.904|3.1e-009|1.4e-006|2.3e-003| 2.511936e-0012.488619e-001| 0:0:01| chol117|1.000|1.000|6.1e-009|7.7e-008|6.6e-004| 2.503336e-0012.496718e-001| 0:0:01| chol118
15、|0.903|0.903|1.8e-009|1.5e-008|1.0e-004| 2.500507e-0012.499497e-001| 0:0:01| chol119|1.000|1.000|4.9e-010|3.5e-010|2.9e-005| 2.500143e-0012.499857e-001| 0:0:01| chol1110|0.904|0.904|5.7e-011|1.3e-010|4.4e-006| 2.500022e-0012.499978e-001| 0:0:01| chol2211|1.000|1.000|5.2e-013|1.1e-011|1.2e-006| 2.500
16、006e-0012.499994e-001| 0:0:01| chol2212|1.000|1.000|5.9e-013|1.0e-012|1.8e-007| 2.500001e-0012.499999e-001| 0:0:01| chol2213|1.000|1.000|1.7e-012|1.0e-012|4.2e-008| 2.500000e-0012.500000e-001| 0:0:01| chol2214|1.000|1.000|2.3e-012|1.0e-012|7.3e-009| 2.500000e-0012.500000e-001| 0:0:01|stop: maxrelati
17、ve gap, infeasibilities 1.49e-008number of iterations = 14primal objective value = 2.50000004e-001 dual objective value = 2.49999996e-001 gap := tracexz = 7.29e-009relative gap= 4.86e-009 actual relative gap= 4.86e-009rel. primal infeas scaled problem= 2.33e-012rel. dual= 1.00e-012rel. primal infeas
18、 unscaled problem = 0.00e+000 rel. dual = 0.00e+000normx, normy, normz = 3.2e+000, 1.5e+000, 1.9e+000 norma, normb, normc = 3.9e+000, 4.2e+000, 2.6e+000 total cpu time secs = 0.99cpu time per iteration = 0.07termination code= 0dimacs: 3.3e-012 0.0e+000 1.3e-012 0.0e+000 4.9e-009 4.9e-009status: solv
19、edoptimal value cvx_optval: -32. 程序代碼:n=3;a=-3 -1 -3;b=2;5;6;c=2 1 1;1 2 3;2 2 1;cvx_begin variable xn minimize a*x subject toc * x =0cvx_end運(yùn)行結(jié)果:calling sdpt3 4.0: 6 variables, 3 equality constraintsnum. of constraints = 3 dim. of linear var = 6*sdpt3: infeasible path-following algorithms* version
20、predcorr gam expon scale_datant10.00010it pstep dstep pinfeas dinfeas gapprim-objdual-objcputime0|0.000|0.000|1.1e+001|5.1e+000|6.0e+002|-7.000000e+001 0.000000e+000| 0:0:00| chol 1 11|0.912|1.000|9.4e-001|4.6e-002|6.5e+001|-5.606627e+000 -2.967567e+001| 0:0:00| chol112|1.000|1.000|1.3e-007|4.6e-003
21、|8.5e+000|-2.723981e+000 -1.113509e+001| 0:0:00| chol113|1.000|0.961|2.3e-008|6.2e-004|1.8e+000|-4.348354e+000 -6.122853e+000| 0:0:00| chol114|0.881|1.000|2.2e-008|4.6e-005|3.7e-001|-5.255152e+000 -5.622375e+000| 0:0:00| chol115|0.995|0.962|1.6e-009|6.2e-006|1.5e-002|-5.394782e+000 -5.409213e+000| 0:0:00| chol116|0.989|0.989|2.7e-010|5.2e-007|1.7e-004|-5.399940e+000 -5.400100e+000| 0:0:00| chol117|0.989|0.989|5.3e-011|5.8e-009|1.8e-006|-5.399999e+000 -5.400001e+000| 0:0:00| chol8|1.000|0.
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 煙草制品銷(xiāo)售合同調(diào)解
- 體育經(jīng)紀(jì)律師聘用協(xié)議
- 智能家居控制系統(tǒng)布線協(xié)議
- 房屋室內(nèi)裝飾施工合同
- 食醋公司總經(jīng)理聘用合同
- 社交高炮施工合同
- 衛(wèi)生打掃合同范例
- 塑料草皮購(gòu)銷(xiāo)合同范例
- 公民代理 勞動(dòng)合同
- 工作師徒合同評(píng)價(jià)
- 中小學(xué)生反恐防暴安全教育課件
- 《藥物制劑工程》課程教學(xué)大綱全套
- DL-T 2559-2022 燈泡貫流式水輪機(jī)狀態(tài)檢修評(píng)估技術(shù)導(dǎo)則
- 信陽(yáng)市光山縣2023-2024學(xué)年七年級(jí)上學(xué)期期末數(shù)學(xué)測(cè)試卷(含答案)
- 《“健康中國(guó)2030”規(guī)劃綱要》全文健康中國(guó)2030規(guī)劃綱要全文
- 案場(chǎng)物業(yè)管理制度
- 軍隊(duì)文職-政治理論-政治-馬克思主義基本原理練習(xí)一
- 南京聯(lián)合體2022-2023學(xué)年九年級(jí)上學(xué)期期中考試化學(xué)試題(含答案)
- 電子商務(wù)網(wǎng)絡(luò)商務(wù)信息采集與處理考核試題及答案
- SA8000-2014社會(huì)責(zé)任績(jī)效委員會(huì)SPT組織架構(gòu)、職責(zé)和定期檢討及評(píng)審會(huì)議記錄
- 攪拌釜式反應(yīng)器攪拌釜式反應(yīng)器課件
評(píng)論
0/150
提交評(píng)論