MATLAB Answers

Optimization running. Error running optimization. Undefined function 'Cost_mini​mization_f​unction' for input arguments of type 'double'.

18 ビュー (過去 30 日間)
Shamir Sheikkariem
Shamir Sheikkariem 2019 年 9 月 25 日
回答済み: Naveen Venkata Krishnan 2019 年 10 月 10 日
Optimization running.
Error running optimization.
Undefined function 'Cost_minimization_function' for input arguments of type 'double'.
What does this mean

  2 件のコメント

Alan Weiss
Alan Weiss 2019 年 9 月 25 日
Please show us the function call that led to this error message.
Alan Weiss
MATLAB mathematical toolbox documentation
Shamir Sheikkariem
Shamir Sheikkariem 2019 年 9 月 25 日
%Objective function
function y = Cost_minimization_function(x) y = (x(1))*x(2); end
% Equality linear constraint
function [c] = costContraints (x)
c = 13000 - (x(1)*x(2));
end
%Initialize optimization
ObjFcn = @Cost_minimization_function;
x0 = [20 5]; % Initial input value for x1 and x2
nvars = 2; % Number of variables
lb = [1 2]; % Lower bound
ub = [171 5]; % Upper bound
ConsFcn = @costContraints; % Linear constraint function
rng default
% For reproducibility
[x, fval, exitFlag, Output] = ga(ObjFcn,nvars,lb,ub,ConsFcn)
% Run Genetic Algorithm solver
Error using ga (line 356)
GA requires the following inputs to be of data type double: 'Aeq'.

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

回答 (1 件)

Naveen Venkata Krishnan
Naveen Venkata Krishnan 2019 年 10 月 10 日
Hello Shamir,
There is a mistake in the way you have implemented the 'ga' function . Change it to :
[x, fval, exitFlag, Output] = ga(ObjFcn,nvars,[],[],[],[],lb,ub,ConsFcn);

  0 件のコメント

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

Community Treasure Hunt

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

Start Hunting!

Translated by