% % Examples From the book: % % Practical Genetic Algorithms % by Haupt & Haupt. % % Epage: 44 % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; clc; clear all; % pick a function to study: % funnum = 7; % this function has a bounded domain funnum = 10; % this function has an unbounded domain %plot_test_functions % display this function wfn = @(x) fn_wrap(x,funnum); addpath('../SHIP'); % The Nelder Mead method: % fprintf('first nelder mead solution\n'); x0_1 = [ 2, 3.; 2, 7.525; 8.5, 7.7 ]'; % start with a very large amoeba that does not surround the solution nm_1 = nelder( x0_1, wfn, 0.00001 ); nm_1 = mean( nm_1', 1 ) wfn( nm_1 ) fprintf('second nelder mead solution\n'); x0_2 = [ 1, 1.; -1, 1; 0, -2 ]'; % start with a smaller amoeba surrounding the global optimum nm_2 = nelder( x0_2, wfn, 0.00001 ); nm_2 = mean( nm_2', 1 ) wfn( nm_2 ) % The BFGS method: % fprintf('The BFGS solution\n'); bfgs_1 = bfgswopt( -[5;5], wfn, 0.00001 ) wfn( bfgs_1 ) % The steepest decent algorithm: % fprintf('The SD solution\n'); sd_1 = steep( -[5;5], wfn, 0.00001 ) wfn( sd_1 )