matlab lsqnonlin fsolve的区别

看看fsolve的源代码:
>> type fsolve
function [x,FVAL,EXITFLAG,OUTPUT,JACOB] = fsolve(FUN,x,options,varargin)
%FSOLVE solves systems of nonlinear equations of several variables.
%
% FSOLVE attempts to solve equations of the form:
%
% F(X)=0 where F and X may be vectors or matrices.
%
% X=FSOLVE(FUN,X0) starts at the matrix X0 and tries to solve the
% equations in FUN. FUN accepts input X and returns a vector (matrix) of
% equation values F evaluated at X.
%
% X=FSOLVE(FUN,X0,OPTIONS) solves the equations with the default optimization
% parameters replaced by values in the structure OPTIONS, an argument
% created with the OPTIMSET function. See OPTIMSET for details. Used
% options are Display, TolX, TolFun, DerivativeCheck, Diagnostics,
% FunValCheck, Jacobian, JacobMult, JacobPattern, LineSearchType,
% NonlEqnAlgorithm, MaxFunEvals, MaxIter, PlotFcns, OutputFcn,
% DiffMinChange and DiffMaxChange, LargeScale, MaxPCGIter,
% PrecondBandWidth, TolPCG, and TypicalX. Use the Jacobian option to
% specify that FUN also returns a second output argument J that is the
% Jacobian matrix at the point X. If FUN returns a vector F of m
% components when X has length n, then J is an m-by-n matrix where J(i,j)
% is the partial derivative of F(i) with respect to x(j). (Note that the
% Jacobian J is the transpose of the gradient of F.)
%
% X = FSOLVE(PROBLEM) solves system defined in PROBLEM. PROBLEM is a
% structure with the function FUN in PROBLEM.objective, the start point
% in PROBLEM.x0, the options structure in PROBLEM.options, and solver
% name 'fsolve' in PROBLEM.solver. Use this syntax to solve at the
% command line a problem exported from OPTIMTOOL. The structure PROBLEM
% must have all the fields.
%
% [X,FVAL]=FSOLVE(FUN,X0,...) returns the value of the equations FUN at X.
%
% [X,FVAL,EXITFLAG]=FSOLVE(FUN,X0,...) returns an EXITFLAG that describes the
% exit condition of FSOLVE. Possible values of EXITFLAG and the corresponding
% exit conditions are
%
% 1 FSOLVE converged to a solution X.
% 2 Change in X smaller than the specified tolerance.
% 3 Change in the residual smaller than the specified tolerance.
% 4 Magnitude of search direction smaller than the specified tolerance.
% 0 Maximum number of function evaluations or iterations reached.
% -1 Algorithm terminated by the output function.
% -2 Algorithm seems to be converging to a point that is not a root.
% -3 Trust region radius became too small.
% -4 Line search cannot sufficiently decrease the residual along the current
% search direction.
%
% [X,FVAL,EXITFLAG,OUTPUT]=FSOLVE(FUN,X0,...) returns a structure OUTPUT
% with the number of iterations taken in OUTPUT.iterations, the number of
% function evaluations in OUTPUT.funcCount, the algorithm used in OUTPUT.algorithm,
% the number of CG iterations (if used) in OUTPUT.cgiterations, the first-order
% optimality (if used) in OUTPUT.firstorderopt, and the exit message in
% OUTPUT.message.
%
% [X,FVAL,EXITFLAG,OUTPUT,JACOB]=FSOLVE(FUN,X0,...) returns the
% Jacobian of FUN at X.
%
% Examples
% FUN can be specified using @:
% x = fsolve(@myfun,[2 3 4],optimset('Display','iter'))
%
% where myfun is a MATLAB function such as:
%
% function F = myfun(x)
% F = sin(x);
%
% FUN can also be an anonymous function:
%
% x = fsolve(@(x) sin(3*x),[1 4],optimset('Display','off'))
%
% If FUN is parameterized, you can use anonymous functions to capture the
% problem-dependent parameters. Suppose you want to solve the system of
% nonlinear equations given in the function myfun, which is parameterized
% by its second argument c. Here myfun is an M-file function such as
%
% function F = myfun(x,c)
% F = [ 2*x(1) - x(2) - exp(c*x(1))
% -x(1) + 2*x(2) - exp(c*x(2))];
%
% To solve the system of equations for a specific value of c, first assign the
% value to c. Then create a one-argument anonymous function that captures
% that value of c and calls myfun with two arguments. Finally, pass this anonymous
% function to FSOLVE:
%
% c = -1; % define parameter first
% x = fsolve(@(x) myfun(x,c),[-5;-5])
%
% See also OPTIMSET, LSQNONLIN, @, INLINE.
% Copyright 1990-2006 The MathWorks, Inc.
% $Revision: 1.41.4.12 $ $Date: 2006/05/19 20:18:49 $
% ------------Initialization----------------
defaultopt = struct('Display','final','LargeScale','off',...
'NonlEqnAlgorithm','dogleg',...
'TolX',1e-6,'TolFun',1e-6,'DerivativeCheck','off',...
'Diagnostics','off','FunValCheck','off',...
'Jacobian','off','JacobMult',[],...% JacobMult set to [] by default
'JacobPattern','sparse(ones(Jrows,Jcols))',...
'MaxFunEvals','100*numberOfVariables',...
'DiffMaxChange',1e-1,'DiffMinChange',1e-8,...
'PrecondBandWidth',0,'TypicalX','ones(numberOfVariables,1)',...
'MaxPCGIter','max(1,floor(numberOfVariables/2))', ...
'TolPCG',0.1,'MaxIter',400,...
'LineSearchType','quadcubic','OutputFcn',[],'PlotFcns',[]);
% If just 'defaults' passed in, return the default options in X
if nargin==1 && nargout 0 % if we think we converged:
if Resnorm > sqrt(optimget(options,'TolFun',defaultopt,'fast'))
OUTPUT.message = ...
sprintf(['Optimizer appears to be converging to a minimum that is not a root:\n' ...
'Sum of squares of the function values is > sqrt(options.TolFun).\n' ...
'Try again with a new starting point.']);
if verbosity > 0
disp(OUTPUT.message)
end
EXITFLAG = -2;
else
OUTPUT.message = msg;
if verbosity > 0
disp(OUTPUT.message);
end
end
else
OUTPUT.message = msg;
if verbosity > 0
disp(OUTPUT.message);
end
end
% Reset FVAL to shape of the user-function output, fuser
FVAL = reshape(FVAL,size(fuser)); 收起
iudollco1360 2014-08-14
简单地说,matlab中fsolve语句数值效果较好,采用的解法是将方程组转化为最小二乘问题,调用指令lsqnonlin求解,所以,它参数的选取和优化指令的用法是一致的。
最优化,原理上说到底都是要从一个初值开始,选择搜索的方向与步长。参数的不同选取,使得算法出现不同。例如Levenberg-Marquardt如果选择'on',搜索方向就是用Levenberg-Marquardt法,如果选... 展开
风飘飘ks30 2014-08-14
简单地说,matlab中fsolve语句数值效果较好,采用的解法是将方程组转化为最小二乘问题,调用指令lsqnonlin求解,所以,它参数的选取和优化指令的用法是一致的。
最优化,原理上说到底都是要从一个初值开始,选择搜索的方向与步长。参数的不同选取,使得算法出现不同。例如Levenberg-Marquardt如果选择'on',搜索方向就是用Levenberg-Marquardt法,如果选择'off',搜索方向就是用Gauss-Newton法.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值