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 2function [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?
Best Answer