![2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)_第1頁](http://file4.renrendoc.com/view/dc9f39db5f555bffefbeefbe399fae5b/dc9f39db5f555bffefbeefbe399fae5b1.gif)
![2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)_第2頁](http://file4.renrendoc.com/view/dc9f39db5f555bffefbeefbe399fae5b/dc9f39db5f555bffefbeefbe399fae5b2.gif)
![2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)_第3頁](http://file4.renrendoc.com/view/dc9f39db5f555bffefbeefbe399fae5b/dc9f39db5f555bffefbeefbe399fae5b3.gif)
![2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)_第4頁](http://file4.renrendoc.com/view/dc9f39db5f555bffefbeefbe399fae5b/dc9f39db5f555bffefbeefbe399fae5b4.gif)
![2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)_第5頁](http://file4.renrendoc.com/view/dc9f39db5f555bffefbeefbe399fae5b/dc9f39db5f555bffefbeefbe399fae5b5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
2023年大連理工大學(xué)優(yōu)化方法上機(jī)大作業(yè)學(xué)院:專業(yè):班級:學(xué)號:姓名:上機(jī)大作業(yè)1:1.最速下降法:functionf=fun(x)f=(1-x(1))^2+100*(x(2)-x(1)^2)^2;endfunctiong=grad(x)g=zeros(2,1);g(1)=2*(x(1)-1)+400*x(1)*(x(1)^2-x(2));g(2)=200*(x(2)-x(1)^2);endfunctionx_star=steepest(x0,eps)gk=grad(x0);res=norm(gk);k=0;whileres>eps&&k<=1000dk=-gk;ak=1;f0=fun(x0);f1=fun(x0+ak*dk);slope=dot(gk,dk);whilef1>f0+0.1*ak*slopeak=ak/4;xk=x0+ak*dk;f1=fun(xk);endk=k+1;x0=xk;gk=grad(xk);res=norm(gk);fprintf('--The%d-thiter,theresidualis%f\n',k,res);endx_star=xk;end>>clear>>x0=[0,0]';>>eps=1e-4;>>x=steepest(x0,eps)2.牛頓法:functionf=fun(x)f=(1-x(1))^2+100*(x(2)-x(1)^2)^2;endfunctiong=grad2(x)g=zeros(2,2);g(1,1)=2+400*(3*x(1)^2-x(2));g(1,2)=-400*x(1);g(2,1)=-400*x(1);g(2,2)=200;endfunctiong=grad(x)g=zeros(2,1);g(1)=2*(x(1)-1)+400*x(1)*(x(1)^2-x(2));g(2)=200*(x(2)-x(1)^2);endfunctionx_star=newton(x0,eps)gk=grad(x0);bk=[grad2(x0)]^(-1);res=norm(gk);k=0;whileres>eps&&k<=1000dk=-bk*gk;xk=x0+dk;k=k+1;x0=xk;gk=grad(xk);bk=[grad2(xk)]^(-1);res=norm(gk);fprintf('--The%d-thiter,theresidualis%f\n',k,res);endx_star=xk;end>>clear>>x0=[0,0]';>>eps=1e-4;>>x1=newton(x0,eps)--The1-thiter,theresidualis447.213595--The2-thiter,theresidualis0.000000x1=1.00001.00003.BFGS法:functionf=fun(x)f=(1-x(1))^2+100*(x(2)-x(1)^2)^2;endfunctiong=grad(x)g=zeros(2,1);g(1)=2*(x(1)-1)+400*x(1)*(x(1)^2-x(2));g(2)=200*(x(2)-x(1)^2);endfunctionx_star=bfgs(x0,eps)g0=grad(x0);gk=g0;res=norm(gk);Hk=eye(2);k=0;whileres>eps&&k<=1000dk=-Hk*gk;ak=1;f0=fun(x0);f1=fun(x0+ak*dk);slope=dot(gk,dk);whilef1>f0+0.1*ak*slopeak=ak/4;xk=x0+ak*dk;f1=fun(xk);endk=k+1;fa0=xk-x0;x0=xk;go=gk;gk=grad(xk);y0=gk-g0;Hk=((eye(2)-fa0*(y0)')/((fa0)'*(y0)))*((eye(2)-(y0)*(fa0)')/((fa0)'*(y0)))+(fa0*(fa0)')/((fa0)'*(y0));res=norm(gk);fprintf('--The%d-thiter,theresidualis%f\n',k,res);endx_star=xk;End>>clear>>x0=[0,0]';>>eps=1e-4;>>x=bfgs(x0,eps)4.共軛梯度法:functionf=fun(x)f=(1-x(1))^2+100*(x(2)-x(1)^2)^2;endfunctiong=grad(x)g=zeros(2,1);g(1)=2*(x(1)-1)+400*x(1)*(x(1)^2-x(2));g(2)=200*(x(2)-x(1)^2);endfunctionx_star=CG(x0,eps)gk=grad(x0);res=norm(gk);k=0;dk=-gk;whileres>eps&&k<=1000ak=1;f0=fun(x0);f1=fun(x0+ak*dk);slope=dot(gk,dk);whilef1>f0+0.1*ak*slopeak=ak/4;xk=x0+ak*dk;f1=fun(xk);endk=k+1;x0=xk;g0=gk;gk=grad(xk);res=norm(gk);p=(gk/g0)^2;dk1=dk;dk=-gk+p*dk1;fprintf('--The%d-thiter,theresidualis%f\n',k,res);endx_star=xk;end>>clear>>x0=[0,0]';>>eps=1e-4;>>x=CG(x0,eps)上機(jī)大作業(yè)2:functionf=obj(x)f=4*x(1)-x(2)^2-12;endfunction[h,g]=constrains(x)h=x(1)^2+x(2)^2-25;g=zeros(3,1);g(1)=-10*x(1)+x(1)^2-10*x(2)+x(2)^2+34;g(2)=-x(1);g(3)=-x(2);endfunctionf=alobj(x)%拉格朗日增廣函數(shù)%N_equ等式約束個(gè)數(shù)?%N_inequ不等式約束個(gè)數(shù)N_equ=1;N_inequ=3;globalr_alpena;%全局變量h_equ=0;h_inequ=0;[h,g]=constrains(x);%等式約束部分?fori=1:N_equh_equ=h_equ+h(i)*r_al(i)+(pena/2)*h(i).^2;end%不等式約束部分fori=1:N_inequh_inequ=h_inequ+(0.5/pena)*(max(0,(r_al(i)+pena*g(i))).^2-r_al(i).^2);end%拉格朗日增廣函數(shù)值f=obj(x)+h_equ+h_inequ;functionf=compare(x)globalr_alpenaN_equN_inequ;N_equ=1;N_inequ=3;h_inequ=zeros(3,1);[h,g]=constrains(x);%等式部分fori=1:1h_equ=abs(h(i));end%不等式部分fori=1:3h_inequ=abs(max(g(i),-r_al(i+1)/pena));endh1=max(h_inequ);f=max(abs(h_equ),h1);%sqrt(h_equ+h_inequ);function[x,fmin,k]=almain(x_al)%本程序?yàn)槔窭嗜粘俗铀惴ㄊ纠惴?函數(shù)輸入:%x_al:初始迭代點(diǎn)%r_al:初始拉格朗日乘子N-equ:等式約束個(gè)數(shù)N_inequ:不等式約束個(gè)數(shù)?%函數(shù)輸出%X:最優(yōu)函數(shù)點(diǎn)FVAL:最優(yōu)函數(shù)值%============================程序開始================================globalr_alpena;%參數(shù)(全局變量)pena=10;%懲罰系數(shù)r_al=[1,1,1,1];c_scale=2;%乘法系數(shù)乘數(shù)cta=0.5;%下降標(biāo)準(zhǔn)系數(shù)e_al=1e-4;%誤差控制范圍max_itera=25;out_itera=1;%迭代次數(shù)%===========================算法迭代開始=============================whileout_itera<max_iterax_al0=x_al;r_al0=r_al;%判斷函數(shù)?compareFlag=compare(x_al0);%無約束的擬牛頓法BFGS[X,fmin]=fminunc(@alobj,x_al0);x_al=X;%得到新迭代點(diǎn)%判斷停止條件?ifcompare(x_al)<e_aldisp('wegettheoptpoint');breakend%c判斷函數(shù)下降度?ifcompare(x_al)<cta*compareFlagpena=1*pena;%可以根據(jù)需要修改懲罰系數(shù)變量elsepena=min(1000,c_scale*pena);%%乘法系數(shù)最大1000disp('pena=2*pena');end%%?更新拉格朗日乘子[h,g]=constrains(x_al);fori=1:1%%等式約束部分r_al(i)=r_al0(i)+pena*h(i);endfori=1:3%%不等式約束部分r_al(i+1)=max(0,(r_al0(i+1)+pena*g(i)));endout_itera=out_itera+1;end%+++++++++++++++++++++++++++迭代結(jié)束+++++++++++++++++++++++++++++++++disp('theiterationnumber');k=out_itera;disp('thevalueofconstrains');compare(x_al)disp('theoptpoint');x=x_al;fmin=obj(X);>>clear>>x_al=[0,0];>>[x,fmin,k]=almain(x_al)上機(jī)大作業(yè)3:1、>>clearalln=3;c=[-3,-1,-3]';A=[2,1,1;1,2,3;2,2,1;-1,0,0;0,-1,0;0,0,-1];b=[2,5,6,0,0,0]';cvx_beginvariablex(n)minimize(c'*x)subjecttoA*x<=bcvx_endCallingSDPT34.0:6variables,3equalityconstraints------------------------------------------------------------num.ofconstraints=3dim.oflinearvar=6*******************************************************************SDPT3:Infeasiblepath-followingalgorithms*******************************************************************versionpredcorrgamexponscale_dataNT10.00010itpstepdsteppinfeasdinfeasgapprim-objdual-objcputime-------------------------------------------------------------------0|0.000|0.000|1.1e+01|5.1e+00|6.0e+02|-7.000000e+010.000000e+00|0:0:00|chol111|0.912|1.000|9.4e-01|4.6e-02|6.5e+01|-5.606627e+00-2.967567e+01|0:0:01|chol112|1.000|1.000|1.3e-07|4.6e-03|8.5e+00|-2.723981e+00-1.113509e+01|0:0:01|chol113|1.000|0.961|2.3e-08|6.2e-04|1.8e+00|-4.348354e+00-6.122853e+00|0:0:01|chol114|0.881|1.000|2.2e-08|4.6e-05|3.7e-01|-5.255152e+00-5.622375e+00|0:0:01|chol115|0.995|0.962|1.6e-09|6.2e-06|1.5e-02|-5.394782e+00-5.409213e+00|0:0:01|chol116|0.989|0.989|2.7e-10|5.2e-07|1.7e-04|-5.399940e+00-5.400100e+00|0:0:01|chol117|0.989|0.989|5.3e-11|5.8e-09|1.8e-06|-5.399999e+00-5.400001e+00|0:0:01|chol118|1.000|0.994|2.8e-13|4.3e-11|2.7e-08|-5.400000e+00-5.400000e+00|0:0:01|stop:max(relativegap,infeasibilities)<1.49e-08-------------------------------------------------------------------numberofiterations=8primalobjectivevalue=-5.39999999e+00dualobjectivevalue=-5.40000002e+00gap:=trace(XZ)=2.66e-08relativegap=2.26e-09actualrelativegap=2.21e-09rel.primalinfeas(scaledproblem)=2.77e-13rel.dual"""=4.31e-11rel.primalinfeas(unscaledproblem)=0.00e+00rel.dual"""=0.00e+00norm(X),norm(y),norm(Z)=4.3e+00,1.3e+00,1.9e+00norm(A),norm(b),norm(C)=6.7e+00,9.1e+00,5.4e+00TotalCPUtime(secs)=0.71CPUtimeperiteration=0.09terminationcode=0DIMACS:3.6e-130.0e+005.8e-110.0e+002.2e-092.3e-09-------------------------------------------------------------------------------------------------------------------------------Status:SolvedOptimalvalue(cvx_optval):-5.42、>>clearalln=2;c=[-2,-4]';G=[0.5,0;0,1];A=[1,1;-1,0;0,-1];b=[1,0,0]';cvx_beginvariablex(n)minimize(x'*G*x+c'*x)subjecttoA*x<=bcvx_endCallingSDPT34.0:7variables,3equalityconstraintsForimprovedefficiency,SDPT3issolvingthedualproblem.------------------------------------------------------------num.ofconstraints=3dim.ofsocpvar=4,num.ofsocpblk=1dim.oflinearvar=3*******************************************************************SDPT3:Infeasiblepath-followingalgorithms*******************************************************************versionpredcorrgamexponscale_dataNT10.00010itpstepdsteppinfeasdinfeasgapprim-objdual-objcputime-------------------------------------------------------------------0|0.000|0.000|8.0e-01|6.5e+00|3.1e+02|1.000000e+010.000000e+00|0:0:00|chol111|1.000|0.987|4.3e-07|1.5e-01|1.6e+01|9.043148e+00-2.714056e-01|0:0:00|chol112|1.000|1.000|2.6e-07|7.6e-03|1.4e+00|1.234938e+00-5.011630e-02|0:0:00|chol113|1.000|1.000|2.4e-07|7.6e-04|3.0e-01|4.166959e-011.181563e-01|0:0:00|chol114|0.892|0.877|6.4e-08|1.6e-04|5.2e-02|2.773022e-012.265122e-01|0:0:00|chol115|1.000|1.000|1.0e-08|7.6e-06|1.5e-02|2.579468e-012.427203e-01|0:0:00|chol116|0.905|0.904|3.1e-09|1.4e-06|2.3e-03|2.511936e-012.488619e-01|0:0:00|chol117|1.000|1.000|6.1e-09|7.7e-08|6.6e-04|2.503336e-012.496718e-01|0:0:00|chol118|0.903|0.903|1.8e-09|1.5e-08|1.0e-04|2.500507e-012.499497e-01|0:0:00|chol119|1.000|1.000|4.9e-10|3.5e-10|2.9e-05|2.500143e-012.499857e-01|0:0:00|chol1110|0.904|0.904|4.7e-11|1.3e-10|4.4e-06|2.500022e-012.499978e-01|0:0:00|chol2211|1.000|1.000|2.3e-12|9.4e-12|1.2e-06|2.500006e-012.499994e-01|0:0:00|chol2212|1.000|1.000|4.7e-13|1.0e-12|1.8e-07|2.500001e-012.499999e-01|0:0:00|chol2213|1.000|1.000|2.0e-12|1.0e-12|4.2e-08|2.500000e-012.5000
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 物理科技在智能交通系統(tǒng)中的應(yīng)用
- 現(xiàn)代藝術(shù)與設(shè)計(jì)趨勢創(chuàng)新與變革
- 現(xiàn)代營銷中的用戶體驗(yàn)設(shè)計(jì)
- 環(huán)境科學(xué)與未來綠色發(fā)展的結(jié)合策略
- 國慶節(jié)紅色電影活動(dòng)方案
- Unit7《Lesson 26 I Love My Family》(說課稿)-2024-2025學(xué)年北京版(2024)英語三年級上冊
- 2024-2025學(xué)年高中地理 第4章 旅游與區(qū)域的發(fā)展 章末分層突破說課稿 中圖版選修3
- Unit 7 Happy Birthday!(說課稿)-2024-2025學(xué)年譯林版(三起)(2024)英語三年級上冊
- 2024年屆九年級歷史上冊 第11課 開辟新時(shí)代的“宣言”說課稿2 北師大版001
- 《18 初始機(jī)器人》說課稿-2023-2024學(xué)年清華版(2012)信息技術(shù)一年級下冊
- 醫(yī)院消防安全培訓(xùn)課件
- 質(zhì)保管理制度
- 《00541語言學(xué)概論》自考復(fù)習(xí)題庫(含答案)
- 2025年機(jī)關(guān)工會(huì)個(gè)人工作計(jì)劃
- 人事測評理論與方法-課件
- 最新卷宗的整理、裝訂(全)課件
- 城市旅行珠海景色介紹珠海旅游攻略PPT圖文課件
- 小學(xué) 三年級 科學(xué)《觀測風(fēng)》教學(xué)設(shè)計(jì)
- JJF1664-2017溫度顯示儀校準(zhǔn)規(guī)范-(高清現(xiàn)行)
- 第二講共振理論、有機(jī)酸堿理論
- 高考英語聽力必備場景詞匯精選(必看)
評論
0/150
提交評論