lnsrch1
PURPOSE 
function [x,f,fvec,check]=lnsrch1(xold,fold,g,p,stpmax,func,j1,j2,varargin)
SYNOPSIS 
function [x,f,fvec,check]=lnsrch1(xold,fold,g,p,stpmax,func,j1,j2,varargin)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- max @info:
- check Checks determinacy conditions by computing the generalized eigenvalues.
This function is called by:
- solve1 function [x,check] = solve1(func,x,j1,j2,jacobian_flag,bad_cond_flag,varargin)
- solve_one_boundary Computes the deterministic simulation of a block of equation containing
- solve_two_boundaries Computes the deterministic simulation of a block of equation containing
SOURCE CODE 
0001 function [x,f,fvec,check]=lnsrch1(xold,fold,g,p,stpmax,func,j1,j2,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 global options_
0044
0045 alf = 1e-4 ;
0046 tolx = options_.solve_tolx;
0047 alam = 1;
0048
0049 x = xold;
0050 nn = length(j2);
0051 summ = sqrt(sum(p.*p)) ;
0052 if ~isfinite(summ)
0053 error(['Some element of Newton direction isn''t finite. Jacobian maybe' ...
0054 ' singular or there is a problem with initial values'])
0055 end
0056
0057 if summ > stpmax
0058 p=p.*stpmax/summ ;
0059 end
0060
0061 slope = g'*p ;
0062
0063 test = max(abs(p)'./max([abs(xold(j2))';ones(1,nn)])) ;
0064 alamin = tolx/test ;
0065
0066 if alamin > 0.1
0067 alamin = 0.1;
0068 end
0069
0070 while 1
0071 if alam < alamin
0072 check = 1 ;
0073 return
0074 end
0075
0076 x(j2) = xold(j2) + (alam*p) ;
0077 fvec = feval(func,x,varargin{:}) ;
0078 fvec = fvec(j1);
0079 f = 0.5*fvec'*fvec ;
0080
0081 if any(isnan(fvec))
0082 alam = alam/2 ;
0083 alam2 = alam ;
0084 f2 = f ;
0085 fold2 = fold ;
0086 else
0087
0088 if f <= fold+alf*alam*slope
0089 check = 0;
0090 break ;
0091 else
0092 if alam == 1
0093 tmplam = -slope/(2*(f-fold-slope)) ;
0094 else
0095 rhs1 = f-fold-alam*slope ;
0096 rhs2 = f2-fold2-alam2*slope ;
0097 a = (rhs1/(alam^2)-rhs2/(alam2^2))/(alam-alam2) ;
0098 b = (-alam2*rhs1/(alam^2)+alam*rhs2/(alam2^2))/(alam-alam2) ;
0099 if a == 0
0100 tmplam = -slope/(2*b) ;
0101 else
0102 disc = (b^2)-3*a*slope ;
0103
0104 if disc < 0
0105 error ('Roundoff problem in nlsearch') ;
0106 else
0107 tmplam = (-b+sqrt(disc))/(3*a) ;
0108 end
0109
0110 end
0111
0112 if tmplam > 0.5*alam
0113 tmplam = 0.5*alam;
0114 end
0115
0116 end
0117
0118 alam2 = alam ;
0119 f2 = f ;
0120 fold2 = fold ;
0121 alam = max([tmplam;(0.1*alam)]) ;
0122 end
0123 end
0124 end
0125
0126
0127
0128
Generated on Mon 21-May-2012 02:42:43 by m2html © 2005