Cody

Problem 45963. Function minimization - global minimum

Solution 2877287

Submitted on 25 Aug 2020 by Alfonso Nieto-Castanon
  • Size: 48
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('global_min.m'); filetext(find(filetext == '%', 1, 'last') : end) = []; assert(isempty(strfind(filetext, '>')), 'File handling is forbidden.'); assert(isempty(strfind(filetext, 'eval')), 'Eval forbidden.'); assert(isempty(strfind(filetext, 'regexp')), 'Regexp forbidden.'); assert(isempty(strfind(filetext, '!')), 'Shell commands are forbidden.'); assert(isempty(strfind(filetext, 'mlock')), 'mlock is forbidden.'); assert(isempty(strfind(filetext, 'munlock')), 'munlock is forbidden.'); assert(isempty(strfind(filetext, '@')), 'Anonymous functions are forbidden.');

2   Pass
fun=@(x)cos(x)-cos(pi*x)/pi; ytobeat=-1.318280171; xopt = global_min(fun,ytobeat) yopt=fun(xopt) assert(yopt < ytobeat)

xopt = -21.9979 yopt = -1.3183

3   Pass
fun=@(x)cos(x/100)-cos(pi*x/100)/pi; ytobeat=-1.318280171; xopt = global_min(fun,ytobeat) yopt=fun(xopt) assert(yopt < ytobeat)

xopt = -2.1998e+03 yopt = -1.3183

4   Pass
fun=@(x)sin(20./x).*sin(20*x) ytobeat=-0.9999635; xopt = global_min(fun,ytobeat) yopt=fun(xopt) assert(yopt < ytobeat)

fun = function_handle with value: @(x)sin(20./x).*sin(20*x) xopt = -12.8020 yopt = -1.0000

5   Pass
fun=@(x)sin(20./(x/100)).*sin(20*x/100) ytobeat=-0.999963542; xopt = global_min(fun,ytobeat) yopt=fun(xopt) assert(yopt < ytobeat)

fun = function_handle with value: @(x)sin(20./(x/100)).*sin(20*x/100) xopt = -7.8113 yopt = -1.0000

Suggested Problems

More from this Author10

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!