ローゼンブロック関数の最適化
pkg load ga; function y = rosenbrock(x) % Rosenbrock function, commonly used for testing optimization algorithms y = 100 * (x(2) - x(1)^2)^2 + (1 - x(1))^2; end nvars = 2; lb = [-5, -5]; % Lower bounds ub = [5, 5]; % Upper bounds ga_options = gaoptimset('Generations', 200, 'PopulationSize', 100, 'InitialPopulation', x0, 'Vectorized', 'off'); [x, fval] = ga(@rosenbrock, nvars, [], [], [], [], lb, ub, ga_options); % Display the result disp("Optimized variables:"); disp(x); disp("Minimum value of the function:"); disp(fval);