i want only that child which strickly follow X+Y+Z=9 if not follow than doing process one more time with other element,

1 Ansicht (letzte 30 Tage)
wrappedcolumns = [7 8];
child = parent;
swapoddeven = reshape([2:2:size(parent, 1); 1:2:size(parent, 1)], 1, ]);
child(swapoddeven, swappedcolumns) = child(1:size(parent, 1),swappedcolumns)
after this i process i got child matrix
x y z
1 2 6 =9 valid
6 2 1 =9 valid
2 1 4 =7 not valid
2 1 1 =4 not valid
6 2 8 =16 not valid
1 7 8 =16 not valid
{i want only that child which strickly follow X+Y+Z=9 if not follow than doing process one more time with other element} {i want to find minumum value of [(X(-0.33).^2+(Y-0.33).^2+(Z-0.33).^2] this function where X+Y+Z=9 with genetic algorithm}
  6 Kommentare
Guillaume
Guillaume am 14 Dez. 2016
That code is a total mess, with meaningless variable names (iwant, el, c), half of the lines that don't do anything and bits of code that don't appear to be related.
Simplification of the first part:
[X, Y, Z ] = ndgrid(0:9); %all combinations
XYZ = [X(:), Y(:), Z(:)]; %concatenate into a three column matrix
XYZ = XYZ(sum(XYZ, 2) == 9, :); %only keep rows that sum to 9
eq1 = sum((XYZ - 0.33) .^ 2, 2);
chosenrows = randi(size(XYZ, 1), 1, 6); %your c
entries = XYZ(chosenrows, :);
bins = fliplr(de2bi(entries), 8);
%... rest of the code as normal
I have no idea what your question is.
Steven Lord
Steven Lord am 14 Dez. 2016
How about this:
[X, Y] = meshgrid(0:9);
XYZ = [X(:), Y(:), 9-X(:)-Y(:)];
If you have an additional constraint, that Z must contain only nonnegative values:
XYZ(XYZ(:, 3) < 0, :) = [];

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by