




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Broyden方法求解非线性方程组的Matlab实现 注:matlab代码来自网络,仅供学习参考。1. 把以下代码复制在一个.m文件上function sol, it_hist, ierr = brsola(x,f,tol, parms)% Broydens Method solver, globally convergent% solver for f(x) = 0, Armijo rule, one vector storage% This code comes with no guarantee or warranty of any kind.% function sol, it_hist, ierr = brsola(x,f,tol,parms)% inputs:% initial iterate = x% function = f% tol = atol, rtol relative/absolute% error tolerances for the nonlinear iteration% parms = maxit, maxdim% maxit = maxmium number of nonlinear iterations% default = 40% maxdim = maximum number of Broyden iterations% before restart, so maxdim-1 vectors are % stored% default = 40% output:% sol = solution% it_hist(maxit,3) = scaled l2 norms of nonlinear residuals% for the iteration, number function evaluations,% and number of steplength reductions% ierr = 0 upon successful termination% ierr = 1 if after maxit iterations% the termination criterion is not satsified.% ierr = 2 failure in the line search. The iteration% is terminated if too many steplength reductions% are taken.% internal parameter:% debug = turns on/off iteration statistics display as% the iteration progresses% alpha = 1.d-4, parameter to measure sufficient decrease% maxarm = 10, maximum number of steplength reductions before% failure is reported % set the debug parameter, 1 turns display on, otherwise off%debug=1;% initialize it_hist, ierr, and set the iteration parameters%ierr = 0; maxit=40; maxdim=39; it_histx=zeros(maxit,3);maxarm=10;%if nargin = 4 maxit=parms(1); maxdim=parms(2)-1; endrtol=tol(2); atol=tol(1); n = length(x); fnrm=1; itc=0; nbroy=0;% evaluate f at the initial iterate% compute the stop tolerance%f0=feval(f,x);fc=f0;fnrm=norm(f0)/sqrt(n);it_hist(itc+1)=fnrm;it_histx(itc+1,1)=fnrm; it_histx(itc+1,2)=0; it_histx(itc+1,3)=0;fnrmo=1;stop_tol=atol + rtol*fnrm;outstat(itc+1, :) = itc fnrm 0 0;% terminate on entry?%if fnrm stop_tol sol=x; returnend% initialize the iteration history storage matrices%stp=zeros(n,maxdim);stp_nrm=zeros(maxdim,1);lam_rec=ones(maxdim,1);% Set the initial step to -F, compute the step norm%lambda=1;stp(:,1) = -fc;stp_nrm(1)=stp(:,1)*stp(:,1);% main iteration loop%while(itc = (1 - lambda*alpha)*fnrmo & iarm maxarm% lambda=lambda*lrat; if iarm=0 lambda=lambda*lrat; else lambda=parab3p(lamc, lamm, ff0, ffc, ffm); end lamm=lamc; ffm=ffc; lamc=lambda; x = xold + lambda*stp(:,nbroy); fc=feval(f,x); fnrm=norm(fc)/sqrt(n); ffc=fnrm*fnrm; iarm=iarm+1; end% set error flag and return on failure of the line search% if iarm = maxarm disp(Line search failure in brsola ) ierr=2; it_hist=it_histx(1:itc+1,:); sol=xold; return; end% How many function evaluations did this iteration require?% it_histx(itc+1,1)=fnrm; it_histx(itc+1,2)=it_histx(itc,2)+iarm+1; if(itc = 1) it_histx(itc+1,2) = it_histx(itc+1,2)+1; end; it_histx(itc+1,3)=iarm;% terminate?% if fnrm stop_tol sol=x; rat=fnrm/fnrmo; outstat(itc+1, :) = itc fnrm iarm rat; it_hist=it_histx(1:itc+1,:);% it_hist(itc+1)=fnrm; if debug=1 disp(outstat(itc+1,:) end return end% modify the step and step norm if needed to reflect the line % search% lam_rec(nbroy)=lambda; if lambda = 1 stp(:,nbroy)=lambda*stp(:,nbroy); stp_nrm(nbroy)=lambda*lambda*stp_nrm(nbroy); end% it_hist(itc+1)=fnrm; rat=fnrm/fnrmo; outstat(itc+1, :) = itc fnrm iarm rat; if debug=1 disp(outstat(itc+1,:) end% if theres room, compute the next search direction and step norm and% add to the iteration history % if nbroy 1 for kbr = 1:nbroy-1 ztmp=stp(:,kbr+1)/lam_rec(kbr+1); ztmp=ztmp+(1 - 1/lam_rec(kbr)*stp(:,kbr); ztmp=ztmp*lam_rec(kbr); z=z+ztmp*(stp(:,kbr)*z)/stp_nrm(kbr); end end% store the new search direction and its norm% a2=-lam_rec(nbroy)/stp_nrm(nbroy); a1=1 - lam_rec(nbroy); zz=stp(:,nbroy)*z; a3=a1*zz/stp_nrm(nbroy); a4=1+a2*zz; stp(:,nbroy+1)=(z-a3*stp(:,nbroy)/a4; stp_nrm(nbroy+1)=stp(:,nbroy+1)*stp(:,nbroy+1);% else% out of room, time to restart% stp(:,1)=-fc; stp_nrm(1)=stp(:,1)*stp(:,1); nbroy=0;% end% end whileend% Were not supposed to be here, weve taken the maximum% number of iterations and not terminated.%sol=x;it_hist=it_histx(1:itc+1,:);ierr=1;if debug=1 disp( outstat)end function lambdap = parab3p(lambdac, lambdam, ff0, ffc, ffm)% Apply three-point safeguarded parabolic model for a line search.% This code comes with no guarantee or warranty of any kind.% function lambdap = parab3p(lambdac, lambdam, ff0, ffc, ffm)% input:% lambdac = current steplength% lambdam = previous steplength% ff0 = value of | F(x_c) |2% ffc = value of | F(x_c + lambdac d) |2% ffm = value of | F(x_c + lambdam d) |2% output:% lambdap = new value of lambda given parabolic model% internal parameters:% sigma0 = .1, sigma1=.5, safeguarding bounds for the linesearch% % set internal parameters%sigma0=.1; sigma1=.5;% compute coefficients of interpolation polynomial% p(lambda) = ff0 + (c1 lambda + c2 lambda2)/d1% d1 = (lambdac - lambdam)*lambdac*lambdam 0 we have negative curvature and default to% lambdap = sigam1 * lambda%c2 = lambdam*(ffc-ff0)-lambdac*(ffm-ff0);if c2 = 0 lambdap = sigma1*lambdac; returnendc1=lambdac*lambdac*(ffm-ff0)-lambdam*lambdam*(ffc-ff0);lambdap=-c1*.5/c2;if (lambdap sigma1*lambda
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 肿瘤护理中的有效沟通
- 直肠恶性肿瘤内科诊疗体系
- 全国中医护理骨干人才汇报
- 行政制度新人培训
- 开户云五期培训
- 护理标识管理规章制度
- 幼儿教师音乐乐理培训
- 木材采购保密及森林资源保护协议
- 车辆收费员招聘与管理服务协议
- 高端草莓采摘园与旅行社定制旅游合同范本
- 湖北省襄阳四中2024-2025学年高三下学期期末统一检测试题英语试题含解析
- 2025年中考地理模拟考试卷(附答案)
- 大学生全国创业服务网项目
- 演艺厅安全事故应急预案
- 国家开放大学行管本科《行政领导学》期末纸质考试总题库2025春期版
- 国家开放大学《课程与教学论》形考任务1-4参考答案
- 2025年学校意识形态工作总结范文(2篇)
- 2025年职业技能(工业废水处理工)专业技术及理论知识考试题及答案
- 电大国开2024秋《习近平新时代中国特色社会主义思想》学习行为表现(范文2篇)
- 《市场人员商务礼仪》课件
- 上海市市辖区(2024年-2025年小学六年级语文)统编版小升初真题(下学期)试卷及答案
评论
0/150
提交评论