



免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电气线路管理办法
- 滩涂开发管理办法
- 电滋辐射管理办法
- 物资查缺管理办法
- 药品储存管理办法
- 物流小区管理办法
- 票务流通管理办法
- 离职管理办法模板
- 盈余分配管理办法
- 税收扣除管理办法
- GB/T 1665-2008增塑剂皂化值及酯含量的测定
- GB/T 12340-20081∶25 0001∶50 0001∶100 000地形图航空摄影测量内业规范
- GB 4789.15-2016食品安全国家标准食品微生物学检验霉菌和酵母计数
- GA 6-2004消防员灭火防护靴
- FZ/T 62033-2016超细纤维毛巾
- 风险分级管控措施清单(路基工程)
- 2023年上海宝建(集团)有限公司招聘笔试题库及答案解析
- 《概率论与数理统计》-教学教案
- 调机品管理规定
- 童年简谱-儿童经典歌曲-罗大佑
- 水泥砂浆找平施工工艺
评论
0/150
提交评论