How can I write the code of the matrix calculations ?

1 view (last 30 days)
I need some help to write the code of the calculations below. Let out matrix be like the one below.
[X11 X12... X1n [1 3 5
X21 X22... X2n 2 4 1
Xm1 Xm2... Xmn] 4 6 2]
I added the objection function values of each row in their row.(onj. function is the sum of elements in each row.)
[X11 X12... X1n ObV1 [ 1 3 5 9
X21 X22... X2n ObV2 2 4 1 7
Xm1 Xm2... Xmn ObVm] 4 6 2 12]
I want to give ranks to the rows according to their objective function values in an ascending order and sort them.
[2 4 1 7 1
1 3 5 9 2
4 6 2 12 3]
Then I want to choose the first two one as best ones and the rest is worst. Like select the first two rows and create new rows from them according to this function
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example;
NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]
Thanks in advance.
  1 Comment
CarenCaren
CarenCaren on 12 May 2016
Edited: CarenCaren on 12 May 2016
Initial Matrix [X11 X12... X1n [1 3 5
X21 X22... X2n 2 4 1
Xm1 Xm2... Xmn] 4 6 2]
Objec. func. values [X11 X12... X1n ObV1 [1 3 5 9
X21 X22... X2n ObV2 2 4 1 7
Xm1 Xm2... Xmn ObVm] 4 6 2 12]
Ranked [2 4 1 7 1
1 3 5 9 2
4 6 2 12 3]
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example; NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 12 May 2016
X = [1 3 5
2 4 1
4 6 2];
[~,ii] = sort(sum(X,2));
B = X(ii,:);
NewOne = B + bsxfun(@times,rand(size(X,1),1)./B(:,1),B);
  1 Comment
CarenCaren
CarenCaren on 12 May 2016
Like select the first two rows and create new rows from them according to this function.
NewOne(m,n)=BestOne(m,n)+(rand()/coefficient)*BestOne(m,n)
For example;
NewOne= [2 4 1]+ (0.4/2)*[2 4 1]=[2.4 4.8 1.2]
and the new row created from the row with the worst obj. function value according to
New One= WorstOne+rand()*WorstOne. How can I separate the rows and apply this equations for creating new rows from them? For example I want to select the first n rows and apply them equation 1, and for the rest ı want to apply equation 2.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!