Matlab在求解优化问题中应用.ppt

x=lsqnonlin( fun,x0 ,LB,UB,options ) 功能:用 options 参数指定的优化参数进行最小化,其中, options 可取值为:Display,TolX,TolFun,Derivativecheck,Diagnostics,FunValCheck,Jacobian,JacobMult, JacobPattern, LineSearchType, LevenbergMarquadt, MaxFunEvals, MaxIter, DiffMinChange,以及DiffMaxChange, LargeScale, MaxPCGIter, PrecondBandWidth, TolPCG, TypicalX。 [x,resnorm]=lsqnonlin( fun,x0, … ) 功能: 返回解 x 处残差的平方范数:sum(fun(x).^2)。 [x,resnorm ,residual]= lsqnonlin( fun,x0, … ) 功能: 返回解 x 处残差值: residual =fun(x)。 [x,resnorm ,residual ,exitflag]= lsqnonlin ( fun,x0, …) 功能:返回解 x 处残差值: residual =fun(x)。另外,返回exitflag值,描述极小化函数的退出条件。 exitflag值 含义 1 函数收敛到目标函数最优解处 2 x的变化小于规定的容许范围 3 残差的变化小于规定的容许范围 4 重要搜索方向小于规定的容许范围 0 达到最大迭代次数或达到函数评价 -1 算法由输出函数终止 -2 下界大于上界 -4 当前搜索方向线搜索不能充分减少残差 exitflag值和相应的含义如下表所示: [x,resnorm ,residual ,exitflag ,output]= lsqnonlin ( fun,x0, … ) 功能:返回同上述格式的值。另外,返回包含output结构的输出。 output结构值 含义 output.iterations 迭代次数 output.funcCount 函数评价次数 output.algorithm 所用的算法 output.cgiterations 共轭梯度法的使用次数 output.firstorderopt 一阶最优性条件 output.message 跳出信息 output包含的内容和相应的含义如下表所示: [x,resnorm ,residual ,exitflag ,output,lambda]= lsqnonlin ( fun,x0, …) 功能: 返回lambda在解x处的结构参数,下界对应为: lambda.lower,上界对应为: lambda.upper。 [x,resnorm ,residual ,exitflag ,output,lambda ,Jacobian]= lsqnonlin ( fun,x0, …) 功能: 返回解x处的fun的Jacobian矩阵。 函数fun的调用方式有多种,可以是函数文件,也可以是类似于C++语言中的调用格式。 例18 求函数 f =sin(x) 的最小二乘问题。 x=lsqnonlin(@(x) sin(x),[2 3 4]) Optimization terminated: first-order optimality less than OPTIONS.TolFun, and no negative/zero curvature detected in trust region model. x = 3.1416 3.1416 3.1416 方法二:直接在命令窗口中输入: function f=ex18(x) %This is a function for demonstration f=sin(x); 方法一:先编辑如下 M 文件 ex18.m,再调用该函数: x=lsqnonlin(@ex18,[2 3 4]) 或 x=lsqnonlin(ex18,[2 3 4]) 结果同上 例19 求解函数 的最小二乘问题。 function f=ex19(x,a) f=[2*x(1)-exp(a*x(1)) -x(1)-exp(a*x(2)) x(1)-x(2)]; 先编辑如下 M 文件 ex19.m

文档评论(0)

1亿VIP精品文档

相关文档