Fmincon issue: Failure in initial objective function evaluation. FMINCON cannot continue.

I am trying to minimize the absolute differences between frequencies in ETABSV21 through API using a self created objective function. But with the code i have this error is showed: Failure in initial objective function evaluation. FMINCON cannot continue.
Bellow is the function code
function fo=objetivo(x)
global SapModel PropFrame PropMaterial Analyze AnalysisResultsSetup Results
PropMaterial.SetMPIsotropic('conc_losa',x(1)*24855.58,0.2,0.0000099);
PropMaterial.SetMPIsotropic('conc_muros',x(2)*24855.58,0.2,0.0000099);
Analyze.RunAnalysis();
AnalysisResultsSetup.DeselectAllCasesAndCombosForOutput;
AnalysisResultsSetup.SetCaseSelectedForOutput('MODAL');
NumberResults = 0;
LoadCase = {''};
StepType = {''};
StepNum = 0;
Period = 0;
Frequency = 0;
CircFreq = 0;
EigenValue = 0;
[ret,NumberResults,~,~,~,Period,Frequency,~,~]=Results.ModalPeriod(NumberResults, LoadCase, StepType, StepNum, Period, Frequency, CircFreq, EigenValue)
frecuencias=double(Frequency)
fo=mean(abs((frecuencias(1)-2.5781))/2.5781 + abs((frecuencias(3)-2.7930))/2.7930+abs((frecuencias(2)-4.8438))/4.8438);
xo = x;
save('xo', 'xo')
end
NOW this is how i call the function
LI=[20000.58/24855.58];
CI=[24855.58/24855.58];
LS=[33855.58/24855.58];
opciones=optimoptions('fmincon','Algorithm','sqp','Display','iter','PlotFcn',@optimplotfval)
[x,fval,~] = fmincon(@objetivo,CI,[],[],[],[],LI,LS,[],opciones);

댓글 수: 4

I suggest you try
fo = objetivo(CI)
right before the call to "fmincon" and see what is returned in "fo".
It should be some scalar value in order to let "fmincon" work.
It appears that like that the initial error is corrected. Now is this:
Dot indexing is not supported for variables of this type.
Error in objetivo (line 5)
PropMaterial.SetMPIsotropic('conc_losa', x(1)*24855.58, 0.2,0.0000099);
You only have one unknown CI = x(1). Thus refering to x(2) in the line
PropMaterial.SetMPIsotropic('conc_muros',x(2)*24855.58,0.2,0.0000099);
makes no sense.
Thank you so much, however,
I do have this:
LI=[20000.58/24855.58, 20000.58/24855.58];
CI=[24855.58/24855.58, 24855.58/24855.58];
LS=[33855.58/24855.58, 33855.58/24855.58];
Its still the same error

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2023년 6월 28일
이동: Walter Roberson 2023년 6월 29일
It seems that
PropMaterial.SetMPIsotropic
cannot be accessed in "objetivo".
Are you sure it has been written into the global variable "PropMaterial" somewhere before in your code ?
What do you get if you type
PropMaterial
right after
function fo=objetivo(x)
global SapModel PropFrame PropMaterial Analyze AnalysisResultsSetup Results
?
Maybe empty ?

댓글 수: 1

That was the thing, i have to define the global variables both in the script like in the function. Thank you for everything

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2023년 6월 28일

이동:

2023년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by