From e48a55324464193dbed3971d39d2a544fc8d50a3 Mon Sep 17 00:00:00 2001 From: Abhishek Mehra <52788025+Triaro@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:25:10 +0530 Subject: [PATCH] Create Random Search This code finds the minimum of f(x) = x(1)^2 + x(2)^2 in which -5 < x(i) < 5 This function is a convex and the minimum is at (0,0) The RSA is the simplest algorithm to solve optimization problem It is not efficient and it sometimes cannot solve the problem --- algorithms/Searching/random_search.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 algorithms/Searching/random_search.m diff --git a/algorithms/Searching/random_search.m b/algorithms/Searching/random_search.m new file mode 100644 index 0000000..2b46bf6 --- /dev/null +++ b/algorithms/Searching/random_search.m @@ -0,0 +1,24 @@ +%% Random Search Algorithm (Pure Random Search Algorithm) + +% This code finds the minimum of f(x) = x(1)^2 + x(2)^2 +% in which -5 < x(i) < 5 +% This function is a convex and the minimum is at (0,0) +% The RSA is the simplest algorithm to solve optimization problem +% it is not efficient and it sometimes cannot solve the problem + +clc +close all +clear all +dim=2; +popsize=100; +ftarget=0.01; +numIter=100; +ObjFun=@(x) sum(x.^2); +for i=1:numIter + candidate=10*rand(dim,popsize)-5; + best,=min(feval(ObjFun,candidate)); + if best <= ftarget + break; + end +end +disp(best);