全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
%最速下降梯度法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;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030粽子米饼行业市场供需分析及投资评估规划分析研究报告
- 2025-2030药品流通行业市场竞争研究及行业前景后市展望报告
- 2025-2030草莓霜市场现状研究品牌营销评估供求平衡发展策略规划报告
- 2025-2030茶叶行业政策分析及投资评估规划分析研究报告
- 2025-2030芬兰林业行业发展现状供需分析及投资评估规划分析研究报告
- 2025-2030翻译教育行业市场现状需求分析及投资评估服务质量规划分析研究报告
- 基于用户行为分析的AI教育平台用户粘性提升策略优化教学研究课题报告
- 吉林省白城四中2025-2026学年高中高三第二次教学质量检测试题物理试题试卷含解析
- 中班语言教案
- 中班语言教案12篇
- (2026年)中华护理学会团体标准2024针刺伤预防与处理课件
- 非煤矿山复工安全培训
- 护理核心制度实践指南
- 工厂安全生产三级培训课件
- 2025四川安吉物流集团有限公司下半年招聘工作人员11人(二)笔试历年参考题库附带答案详解
- 2026届广东省东莞市三校英语高三上期末学业质量监测模拟试题含解析
- 严厉的主奴协议书
- 2025年10月自考15040习概论试题及答案
- 医保管理制度、财务制度、统计信息管理制度、医疗质量安全核心制度
- 气道腔内球囊封堵治疗咯血专家共识(2025版)解读课件
- 2025年初级会计职称《经济法基础》精讲课件第1-4章
评论
0/150
提交评论