failure in user-supplied fitness function evaluation. GA cannot continue. problem based
12 views (last 30 days)
Show older comments
hi im using problem based format to do optimization, when im using fmincon it doest have a problem however it fall to local minimum therefore, i try using GA but somehow it have error as follow;
Error using interp1
Input coordinates must be real.
Error in ha>objectiveFcn (line 63)
data(i,16)=interp1(RS(1,:),RS(2,:),data(i,12))/data(i,15);
Error in generatedObjective (line 42)
....
Error in ha (line 45)
[solution,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint,Solver="ga",Options=opts);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
below is the coding....
clear;
clc;
%data input
data=readmatrix('sortout data.xlsx');
%column 1 = no PGA
%column 2 = PGA
%column 3 = M(kg)
%column 4 = Friction Damping (N)
%column 5 = sloping angle (radian)
%column 6 = arc radius (m)
%column 7 = arc range (m)
%column 8 = NLTH displacement
%column 9= NLTH acceleration
responsespectra=readmatrix('far field response spectra.xlsx');
dampingfactor=[2 0.8;5 1;10 1.2;20 1.5;30 1.7;40 1.9;50 2].';
% Create optimization variables
A3 = optimvar("A",LowerBound=-50,UpperBound=50);
B3 = optimvar("B",LowerBound=-50,UpperBound=50);
C3 = optimvar("C",LowerBound=-50,UpperBound=50);
D3 = optimvar("D",LowerBound=-50,UpperBound=50);
E3 = optimvar("E",LowerBound=-50,UpperBound=50);
F3 = optimvar("F",LowerBound=-50,UpperBound=50);
% Set initial starting point for the solver
initialPoint.A = 1;
initialPoint.B = 1;
initialPoint.C = 1;
initialPoint.D = 1;
initialPoint.E = 1;
initialPoint.F = 1;
% Create problem
problem = optimproblem;
% Define problem objective
expr=fcn2optimexpr(@objectiveFcn,A3,B3,C3,D3,E3,F3,data,responsespectra, ...
dampingfactor);
problem.Objective = expr;
% Define problem constraints
% Solve problem
opts=optimoptions("ga",'UseParallel',true);
[solution,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint, ...
Solver="ga",Options=opts);
%function
function objective = objectiveFcn(A,B,C,D,E,F,data,responsespectra,dampingfactor)
data(:,10)=A+B*data(:,5)+C*(data(:,4)./data(:,3)); %optimization Keq
data(:,11)=(data(:,4)+data(:,3)*9.81.*data(:,7)/2./data(:,6))./data(:,8).*data(:,10);%Keq
data(:,12)=2*pi*sqrt(data(:,3)./data(:,11));%Teq
data(:,13)=D+E*data(:,5)+F*(data(:,4)./data(:,3)); %optimization KSIeq
data(:,14)=2*data(:,4)/pi./data(:,11)./data(:,8).*data(:,13)*100; %Ksi
for i=1:length(data)
if data(i,14)<=2
data(i,15)=0.8;
elseif data(i,14)>=50
data(i,15)=2;
else
data(i,15)=interp1(dampingfactor(1,:),dampingfactor(2,:),data(i,14));
end
RS=responsespectra(:,[1 1+data(i,1)]).';
data(i,16)=interp1(RS(1,:),RS(2,:),data(i,12))/data(i,15);
end
objective=mean((data(:,16)-data(:,8))./data(:,8))*100;
end
0 Comments
Answers (1)
Matt J
on 2 Nov 2022
The error message is complaining that RS(1,:),RS(2,:), or data(i,12) do not contain real values. You should check.
0 Comments
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!