// // compute.roots.sce -- // Compute the roots of the caracteristic equation of Nelder-Mead algorithm. // Reproduce the results by Han & Neuman. // // Copyright 2008-2009 Michael Baudin // // // computeroots1 -- // Compute the roots of the caracteristic equations of // usual Nelder-Mead method. // function computeroots1 ( n ) // Polynomial for outside contraction : // n - 3x - ... - 3x^(n-1) + 2n x^(n) = 0 mprintf("Polynomial for outside contraction :\n"); coeffs = zeros(1,n+1); coeffs(1) = n coeffs(2:n) = -3 coeffs(n+1) = 2 * n p=poly(coeffs,"x","coeff") disp(p) r = roots(p) for i=1:n mprintf("#%d/%d |%s|=%f\n", i, length(r),string(r(i)),abs(r(i))) end // Polynomial for inside contraction : // - n - x - ... - x^(n-1) + 2n x^(n)= 0 mprintf("Polynomial for inside contraction :\n"); coeffs = zeros(1,n+1); coeffs(1) = -n coeffs(2:n) = -1 coeffs(n+1) = 2 * n p=poly(coeffs,"x","coeff") disp(p) r = roots(p) for i=1:n mprintf("#%d/%d |%s|=%f\n", i, length(r),string(r(i)),abs(r(i))) end // Polynomial for reflection : // n - 2x - ... - 2x^(n-1) + n x^(n) = 0 mprintf("Polynomial for reflection :\n"); coeffs = zeros(1,n+1); coeffs(1) = n coeffs(2:n) = -2 coeffs(n+1) = n p=poly(coeffs,"x","coeff") disp(p) r = roots(p) for i=1:n mprintf("#%d/%d |%s|=%f\n", i, length(r),string(r(i)),abs(r(i))) end endfunction function [rminoc , rmaxoc , rminic , rmaxic] = computeroots1_abstract ( n ) // Polynomial for outside contraction : // n - 3x - ... - 3x^(n-1) + 2n x^(n) = 0 coeffs = zeros(1,n+1); coeffs(1) = n coeffs(2:n) = -3 coeffs(n+1) = 2 * n p=poly(coeffs,"x","coeff") r = roots(p , "e") rminoc = min(abs(r)) rmaxoc = max(abs(r)) // Polynomial for inside contraction : // - n - x - ... - x^(n-1) + 2n x^(n)= 0 coeffs = zeros(1,n+1); coeffs(1) = -n coeffs(2:n) = -1 coeffs(n+1) = 2 * n p=poly(coeffs,"x","coeff") r = roots(p , "e") rminic = min(abs(r)) rmaxic = max(abs(r)) mprintf("%d & %f & %f & %f & %f\\\\\n", n, rminoc, rmaxoc, rminic, rmaxic) endfunction function drawfigure1 ( nbmax ) rminoctable = zeros(1,nbmax) rmaxoctable = zeros(1,nbmax) rminictable = zeros(1,nbmax) rmaxictable = zeros(1,nbmax) for n = 1 : nbmax [rminoc , rmaxoc , rminic , rmaxic] = computeroots1_abstract ( n ) rminoctable ( n ) = rminoc rmaxoctable ( n ) = rmaxoc rminictable ( n ) = rminic rmaxictable ( n ) = rmaxic end plot2d ( 1:nbmax , [ rminoctable' , rmaxoctable' , rminictable' , rmaxictable' ] ) f = gcf(); pause f.children.title.text = "Nelder-Mead caracteristic equation roots"; f.children.x_label.text = "Number of variables (n)"; f.children.y_label.text = "Roots of the caracteristic equation"; captions(f.children.children.children,["R-max-IC","R-min-IC","R-max-OC","R-min-OC"]); f.children.children(1).legend_location="in_lower_right"; for i = 1:4 mypoly = f.children.children(2).children(i); mypoly.foreground=i; mypoly.line_style=i; end xs2png(0,"neldermead-roots.png"); endfunction // // computeroots2 -- // Compute the roots of the caracteristic equations of // baudin Nelder-Mead method, when the xbar is xlow. // function computeroots2 ( n ) // Polynomial for outside contraction : // 1 - 3x^(n-1) + 2 x^(n) = 0 mprintf("Polynomial for outside contraction :\n"); coeffs = zeros(1,n+1); coeffs(1) = 1 coeffs(n) = -3 coeffs(n+1) = 2 p=poly(coeffs,"x","coeff") disp(p) r = roots(p) for i=1:n mprintf("#%d/%d |%s|=%f\n", i, length(r),string(r(i)),abs(r(i))) end // Polynomial for inside contraction : // - 1 - x^(n-1) + 2 x^(n)= 0 mprintf("Polynomial for inside contraction :\n"); coeffs = zeros(1,n+1); coeffs(1) = -1 coeffs(n) = -1 coeffs(n+1) = 2 p=poly(coeffs,"x","coeff") disp(p) r = roots(p) for i=1:n mprintf("#%d/%d |%s|=%f\n", i, length(r),string(r(i)),abs(r(i))) end // Polynomial for reflection : // ??? endfunction // // rootsvariable -- // Compute roots of the caracteristic equation // of Nelder-Mead with variable coefficient mu. // Polynomial for outside/inside contraction : // n mu - (1+mu)x - ... - (1+mu)x^(n-1) + n x^(n) = 0 // function [rmin , rmax] = rootsvariable ( n , mu ) coeffs = zeros(1,n+1); coeffs(1) = n * mu coeffs(2:n) = -(1+mu) coeffs(n+1) = n p=poly(coeffs,"x","coeff") r = roots(p , "e") rmin = min(abs(r)) rmax = max(abs(r)) mprintf("%f & %f & %f\\\\\n", mu, rmin, rmax) endfunction function drawfigure_variable ( n , nmumax ) rmintable = zeros(1,nmumax) rmaxtable = zeros(1,nmumax) mutable = linspace ( -1 , 1 , nmumax ) for index = 1 : nmumax mu = mutable ( index ) [rmin , rmax ] = rootsvariable ( n , mu ) rmintable ( index ) = rmin rmaxtable ( index ) = rmax end plot2d ( mutable , [ rmintable' , rmaxtable' ] ) f = gcf(); pause f.children.title.text = "Nelder-Mead caracteristic equation roots"; f.children.x_label.text = "Contraction coefficient"; f.children.y_label.text = "Roots of the caracteristic equation"; captions(f.children.children.children,["R-max","R-min"]); f.children.children(1).legend_location="in_lower_right"; for i = 1:2 mypoly = f.children.children(2).children(i); mypoly.foreground=i; mypoly.line_style=i; end xs2png(0,"neldermead-roots-variable.png"); endfunction