Skip to content

Commit e48a553

Browse files
authored
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
1 parent 4899c7a commit e48a553

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%% Random Search Algorithm (Pure Random Search Algorithm)
2+
3+
% This code finds the minimum of f(x) = x(1)^2 + x(2)^2
4+
% in which -5 < x(i) < 5
5+
% This function is a convex and the minimum is at (0,0)
6+
% The RSA is the simplest algorithm to solve optimization problem
7+
% it is not efficient and it sometimes cannot solve the problem
8+
9+
clc
10+
close all
11+
clear all
12+
dim=2;
13+
popsize=100;
14+
ftarget=0.01;
15+
numIter=100;
16+
ObjFun=@(x) sum(x.^2);
17+
for i=1:numIter
18+
candidate=10*rand(dim,popsize)-5;
19+
best,=min(feval(ObjFun,candidate));
20+
if best <= ftarget
21+
break;
22+
end
23+
end
24+
disp(best);

0 commit comments

Comments
 (0)