免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
。%最速下降梯度法matlab程序% Steepest Descent Method% By Kshitij Deshpandeclcclear allwarning offprompt = Coeficients if X1=,Coefficients of X2=,Coefficeint of X1X2=,Initial Point=;def = 2 1 0,1 -1 0,2,0 0;a=inputdlg(prompt,Data,1,def);a=char(a);m,n=size(a);x1 = eval(a(1,1:n);x2=eval(a(2,1:n);x1x2=eval(a(3,1:n);X1=eval(a(4,1:n);delf1(1) = polyval(polyder(x1),X1(1);delf1(1) = (delf1(1)+(x1x2*X1(2);delf1(2) = polyval(polyder(x2),X1(1);delf1(2) = (delf1(2)+(x1x2*X1(1);s=-delf1;%reportsrep(1,1:2)=s;% x1new(1)=s(1)2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)2; x1new=x1new*x1(1); x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1); x1new = x1new+x1new_; x2new(1)=s(2)2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)2; x2new=x2new*x2(1); x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2); x2new = x2new+x2new_; x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2); x1x2new=x1x2*x1x2new; df = polyder(x1new+x2new+x1x2new); lambda(1) = roots(df); X1=X1+lambda(1)*s; Xrep(1,1:2)=X1; delf1(1) = polyval(polyder(x1),X1(1); delf1(1) = (delf1(1)+(x1x2*X1(2); delf1(2) = polyval(polyder(x2),X1(2); delf1(2) = (delf1(2)+(x1x2*X1(1);if all(X1)= 0 fprintf(%d %d is the optimum point,X1(1),X1(2);enditrep(1)=1;it=2;while all(delf1)=1 s=-delf1; x1new(1)=s(1)2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)2; x1new=x1new*x1(1); x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1); x1new = x1new+x1new_; x2new(1)=s(2)2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)2; x2new=x2new*x2(1); x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2); x2new = x2new+x2new_; x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2); x1x2new=x1x2*x1x2new; df = polyder(x1new+x2new+x1x2new); lambda(it) = roots(df); X1=X1+lambda(it)*s; delf1(1) = polyval(polyder(x1),X1(1); delf1(1) = (delf1(1)+(x1x2*X1(2); delf1(2) = polyval(polyder(x2),X1(2); delf1(2) = (delf1(2)+(x1x2*X1(1); itrep(it)=it; srep(it,1:2)=s; Xrep(it,1:2)=X1; it=it+1;endm,n=size(itrep);matrix=itrep srep(1:n,1) srep(1:n,2) Xrep(1:n,1) Xrep(1:n,2);answer = char(num2str(X1);answer = The optimal point is answer ;msgbox(answer,Solution);disp( Press Any key to View Detailed Report.);pauseecho offreport steep;clc -%最速下降法(爬山法)的一个matlab程序function y=steepest(x)%This program uses the steepest descent direction algorithm%to calculate the minimum of the function f(x)=x(1)2+2*x(2)2format longeps=input(please input your accuracy:);%eps is the demmanded accuracy on the norm of %the gradient of the objective functionm=1;%m is the count of the iteration step of the algorithmiterstep(1,:)=x;%iterstep contains the intermediate points of iterationwhile norm(gradobject1(x)eps grad=gradobject1(x); alpha=goldsplictobj(x); x=x-alpha*grad; iterstep(m+1,:)=x; m=m+1;endstep=max(size(iterstep)-1plot(iterstep(:,1),iterstep(:,2);%Draw the search trajectory title(The search trajectory of the Steepest dscent direction algorithm);xlabel(x1-axis);ylabel(x2-axis);text(x(1),x(2),The minimum point found by the algorithm);text(iterstep(1,1),iterstep(1,2),The initial point (2,1);gtext(The number of the total iteration steps of the algorithm is:);gtext(The set accuracy in advance is 1.0*10-10);%The following subfunction is on the objective functionfunction y=object1(v)y=v(1)2+2*v(2)2;%The following subfunction is on the gradient of%the objective functionfunction y=gradobject1(v)y(1)=2*v(1);y(2)=4*v(2);%The following subfunction is on the comming%search function of alphafunction y=substi(alpha,x)y=feval(object1,x-alpha*gradobject1(x);%The following subfunction is on the goldspliction%search of the substi functionfunction y=goldsplictobj(x)a=0;b=10;eps=0.01;y1=a+0.382*(b-a);y2=a+0.618*(b-a);while abs(b-a)eps if substi(y1,x)substi(y2,x) a=y1; b=b; y1=a+0.382*(b-a); y2=a+0.618*(b-a); elseif su
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 供销合同保密协议
- 货车分期买卖协议书
- 货车承包货运协议书
- 供销合同终止协议
- 代耕费结算协议书
- 货车销售转让协议书
- 贵金属供货协议合同
- 购置设备补助协议书
- 2025杭州桐庐县总工会招聘工会社会工作者2人备考题库附答案详解(培优a卷)
- 供销标准合同范本
- 【生物】生物进化的历程课件 2025-2026学年人教版生物八年级上册
- 菌类的营养与健康
- 停车场管理制度牌(3篇)
- 2025年胎儿胎心监护理论知识考试试题及答案
- 广东省多校联考2025-2026学年高二上学期12月考试语文试卷
- 2025江苏镇江市京口产业投资发展集团有限公司招聘2人备考题库含答案详解(综合题)
- 2025至2030中国意大利面行业市场深度研究与战略咨询分析报告
- 贵州国企招聘:2025贵州凉都能源有限责任公司招聘10人备考题库附答案详解(综合题)
- 糖尿病患者长期管理的心理疲劳与应对
- 老年患者意识状态分级及分级护理措施
- 第二单元-学习项目二世界民族音乐博览会(第二课时)核心素养教学设计人教版(简谱)初中音乐七年级上册
评论
0/150
提交评论