



免费预览已结束,剩余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-2030工业机器人应用领域拓展与技术升级研究报告
- 2025-2030工业无人机巡检算法优化与精准度提升分析报告
- 2025-2030工业废水零排放技术路线经济性对比分析报告
- 2025-2030工业大数据应用市场格局及投资风险评估报告
- 安全污染培训心得体会课件
- 申请书怎么想
- 学校编辑部申请书
- 濮阳县消防安全培训课件
- 西藏公积金申请书
- 2025广西公需科目真题续集(附答案)
- T/CECS 10214-2022钢面镁质复合风管
- 学校“1530”安全教育记录表(2024年秋季全学期)
- 公路工程标准施工招标文件(2018年版)
- DL∕T 5776-2018 水平定向钻敷设电力管线技术规定
- (正式版)SH∕T 3548-2024 石油化工涂料防腐蚀工程施工及验收规范
- 第十四章 环合反应天津大学
- 有机化学汪小兰 知识点总结 315化学
- 水土保持工程概(估)算编制规定(水利部水总[2003]67号)
- 串谐说明书概要
- 蒙牛渠道梳理之通路划分(最新)
评论
0/150
提交评论