How to direct the variable in the genetic algorithm function to workspace function?
古いコメントを表示
variable1 = input('Variable 1: ');
variable2 = input('Variable 2: ');
variable3 = input('Variable 3: ');
variable4 = input('Variable 4: ');
function y = myfunc(x)
y = x(1)*variable1 + x(2)*variable 2
function [c,ceq] = constraint(x)
c = [x(1)+x(2)-variable3;x(1)*x(2)-variable4];
ceq = [];
ObjectiveFunction = @myfunc;
nvars = 2; % Number of variables
LB = [0 0]; % Lower bound
UB = [100 100]; % Upper bound
ConstraintFunction = @constraint;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction);
As shown in the code above, I am trying to optimize the objective function based on some inputs from user. However, the function handler does not permit the variable from workspace direct to the function even their name is same. Is there any solution for this case?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!