8-4 ��ƪ����p��

MATLAB ´£¨Ñ¤F¼Æ­Ó«ü¥O¨Ó¶i¦æ¼Æ¾Ç¨ç¼Æªº³Ì¨Î¤Æ¡A¥»¸`±N¤¶²Ð¡G

¥»¸`©Ò°Q½×ªº³Ì¨Î¤Æ¤èªk¬O¤ñ¸û°ò¥»ªº¤èªk¡A­YŪªÌ¦³¿³½ì¨Ï¥Î¸û½ÆÂøªº¤èªk¡A¥i¥H¨Ï¥Î¡u³Ì¨Î¤Æ¤u¨ã½c¡v¡]Optimization Toolbox¡^¡C

­º¥ý§Ú­Ì¤¶²Ð³æÅܨç¼Æªº³Ì¤p¤Æ¡C¦pªG±z­n´M¨D humps ¦b [0.3, 1] ¤¤ªº³Ì¤p­È¡A¥i¥Î fminbnd «ü¥O¨Ó§ä¥X³Ì¤p­Èªºµo¥ÍÂI¡A¨Ò¦p¡G

Example 1: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/fminbnd01.m[x, minValue] = fminbnd(@humps, 0.3, 1) % ¨Ï¥Î fminbnd «ü¥O§ä¥X³Ì¤p­Èªºµo¥ÍÂI fplot(@humps, [0.3, 1]); grid on line(x, minValue, 'marker', 'o', 'color', 'r'); % Plot the minimum point x = 0.6370 minValue = 11.2528

¥Ñ¤W¨Ò¥iª¾¡AMATLAB ¨D±oªº³Ì¤p­Èµo¥Í¦b x = 0.637¡A¥B³Ì¤p­È¬° 11.2528¡C­Y­nª¾¹D´M¨D³Ì¤p­Èªº¤¤¶¡¹Lµ{¡A¥i¨Ï¥Î optimset «ü¥O¨Ó³]©wÅã¥Ü¿ï¶µ¡A¦A±N optimset ¶Ç¦^ªºµ²ºcÅܼưe¤J fminbnd¡A¨Ò¦p¡G

Example 2: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/fminbnd02.mopt = optimset('disp', 'iter'); % Åã¥Ü¨C­Ó¨BÆJªºµ²ªG [x, minValue] = fminbnd(@humps, 0.3, 1, opt) Func-count x f(x) Procedure 1 0.567376 12.9098 initial 2 0.732624 13.7746 golden 3 0.465248 25.1714 golden 4 0.644416 11.2693 parabolic 5 0.6413 11.2583 parabolic 6 0.637618 11.2529 parabolic 7 0.636985 11.2528 parabolic 8 0.637019 11.2528 parabolic 9 0.637052 11.2528 parabolic Optimization terminated: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04 x = 0.6370 minValue = 11.2528

¤Wªí¦C¥X x ­ÈªºÅܤƤά۹ïÀ³ªº¨ç¼Æ­È f(x)¡A³Ì«á¤@Äæ¦ì¦C¥X¨D·¥¤p­Èªº¤èªk¡A³q±`¬O¶Àª÷¤À³Î·j´M¡]Golden Section Search¡^©Î¬O©ßª«½u¤º´¡ªk¡]Parabolic Interpolation¡^¡C¥Ñ¦C¥Xªº¤å¦r°T®§¥i¥Hª¾¹D¡A©Òºâ¥Xªº x ­Èªº»~®t¤p©ó 10 ªº -4 ¦¸¤è¡C

­Y­n©ñÃP»~®tºÞ¨î¡A¨Ï fminbnd ´£¦­¶Ç¦^­pºâµ²ªG¡A¥ç¥i¥Ñ optimset ¨Ó¹F¦¨¡C¤U¨Ò±N x ªº»~®t½d³ò´£°ª¬° 0.1¡G

Example 3: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/fminbnd03.mopt = optimset( 'disp', 'iter', 'TolX', 0.1); % Åã¥Ü¨C­Ó¨BÆJªºµ²ªG¨Ã³]©w»~®t®e§Ô­È [x, minValue] = fminbnd(@humps, 0.3, 1, opt) Func-count x f(x) Procedure 1 0.567376 12.9098 initial 2 0.732624 13.7746 golden 3 0.465248 25.1714 golden 4 0.644416 11.2693 parabolic 5 0.611083 11.4646 parabolic 6 0.677749 11.7353 parabolic Optimization terminated: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-01 x = 0.6444 minValue = 11.2693

¥H¤W½d¨Ò§¡¬O¹ï³æÅܨç¼Æ¨D¤Î­È¡A­Y­n¨D¨ú¦hÅܼƨç¼Æªº·¥­È¡A¥i¥Ñ fminsearch «ü¥O¨D±o¡A¦ý±z¥²¶·«ü©w¤@­Ó°_©lÂI¡A¥HÅý fminsearch ¾Ú¥H¨D¥X¦b°_©lÂIªþªñªº§½³¡³Ì¤p­È¡]Local Minima¡^¡C°²³]±zªº¥Ø¼Ð¨ç¼Æ¬O¡G $$f(x_1, x_2, x_3)=(x_1-1)^2+5(x_2-2)^2+(x_3-3)^2$$

­º¥ý±z¥²¶·²£¥Í¤@­Ó MATLAB ªº¨ç¼Æ objective.m¡A¨ä¤º®e¥iÅã¥Ü¦p¤U¡G

function y = objective(x) y = (x(1)-1).^2 + 5*(x(2)-2).^2 + (x(3)-3).^2;

­Y°_©lÂI¬° $(x_1, x_2, x_3)=(0, 0, 0)$¡A«h§Ú­Ì¥i¥H¿é¤J¦p¤U¥H¨D¨ú³Ì¤p­Èªºµo¥Í¦ì¸m¡G

Example 4: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/fminsearch01.mx0 = [0, 0, 0]; x = fminsearch(@objective, x0) x = 1.0000 2.0000 3.0000

fminsearch ¨Ï¥Îªº¤èªk¬O¤U©Y¦¡ Simplex ·j´M¡]Downhill Simplex Search¡^¡A¸Ô²Ó°Ñ¦Ò¸ê®Æ¥i¨£ µ§ªÌªº¥t¤@¥»­^¤åµÛ§@¡G¡uNeuro ¡V Fuzzy and Soft Computing¡v, Prentice Hall, 1997¡C

MATLAB ³Ì¨Î¤Æªº¤èªk¦³³\¦h¤£¦Pªº¿ï¶µ¡A³o¨Ç¿ï¶µ¬O¸g¥Ñ¥t¤@­Ó¿é¤J¤Þ¼Æ¡]Input Argument¡^¨Ó¶i¤J fminbnd ©Î fminsearch¡A¨ä¨Ï¥Î»yªk¬°¡G

x = fminbnd(@function, x1, x2, options)

©Î

x = fminsearch(@function, x0, options )

¨ä¤¤ options ¬O¤@­Óµ²ºcÅܼơA¥]§t¤»¤Q¦h­ÓÄæ¦ì¡A¥Nªí¦UºØ³Ì¨Î¤Æªº¿ï¶µ¡]©Î°Ñ¼Æ¡^¡C±ý³]©w³o¨Ç³Ì¨Î¤Æ¿ï¶µ¡A¥i¥Î optimset «ü¥O¡A¨ä¨Ï¥Î»yªk¬°¡G

options = optimset(prop1, value1, prop2, value2, ¡K)

¨ä¤¤ prop1¡Bprop2 µ¥¬OÄæ¦ì¦WºÙ¡Avalue1¡Bvalue2 µ¥¬O¹ïÀ³ªºÄæ¦ì­È¡C¨Ò¦p¡A¦p«e©Ò­z¡A­Y­n¨Ï MATLAB ¦L¥X¨C¤@­Ó³Ì¨Î¤Æ¨BÆJªº¤¤¶¡µ²ªG¡A¨Ã©ñÃP»~®t½d³ò¡A«h¥i³]©w¦p¤U¡G

Example 5: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/optimset01.moptions = optimset('Disp', 'iter', 'TolX', 0.1); fieldNames=fieldnames(options); fprintf('No. of fields = %d\n', length(fieldNames)); options No. of fields = 55 options = <a href="matlab:helpPopup struct" style="font-weight:bold">struct</a> with fields: Display: 'iter' MaxFunEvals: [] MaxIter: [] TolFun: [] TolX: 0.1000 FunValCheck: [] OutputFcn: [] PlotFcns: [] ActiveConstrTol: [] Algorithm: [] AlwaysHonorConstraints: [] DerivativeCheck: [] Diagnostics: [] DiffMaxChange: [] DiffMinChange: [] FinDiffRelStep: [] FinDiffType: [] GoalsExactAchieve: [] GradConstr: [] GradObj: [] HessFcn: [] Hessian: [] HessMult: [] HessPattern: [] HessUpdate: [] InitBarrierParam: [] InitTrustRegionRadius: [] Jacobian: [] JacobMult: [] JacobPattern: [] LargeScale: [] MaxNodes: [] MaxPCGIter: [] MaxProjCGIter: [] MaxSQPIter: [] MaxTime: [] MeritFunction: [] MinAbsMax: [] NoStopIfFlatInfeas: [] ObjectiveLimit: [] PhaseOneTotalScaling: [] Preconditioner: [] PrecondBandWidth: [] RelLineSrchBnd: [] RelLineSrchBndDuration: [] ScaleProblem: [] SubproblemAlgorithm: [] TolCon: [] TolConSQP: [] TolGradCon: [] TolPCG: [] TolProjCG: [] TolProjCGAbs: [] TypicalX: [] UseParallel: []

¥Ñ¤W¨Ò¥iª¾¡Aoptions ¦@¦³¤»¤Q¦h­ÓÄæ¦ì¡A¥Hº¡¨¬²³¦h³Ì¨Î¤Æ«ü¥Oªº»Ý¨D¡C¡]¨ä¥¦³Ì¨Î¤Æ«ü¥O¥i¨£¡u³Ì¨Î¤Æ¤u¨ã½c¡]Optimization Toolbox¡^¡v¡^ÁöµM options Äæ¦ì²³¦h¡A¦ý¨Æ¹ê¤W¡A¨Ã¤£¬O¨C¤@­ÓÄæ¦ì­È³£·|³Q¥Î¨ì¡A¦pªGÄæ¦ì­ÈÅã¥Ü¬OªÅ¯x°}¡A¥Nªí MATLAB ·|¨Ï¥Î¦¹Äæ¦ìªº¹w³]­È¨Ó¶i¦æ¹Bºâ¡C¥t¡Aoptimset ·|®Ú¾Ú¿é¤Jªº³Ì¨Î¤Æ¨ç¼Æ¦WºÙ¦Ó¦^¶Ç¤£¦Pªºµ²ªG¡A¨Ò¦p§Ú­Ì¥i¥HÀ˵ø»P fminbnd ¬ÛÃöªº³Ì¨Î¤Æ¿ï¶µ¡G

Example 6: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/optimset02.moptions = optimset('fminbnd'); fieldNames=fieldnames(options); fprintf('No. of fields = %d\n', length(fieldNames)); for i=1:length(fieldNames) if ~isempty(options.(fieldNames{i})) fprintf('options.%s=%s\n', fieldNames{i}, num2str(options.(fieldNames{i}))); end endNo. of fields = 55 options.Display=notify options.MaxFunEvals=500 options.MaxIter=500 options.TolX=0.0001 options.FunValCheck=off

¦b¤W¼Æ½d¨Ò¤¤¡A§Ú­Ì¯S§O±NÄæ¦ì­È¬°ªÅ¦r¦êªºÄæ¦ì¶i¦æ§R°£¡A¥H¸`¬ÙÅã¥ÜªÅ¶¡¡C

­Y­nÀ˵ø»P fminsearch ¬ÛÃöªº³Ì¨Î¤Æ¿ï¶µ¡A¥i¥H¿é¤J¦p¤U

Example 7: 08-¤@¯ë¼Æ¾Ç¨ç¼Æªº³B²z»P¤ÀªR/optimset03.moptions = optimset('fminsearch'); fieldNames=fieldnames(options); fprintf('No. of fields = %d\n', length(fieldNames)); for i=1:length(fieldNames) if ~isempty(options.(fieldNames{i})) fprintf('options.%s=%s\n', fieldNames{i}, num2str(options.(fieldNames{i}))); end end No. of fields = 55 options.Display=notify options.MaxFunEvals=200*numberofvariables options.MaxIter=200*numberofvariables options.TolFun=0.0001 options.TolX=0.0001 options.FunValCheck=off

»P fminbnd ©M fminsearch ¬ÛÃöªº­«­n³Ì¨Î¤Æ¿ï¶µ¥i¥H»¡©ú¦p¤U¡G

  1. Display ­Y¬° 0 ¡]¹w³]­È¡^¡A«h¤£Åã¥Ü¤¤¶¡¹Bºâµ²ªG¡C¤Ï¤§¡A­Y¤£¬° 0¡A«hÅã¥Ü¹Bºâ¹Lµ{ªº¤¤¶¡µ²ªG¡C
  2. MaxFunEvals ¬O¨ç¼Æ¨D­È¹Bºâ¡]Function Evaluation¡^ªº³Ì°ª¦¸¼Æ¡A¹ï fminbnd ªº¹w³]­È¬O 500¡A¹ï fminsearch ªº¹w³]­È¬O 200 ­¼¤W x0 ªºªø«×¡C
  3. MaxIter ¬O³Ì¤jÅ|¥N¦¸¼Æ¡A¹ï fminbnd ªº¹w³]­È¬O 500¡A¹ï fminsearch ªº¹w³]­È¬O 200 ­¼¤W x0 ªºªø«×¡C
  4. TolFun ¬O¨M©w²×¤î·j´Mªº¨ç¼Æ­È®e§Ô«×¡A¹w³]¬° $10^{-4}$¡]¦¹¿ï¶µ¥u³Q fminsearch ¥Î¨ì¡Afminbnd ¨Ã¤£¨Ï¥Î¡^¡C
  5. TolX ¬O¨M©w²×¤î·j´Mªº¦ÛÅܼƭȮe§Ô«×¡A¹w³]¬° $10^{-4}$¡C

Hint
  • ³Ì¨Î¤Æ¨Ã«D¤@Ãà¥i¤Î¡A³q±`¨ä¹Lµ{¬O¤@¦A­«ÂСA³Ì«á¤~¯à¦¬ÀĨì³Ì¨ÎÂI¡C³Ì¨Î¤Æªºµ²ªG©M°_©lÂIªº¿ï©w¦³«Ü¤jªºÃöÁp¡F¤@­Ó¨}¦nªº°_©lÂI¡A¯à¥[§Ö³Ì¨Î¤Æ¦¬ÀĪº³t«×¡A¨Ã´£°ª§ä¨ì¥þ°ì³Ì¨Î­È¡]Global Optimum¡^ªº¾÷·|¡C
  • ¤£¦Pª©¥»ªº MATLAB¡A¥Ñ optimset «ü¥O¶Ç¦^ªº¿ï¶µ¥i¯à¦³©Ò¤£¦P¡A¦ý¬O®t²§©Ê¨Ã¤£¤j¡C


MATLABµ{¦¡³]­p¡G¶i¶¥½g