kindly solve the error' index at position 1 exceedes the array bounds
2 次查看(过去 30 天)
显示 更早的评论
function Output = multi_objective_function(Input)
x(1) = Input(1); % variable 1
x(2) = Input(2); % variable 2
x(3) = Input(2); % variable 3
x(4) = Input(2); % variable 4
F1 = 84718*x(1)+72627.42*x(2)+41021.98*x(3)+58077.44*x(4); % objective 1
F2 = -1124.424*x(1)-1004.247*x(2)-8.40858*x(3)-10.52292*x(4); % objective 2
F3 = -51.524*x(1)-47.666*x(2)-19.136*x(3)-19.134*x(4); % objective 3
Output = [F1 F2 F3];
function [x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,Aeq,beq,Aineq,bineq,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data)
options = optimoptions('gamultiobj');
options = optimoptions(options,'PopulationSize', PopulationSize_Data);
options = optimoptions(options,'MaxGenerations', MaxGenerations_Data);
options = optimoptions(options,'MaxStallGenerations', MaxStallGenerations_Data);
options = optimoptions(options,'FunctionTolerance', FunctionTolerance_Data);
options = optimoptions(options,'ConstraintTolerance', ConstraintTolerance_Data);
options = optimoptions(options,'CrossoverFcn', { @crossoverintermediate [] });
options = optimoptions(options,'Display', 'off');
[x,fval,exitflag,output,population,score] = ...
gamultiobj(@multi_objective_function,nvars,[],[],Aineq,bineq,[],[],[],options);
clc
clear
close all
nvars = 4;
Aineq =[1 1 1 1; 220.086 210.356 92.672 135.994; 464.75 203.194 261.548 206.638];
bineq = [49.9; 660; 1136];
PopulationSize_Data = 500;
MaxGenerations_Data = 100;
MaxStallGenerations_Data = 100;
FunctionTolerance_Data = 0;
ConstraintTolerance_Data = 0;
[x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,[],[],Aineq,bineq,[],[],PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data);
optimal_solution = x;
objective_functions = fval;
plot3(fval(1,:),fval(2,:),fval(3,:),'o')
1 个评论
Walter Roberson
2022-9-20
Is this the same code you posted on a different Question? If so then see https://www.mathworks.com/matlabcentral/answers/408504-index-in-position-2-exceeds-array-bounds-must-not-exceed-1#comment_2371425
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!