How can I write the code of the matrix calculations ?

1 回表示 (過去 30 日間)
CarenCaren
CarenCaren 2016 年 5 月 12 日
編集済み: Stephen23 2016 年 5 月 12 日
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 件のコメント
CarenCaren
CarenCaren 2016 年 5 月 12 日
編集済み: CarenCaren 2016 年 5 月 12 日
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]

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 5 月 12 日
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 件のコメント
CarenCaren
CarenCaren 2016 年 5 月 12 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by