Looking for a function minimizer subject to nonlinear constraints with absolute function tolerance.

9 views (last 30 days)
I am trying to minimize a root mean squared function for a Lorentz distribution. MATLAB's fminsearch did a decent job, but I cannot constrain any variables. MATLAB's fmincon seemed to be able to handle constraints, but it ends prematurely because the of the step size tolerance. I would like the minimizer function to end when objective function tolerance has been met, not when step size tolerance has been met. Any advice on how to change my current code to constrain the variables or which minimizer to try? Below is my code along with comments explaining how I am trying to constrain the variables.
%This is my Lorentz distribution function, I am trying to constrain X(2)
%such that -1.5<=X(2)=1.5, or abs(X(2))-1.5<=0.
y = @(X,loc)X(3)*1/pi*X(1)/((loc-X(2))^2+X(1)^2);
%These are single values, typically on the order of 1E20 to 1E23
Ch1 = double(CH1(returnIndex));
Ch2 = double(CH2(returnIndex));
Ch3 = double(CH3(returnIndex));
Ch = [Ch1,Ch2,Ch3];
%This is my objective function, the root mean squared equation.
%Essentially, I am trying to minimize this by adjusting the values of X in
%our Lorentz distribution.
RMS = @(X)sqrt(((y(X,1.5)-Ch1)^2+(y(X,0)-Ch2)^2 + (y(X,-1.5)-Ch3)^2)/3);
%This is my initial guess for the minimizing function
initial = [1,0,10^(floor(log10(max(Ch))))];%[gamma,x0,fudgeFactor]%Please do not confuse this x0 with the x0 in the fminsearch documentation. The Lorentz distribution also uses an x0.
%Trying to set different options to help get a better result
v=[.1,.01,1E20];
options = optimset('PlotFcns',@optimplotfval,'MaxIter',600,'MaxFunEvals',1000,'FinDiffRelStep',v);%This shows the minimization over each iteration,not necessary for final code
%options = optimset('MaxIter',600,'MaxFunEvals',1800);
Output = fminsearch(RMS,initial,options);%Minimizing root mean squared eqn for Cauchy-Lorentz distribution fcn
% Below is the code I have tried using for the fmincon function
% function [c,ceq] = conditions(X) %<--these are my nonlinear contraints
% c = abs(X(2))-1.5; %|x0|<=1.5
% ceq=[];
% end
%
% nonlcon = @conditions;
% v=[.1,.01,1E20];
% options = optimoptions(@fminimax,'PlotFcns',@optimplotfval,'MaxIter',600,'MaxFunEvals',1800,'FiniteDifferenceStepSize',v,'FunctionTolerance',1E10);
% %optimset('PlotFcns',@optimplotfval,'MaxIter',600,'MaxFunEvals',1800,'FinDiffRelStep',v);
% [Output] = fminimax(RMS,initial,[],[],[],[],[],[],nonlcon,options);
% gamma = Output(1);
% x0 = Output(2);
% fudgeFactor = Output(3);

Answers (1)

Mohammad Sami
Mohammad Sami on 23 Feb 2022
You can try setting the 'TolFun' parameter in the optimset.
You can refer to the following documentations for more details

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!