337 lines
22 KiB
HTML
337 lines
22 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 csminwel</title>
|
|
<meta name="keywords" content="csminwel">
|
|
<meta name="description" content="[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit,varargin)">
|
|
<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> > csminwel.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>csminwel
|
|
</h1>
|
|
|
|
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
<div class="box"><strong>[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit,varargin)</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 [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit,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">[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit,varargin)
|
|
fcn: string naming the objective function to be minimized
|
|
x0: initial value of the parameter vector
|
|
H0: initial value for the inverse Hessian. Must be positive definite.
|
|
grad: Either a string naming a function that calculates the gradient, or the null matrix.
|
|
If it's null, the program calculates a numerical gradient. In this case fcn must
|
|
be written so that it can take a matrix argument and produce a row vector of values.
|
|
crit: Convergence criterion. Iteration will cease when it proves impossible to improve the
|
|
function value by more than crit.
|
|
nit: Maximum number of iterations.
|
|
varargin: A list of optional length of additional parameters that get handed off to fcn each
|
|
time it is called.
|
|
Note that if the program ends abnormally, it is possible to retrieve the current x,
|
|
f, and H from the files g1.mat and H.mat that are written at each iteration and at each
|
|
hessian update, respectively. (When the routine hits certain kinds of difficulty, it
|
|
write g2.mat and g3.mat as well. If all were written at about the same time, any of them
|
|
may be a decent starting point. One can also start from the one with best function value.)</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="bfgsi.html" class="code" title="function H = bfgsi(H0,dg,dx)">bfgsi</a> H = bfgsi(H0,dg,dx)</li><li><a href="csminit.html" class="code" title="function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin)">csminit</a> [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,...</li><li><a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a> function [g badg] = numgrad(fcn,xvarargin)</li></ul>
|
|
This function is called by:
|
|
<ul style="list-style-image:url(../matlabicon.gif)">
|
|
<li><a href="dynare_estimation.html" class="code" title="function dynare_estimation(var_list_)">dynare_estimation</a> </li></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 <a name="_sub0" href="#_subfunctions" class="code">function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(fcn,x0,H0,grad,crit,nit,varargin)</a>
|
|
0002 <span class="comment">%[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel(fcn,x0,H0,grad,crit,nit,varargin)</span>
|
|
0003 <span class="comment">% fcn: string naming the objective function to be minimized</span>
|
|
0004 <span class="comment">% x0: initial value of the parameter vector</span>
|
|
0005 <span class="comment">% H0: initial value for the inverse Hessian. Must be positive definite.</span>
|
|
0006 <span class="comment">% grad: Either a string naming a function that calculates the gradient, or the null matrix.</span>
|
|
0007 <span class="comment">% If it's null, the program calculates a numerical gradient. In this case fcn must</span>
|
|
0008 <span class="comment">% be written so that it can take a matrix argument and produce a row vector of values.</span>
|
|
0009 <span class="comment">% crit: Convergence criterion. Iteration will cease when it proves impossible to improve the</span>
|
|
0010 <span class="comment">% function value by more than crit.</span>
|
|
0011 <span class="comment">% nit: Maximum number of iterations.</span>
|
|
0012 <span class="comment">% varargin: A list of optional length of additional parameters that get handed off to fcn each</span>
|
|
0013 <span class="comment">% time it is called.</span>
|
|
0014 <span class="comment">% Note that if the program ends abnormally, it is possible to retrieve the current x,</span>
|
|
0015 <span class="comment">% f, and H from the files g1.mat and H.mat that are written at each iteration and at each</span>
|
|
0016 <span class="comment">% hessian update, respectively. (When the routine hits certain kinds of difficulty, it</span>
|
|
0017 <span class="comment">% write g2.mat and g3.mat as well. If all were written at about the same time, any of them</span>
|
|
0018 <span class="comment">% may be a decent starting point. One can also start from the one with best function value.)</span>
|
|
0019 <span class="keyword">global</span> bayestopt_
|
|
0020 [nx,no]=size(x0);
|
|
0021 nx=max(nx,no);
|
|
0022 Verbose=1;
|
|
0023 NumGrad= isempty(grad);
|
|
0024 done=0;
|
|
0025 itct=0;
|
|
0026 fcount=0;
|
|
0027 snit=100;
|
|
0028 <span class="comment">%tailstr = ')';</span>
|
|
0029 <span class="comment">%stailstr = [];</span>
|
|
0030 <span class="comment">% Lines below make the number of Pi's optional. This is inefficient, though, and precludes</span>
|
|
0031 <span class="comment">% use of the matlab compiler. Without them, we use feval and the number of Pi's must be</span>
|
|
0032 <span class="comment">% changed with the editor for each application. Places where this is required are marked</span>
|
|
0033 <span class="comment">% with ARGLIST comments</span>
|
|
0034 <span class="comment">%for i=nargin-6:-1:1</span>
|
|
0035 <span class="comment">% tailstr=[ ',P' num2str(i) tailstr];</span>
|
|
0036 <span class="comment">% stailstr=[' P' num2str(i) stailstr];</span>
|
|
0037 <span class="comment">%end</span>
|
|
0038 f0 = feval(fcn,x0,varargin{:});
|
|
0039 <span class="comment">%ARGLIST</span>
|
|
0040 <span class="comment">%f0 = feval(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13);</span>
|
|
0041 <span class="comment">% disp('first fcn in csminwel.m ----------------') % Jinill on 9/5/95</span>
|
|
0042 <span class="keyword">if</span> f0 > 1e50, disp(<span class="string">'Bad initial parameter.'</span>), <span class="keyword">return</span>, <span class="keyword">end</span>
|
|
0043 <span class="keyword">if</span> NumGrad
|
|
0044 <span class="keyword">if</span> length(grad)==0
|
|
0045 [g badg] = <a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a>(fcn,x0, varargin{:});
|
|
0046 <span class="comment">%ARGLIST</span>
|
|
0047 <span class="comment">%[g badg] = numgrad(fcn,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13);</span>
|
|
0048 <span class="keyword">else</span>
|
|
0049 badg=any(find(grad==0));
|
|
0050 g=grad;
|
|
0051 <span class="keyword">end</span>
|
|
0052 <span class="comment">%numgrad(fcn,x0,P1,P2,P3,P4);</span>
|
|
0053 <span class="keyword">else</span>
|
|
0054 [g badg] = feval(grad,x0,varargin{:});
|
|
0055 <span class="comment">%ARGLIST</span>
|
|
0056 <span class="comment">%[g badg] = feval(grad,x0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13);</span>
|
|
0057 <span class="keyword">end</span>
|
|
0058 retcode3=101;
|
|
0059 x=x0;
|
|
0060 f=f0;
|
|
0061 H=H0;
|
|
0062 cliff=0;
|
|
0063 <span class="keyword">while</span> ~done
|
|
0064 bayestopt_.penalty = f;
|
|
0065 g1=[]; g2=[]; g3=[];
|
|
0066 <span class="comment">%addition fj. 7/6/94 for control</span>
|
|
0067 disp(<span class="string">'-----------------'</span>)
|
|
0068 disp(<span class="string">'-----------------'</span>)
|
|
0069 <span class="comment">%disp('f and x at the beginning of new iteration')</span>
|
|
0070 disp(sprintf(<span class="string">'f at the beginning of new iteration, %20.10f'</span>,f))
|
|
0071 <span class="comment">%-----------Comment out this line if the x vector is long----------------</span>
|
|
0072 <span class="comment">% disp([sprintf('x = ') sprintf('%15.8g %15.8g %15.8g %15.8g\n',x)]);</span>
|
|
0073 <span class="comment">%-------------------------</span>
|
|
0074 itct=itct+1;
|
|
0075 [f1 x1 fc retcode1] = <a href="csminit.html" class="code" title="function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin)">csminit</a>(fcn,x,f,g,badg,H,varargin{:});
|
|
0076 <span class="comment">%ARGLIST</span>
|
|
0077 <span class="comment">%[f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,P1,P2,P3,P4,P5,P6,P7,...</span>
|
|
0078 <span class="comment">% P8,P9,P10,P11,P12,P13);</span>
|
|
0079 <span class="comment">% itct=itct+1;</span>
|
|
0080 fcount = fcount+fc;
|
|
0081 <span class="comment">% erased on 8/4/94</span>
|
|
0082 <span class="comment">% if (retcode == 1) | (abs(f1-f) < crit)</span>
|
|
0083 <span class="comment">% done=1;</span>
|
|
0084 <span class="comment">% end</span>
|
|
0085 <span class="comment">% if itct > nit</span>
|
|
0086 <span class="comment">% done = 1;</span>
|
|
0087 <span class="comment">% retcode = -retcode;</span>
|
|
0088 <span class="comment">% end</span>
|
|
0089 <span class="keyword">if</span> retcode1 ~= 1
|
|
0090 <span class="keyword">if</span> retcode1==2 | retcode1==4
|
|
0091 wall1=1; badg1=1;
|
|
0092 <span class="keyword">else</span>
|
|
0093 <span class="keyword">if</span> NumGrad
|
|
0094 [g1 badg1] = <a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a>(fcn, x1,varargin{:});
|
|
0095 <span class="comment">%ARGLIST</span>
|
|
0096 <span class="comment">%[g1 badg1] = numgrad(fcn, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,...</span>
|
|
0097 <span class="comment">% P10,P11,P12,P13);</span>
|
|
0098 <span class="keyword">else</span>
|
|
0099 [g1 badg1] = feval(grad,x1,varargin{:});
|
|
0100 <span class="comment">%ARGLIST</span>
|
|
0101 <span class="comment">%[g1 badg1] = feval(grad, x1,P1,P2,P3,P4,P5,P6,P7,P8,P9,...</span>
|
|
0102 <span class="comment">% P10,P11,P12,P13);</span>
|
|
0103 <span class="keyword">end</span>
|
|
0104 wall1=badg1;
|
|
0105 <span class="comment">% g1</span>
|
|
0106 save g1 g1 x1 f1 varargin;
|
|
0107 <span class="comment">%ARGLIST</span>
|
|
0108 <span class="comment">%save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13;</span>
|
|
0109 <span class="keyword">end</span>
|
|
0110 <span class="keyword">if</span> wall1 <span class="comment">% & (~done) by Jinill</span>
|
|
0111 <span class="comment">% Bad gradient or back and forth on step length. Possibly at</span>
|
|
0112 <span class="comment">% cliff edge. Try perturbing search direction.</span>
|
|
0113 <span class="comment">%</span>
|
|
0114 <span class="comment">%fcliff=fh;xcliff=xh;</span>
|
|
0115 Hcliff=H+diag(diag(H).*rand(nx,1));
|
|
0116 disp(<span class="string">'Cliff. Perturbing search direction.'</span>)
|
|
0117 [f2 x2 fc retcode2] = <a href="csminit.html" class="code" title="function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin)">csminit</a>(fcn,x,f,g,badg,Hcliff,varargin{:});
|
|
0118 <span class="comment">%ARGLIST</span>
|
|
0119 <span class="comment">%[f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,P1,P2,P3,P4,...</span>
|
|
0120 <span class="comment">% P5,P6,P7,P8,P9,P10,P11,P12,P13);</span>
|
|
0121 fcount = fcount+fc; <span class="comment">% put by Jinill</span>
|
|
0122 <span class="keyword">if</span> f2 < f
|
|
0123 <span class="keyword">if</span> retcode2==2 | retcode2==4
|
|
0124 wall2=1; badg2=1;
|
|
0125 <span class="keyword">else</span>
|
|
0126 <span class="keyword">if</span> NumGrad
|
|
0127 [g2 badg2] = <a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a>(fcn, x2,varargin{:});
|
|
0128 <span class="comment">%ARGLIST</span>
|
|
0129 <span class="comment">%[g2 badg2] = numgrad(fcn, x2,P1,P2,P3,P4,P5,P6,P7,P8,...</span>
|
|
0130 <span class="comment">% P9,P10,P11,P12,P13);</span>
|
|
0131 <span class="keyword">else</span>
|
|
0132 [g2 badg2] = feval(grad,x2,varargin{:});
|
|
0133 <span class="comment">%ARGLIST</span>
|
|
0134 <span class="comment">%[g2 badg2] = feval(grad,x2,P1,P2,P3,P4,P5,P6,P7,P8,...</span>
|
|
0135 <span class="comment">% P9,P10,P11,P12,P13);</span>
|
|
0136 <span class="keyword">end</span>
|
|
0137 wall2=badg2;
|
|
0138 <span class="comment">% g2</span>
|
|
0139 badg2
|
|
0140 save g2 g2 x2 f2 varargin
|
|
0141 <span class="comment">%ARGLIST</span>
|
|
0142 <span class="comment">%save g2 g2 x2 f2 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13;</span>
|
|
0143 <span class="keyword">end</span>
|
|
0144 <span class="keyword">if</span> wall2
|
|
0145 disp(<span class="string">'Cliff again. Try traversing'</span>)
|
|
0146 <span class="keyword">if</span> norm(x2-x1) < 1e-13
|
|
0147 f3=f; x3=x; badg3=1;retcode3=101;
|
|
0148 <span class="keyword">else</span>
|
|
0149 gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1);
|
|
0150 <span class="keyword">if</span>(size(x0,2)>1), gcliff=gcliff', <span class="keyword">end</span>
|
|
0151 [f3 x3 fc retcode3] = <a href="csminit.html" class="code" title="function [fhat,xhat,fcount,retcode] = csminit(fcn,x0,f0,g0,badg,H0,varargin)">csminit</a>(fcn,x,f,gcliff,0,eye(nx),varargin{:});
|
|
0152 <span class="comment">%ARGLIST</span>
|
|
0153 <span class="comment">%[f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),P1,P2,P3,...</span>
|
|
0154 <span class="comment">% P4,P5,P6,P7,P8,...</span>
|
|
0155 <span class="comment">% P9,P10,P11,P12,P13);</span>
|
|
0156 fcount = fcount+fc; <span class="comment">% put by Jinill</span>
|
|
0157 <span class="keyword">if</span> retcode3==2 | retcode3==4
|
|
0158 wall3=1; badg3=1;
|
|
0159 <span class="keyword">else</span>
|
|
0160 <span class="keyword">if</span> NumGrad
|
|
0161 [g3 badg3] = <a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a>(fcn, x3,varargin{:});
|
|
0162 <span class="comment">%ARGLIST</span>
|
|
0163 <span class="comment">%[g3 badg3] = numgrad(fcn, x3,P1,P2,P3,P4,P5,P6,P7,P8,...</span>
|
|
0164 <span class="comment">% P9,P10,P11,P12,P13);</span>
|
|
0165 <span class="keyword">else</span>
|
|
0166 [g3 badg3] = feval(grad,x3,varargin{:});
|
|
0167 <span class="comment">%ARGLIST</span>
|
|
0168 <span class="comment">%[g3 badg3] = feval(grad,x3,P1,P2,P3,P4,P5,P6,P7,P8,...</span>
|
|
0169 <span class="comment">% P9,P10,P11,P12,P13);</span>
|
|
0170 <span class="keyword">end</span>
|
|
0171 wall3=badg3;
|
|
0172 <span class="comment">% g3</span>
|
|
0173 badg3
|
|
0174 save g3 g3 x3 f3 varargin;
|
|
0175 <span class="comment">%ARGLIST</span>
|
|
0176 <span class="comment">%save g3 g3 x3 f3 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13;</span>
|
|
0177 <span class="keyword">end</span>
|
|
0178 <span class="keyword">end</span>
|
|
0179 <span class="keyword">else</span>
|
|
0180 f3=f; x3=x; badg3=1; retcode3=101;
|
|
0181 <span class="keyword">end</span>
|
|
0182 <span class="keyword">else</span>
|
|
0183 f3=f; x3=x; badg3=1;retcode3=101;
|
|
0184 <span class="keyword">end</span>
|
|
0185 <span class="keyword">else</span>
|
|
0186 <span class="comment">% normal iteration, no walls, or else we're finished here.</span>
|
|
0187 f2=f; f3=f; badg2=1; badg3=1; retcode2=101; retcode3=101;
|
|
0188 <span class="keyword">end</span>
|
|
0189 <span class="keyword">else</span>
|
|
0190 f2=f;f3=f;f1=f;retcode2=retcode1;retcode3=retcode1;
|
|
0191 <span class="keyword">end</span>
|
|
0192 <span class="comment">%how to pick gh and xh</span>
|
|
0193 <span class="keyword">if</span> f3 < f - crit & badg3==0
|
|
0194 ih=3
|
|
0195 fh=f3;xh=x3;gh=g3;badgh=badg3;retcodeh=retcode3;
|
|
0196 <span class="keyword">elseif</span> f2 < f - crit & badg2==0
|
|
0197 ih=2
|
|
0198 fh=f2;xh=x2;gh=g2;badgh=badg2;retcodeh=retcode2;
|
|
0199 <span class="keyword">elseif</span> f1 < f - crit & badg1==0
|
|
0200 ih=1
|
|
0201 fh=f1;xh=x1;gh=g1;badgh=badg1;retcodeh=retcode1;
|
|
0202 <span class="keyword">else</span>
|
|
0203 [fh,ih] = min([f1,f2,f3]);
|
|
0204 disp(sprintf(<span class="string">'ih = %d'</span>,ih))
|
|
0205 <span class="comment">%eval(['xh=x' num2str(ih) ';'])</span>
|
|
0206 <span class="keyword">switch</span> ih
|
|
0207 <span class="keyword">case</span> 1
|
|
0208 xh=x1;
|
|
0209 <span class="keyword">case</span> 2
|
|
0210 xh=x2;
|
|
0211 <span class="keyword">case</span> 3
|
|
0212 xh=x3;
|
|
0213 <span class="keyword">end</span> <span class="comment">%case</span>
|
|
0214 <span class="comment">%eval(['gh=g' num2str(ih) ';'])</span>
|
|
0215 <span class="comment">%eval(['retcodeh=retcode' num2str(ih) ';'])</span>
|
|
0216 retcodei=[retcode1,retcode2,retcode3];
|
|
0217 retcodeh=retcodei(ih);
|
|
0218 <span class="keyword">if</span> exist(<span class="string">'gh'</span>)
|
|
0219 nogh=isempty(gh);
|
|
0220 <span class="keyword">else</span>
|
|
0221 nogh=1;
|
|
0222 <span class="keyword">end</span>
|
|
0223 <span class="keyword">if</span> nogh
|
|
0224 <span class="keyword">if</span> NumGrad
|
|
0225 [gh badgh] = <a href="numgrad.html" class="code" title="function [g, badg] = numgrad(fcn,x,varargin)">numgrad</a>(fcn,xh,varargin{:});
|
|
0226 <span class="keyword">else</span>
|
|
0227 [gh badgh] = feval(grad, xh,varargin{:});
|
|
0228 <span class="keyword">end</span>
|
|
0229 <span class="keyword">end</span>
|
|
0230 badgh=1;
|
|
0231 <span class="keyword">end</span>
|
|
0232 <span class="comment">%end of picking</span>
|
|
0233 <span class="comment">%ih</span>
|
|
0234 <span class="comment">%fh</span>
|
|
0235 <span class="comment">%xh</span>
|
|
0236 <span class="comment">%gh</span>
|
|
0237 <span class="comment">%badgh</span>
|
|
0238 stuck = (abs(fh-f) < crit);
|
|
0239 <span class="keyword">if</span> (~badg)&(~badgh)&(~stuck)
|
|
0240 H = <a href="bfgsi.html" class="code" title="function H = bfgsi(H0,dg,dx)">bfgsi</a>(H,gh-g,xh-x);
|
|
0241 <span class="keyword">end</span>
|
|
0242 <span class="keyword">if</span> Verbose
|
|
0243 disp(<span class="string">'----'</span>)
|
|
0244 disp(sprintf(<span class="string">'Improvement on iteration %d = %18.9f'</span>,itct,f-fh))
|
|
0245 <span class="keyword">end</span>
|
|
0246 <span class="comment">% if Verbose</span>
|
|
0247 <span class="keyword">if</span> itct > nit
|
|
0248 disp(<span class="string">'iteration count termination'</span>)
|
|
0249 done = 1;
|
|
0250 <span class="keyword">elseif</span> stuck
|
|
0251 disp(<span class="string">'improvement < crit termination'</span>)
|
|
0252 done = 1;
|
|
0253 <span class="keyword">end</span>
|
|
0254 rc=retcodeh;
|
|
0255 <span class="keyword">if</span> rc == 1
|
|
0256 disp(<span class="string">'zero gradient'</span>)
|
|
0257 <span class="keyword">elseif</span> rc == 6
|
|
0258 disp(<span class="string">'smallest step still improving too slow, reversed gradient'</span>)
|
|
0259 <span class="keyword">elseif</span> rc == 5
|
|
0260 disp(<span class="string">'largest step still improving too fast'</span>)
|
|
0261 <span class="keyword">elseif</span> (rc == 4) | (rc==2)
|
|
0262 disp(<span class="string">'back and forth on step length never finished'</span>)
|
|
0263 <span class="keyword">elseif</span> rc == 3
|
|
0264 disp(<span class="string">'smallest step still improving too slow'</span>)
|
|
0265 <span class="keyword">elseif</span> rc == 7
|
|
0266 disp(<span class="string">'warning: possible inaccuracy in H matrix'</span>)
|
|
0267 <span class="keyword">end</span>
|
|
0268 <span class="comment">% end</span>
|
|
0269 f=fh;
|
|
0270 x=xh;
|
|
0271 g=gh;
|
|
0272 badg=badgh;
|
|
0273 <span class="keyword">end</span>
|
|
0274 <span class="comment">% what about making an m-file of 10 lines including numgrad.m</span>
|
|
0275 <span class="comment">% since it appears three times in csminwel.m</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> |