132 lines
5.7 KiB
HTML
132 lines
5.7 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||
|
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Description of lnsrch</title>
|
||
|
<meta name="keywords" content="lnsrch">
|
||
|
<meta name="description" content="Copyright (C) 2001 Michel Juillard">
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||
|
<meta name="generator" content="m2html © 2003 Guillaume Flandin">
|
||
|
<meta name="robots" content="index, follow">
|
||
|
<link type="text/css" rel="stylesheet" href="../m2html.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<a name="_top"></a>
|
||
|
<div><a href="../index.html">Home</a> > <a href="index.html">.</a> > lnsrch.m</div>
|
||
|
|
||
|
<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td>
|
||
|
<td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
|
||
|
|
||
|
<h1>lnsrch
|
||
|
</h1>
|
||
|
|
||
|
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
||
|
<div class="box"><strong>Copyright (C) 2001 Michel Juillard</strong></div>
|
||
|
|
||
|
<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
||
|
<div class="box"><strong>function [x,f,fvec,check]=lnsrch(xold,fold,g,p,stpmax,func,varargin) </strong></div>
|
||
|
|
||
|
<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
||
|
<div class="fragment"><pre class="comment"> Copyright (C) 2001 Michel Juillard</pre></div>
|
||
|
|
||
|
<!-- crossreference -->
|
||
|
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
||
|
This function calls:
|
||
|
<ul style="list-style-image:url(../matlabicon.gif)">
|
||
|
<li><a href="check.html" class="code" title="function result = check">check</a> Copyright (C) 2001 Michel Juillard</li></ul>
|
||
|
This function is called by:
|
||
|
<ul style="list-style-image:url(../matlabicon.gif)">
|
||
|
</ul>
|
||
|
<!-- crossreference -->
|
||
|
|
||
|
|
||
|
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
||
|
<div class="fragment"><pre>0001 <span class="comment">% Copyright (C) 2001 Michel Juillard</span>
|
||
|
0002 <span class="comment">%</span>
|
||
|
0003 <a name="_sub0" href="#_subfunctions" class="code">function [x,f,fvec,check]=lnsrch(xold,fold,g,p,stpmax,func,varargin)</a>
|
||
|
0004
|
||
|
0005 alf = 1e-4 ;
|
||
|
0006 tolx = 3.7e-11 ;
|
||
|
0007 alam = 1;
|
||
|
0008
|
||
|
0009 nn = size(xold,1) ;
|
||
|
0010 summ = sqrt(sum(p.*p)) ;
|
||
|
0011 <span class="keyword">if</span> ~isfinite(summ)
|
||
|
0012 error([<span class="string">'Some element of Newton direction isn''t finite. Jacobian maybe'</span> <span class="keyword">...</span>
|
||
|
0013 <span class="string">' singular or there is a problem with initial values'</span>])
|
||
|
0014 <span class="keyword">end</span>
|
||
|
0015
|
||
|
0016 <span class="keyword">if</span> summ > stpmax
|
||
|
0017 p=p.*stpmax/summ ;
|
||
|
0018 <span class="keyword">end</span>
|
||
|
0019
|
||
|
0020 slope = g'*p ;
|
||
|
0021
|
||
|
0022 test = max(abs(p)'./max([abs(xold)';ones(1,nn)])) ;
|
||
|
0023 alamin = tolx/test ;
|
||
|
0024
|
||
|
0025 <span class="keyword">if</span> alamin > 0.1
|
||
|
0026 alamin = 0.1;
|
||
|
0027 <span class="keyword">end</span>
|
||
|
0028
|
||
|
0029 <span class="keyword">while</span> 1
|
||
|
0030 <span class="keyword">if</span> alam < alamin
|
||
|
0031 <a href="check.html" class="code" title="function result = check">check</a> = 1 ;
|
||
|
0032 <span class="keyword">return</span>
|
||
|
0033 <span class="keyword">end</span>
|
||
|
0034
|
||
|
0035 x = xold + (alam*p) ;
|
||
|
0036 fvec = feval(func,x,varargin{:}) ;
|
||
|
0037 f = 0.5*fvec'*fvec ;
|
||
|
0038
|
||
|
0039 <span class="keyword">if</span> any(isnan(fvec))
|
||
|
0040 alam = alam/2 ;
|
||
|
0041 alam2 = alam ;
|
||
|
0042 f2 = f ;
|
||
|
0043 fold2 = fold ;
|
||
|
0044 <span class="keyword">else</span>
|
||
|
0045
|
||
|
0046 <span class="keyword">if</span> f <= fold+alf*alam*slope
|
||
|
0047 <a href="check.html" class="code" title="function result = check">check</a> = 0;
|
||
|
0048 <span class="keyword">break</span> ;
|
||
|
0049 <span class="keyword">else</span>
|
||
|
0050 <span class="keyword">if</span> alam == 1
|
||
|
0051 tmplam = -slope/(2*(f-fold-slope)) ;
|
||
|
0052 <span class="keyword">else</span>
|
||
|
0053 rhs1 = f-fold-alam*slope ;
|
||
|
0054 rhs2 = f2-fold2-alam2*slope ;
|
||
|
0055 a = (rhs1/(alam^2)-rhs2/(alam2^2))/(alam-alam2) ;
|
||
|
0056 b = (-alam2*rhs1/(alam^2)+alam*rhs2/(alam2^2))/(alam-alam2) ;
|
||
|
0057 <span class="keyword">if</span> a == 0
|
||
|
0058 tmplam = -slope/(2*b) ;
|
||
|
0059 <span class="keyword">else</span>
|
||
|
0060 disc = (b^2)-3*a*slope ;
|
||
|
0061
|
||
|
0062 <span class="keyword">if</span> disc < 0
|
||
|
0063 error (<span class="string">'Roundoff problem in nlsearch'</span>) ;
|
||
|
0064 <span class="keyword">else</span>
|
||
|
0065 tmplam = (-b+sqrt(disc))/(3*a) ;
|
||
|
0066 <span class="keyword">end</span>
|
||
|
0067
|
||
|
0068 <span class="keyword">end</span>
|
||
|
0069
|
||
|
0070 <span class="keyword">if</span> tmplam > 0.5*alam
|
||
|
0071 tmplam = 0.5*alam;
|
||
|
0072 <span class="keyword">end</span>
|
||
|
0073
|
||
|
0074 <span class="keyword">end</span>
|
||
|
0075
|
||
|
0076 alam2 = alam ;
|
||
|
0077 f2 = f ;
|
||
|
0078 fold2 = fold ;
|
||
|
0079 alam = max([tmplam;(0.1*alam)]) ;
|
||
|
0080 <span class="keyword">end</span>
|
||
|
0081 <span class="keyword">end</span>
|
||
|
0082 <span class="keyword">end</span>
|
||
|
0083
|
||
|
0084 <span class="comment">% 01/14/01 MJ lnsearch is now a separate function</span>
|
||
|
0085 <span class="comment">% 01/12/03 MJ check for finite summ to avoid infinite loop when Jacobian</span>
|
||
|
0086 <span class="comment">% is singular or model is denormalized</span></pre></div>
|
||
|
<hr><address>Generated on Fri 16-Jun-2006 09:09:06 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address>
|
||
|
</body>
|
||
|
</html>
|