Issue using fmincon, using code not written by my group and updating it to work now

1 view (last 30 days)
I am currently working with a research group on modeling aerospikes and we found an old research paper from 2003 with included MatLAB code. We are going to try to modify it but first we are trying to simplify it and just get it to run but now we're running into this error: Failure in initial objective function evaluation. FMINCON cannot continue. Our code looks like this:
pinf = .160; % Ambient pressure
at = 4; % Thruster area per unit depth
p0 = 850; % Chamber stagnation pressure
gamma = 1.4; % Specific heat ratio
numsteps = 100; % Number of steps in mach number distribution
% Start the timer so the runtime can be determined
tic;
% Initial guess for thruster angle and truncation
x0 = [50,.4];
% Lower Boundary on optimization
lb = [20,.1];
% Upper Boundary on optimization
ub = [70,1];
% Set optimization options available within FMINCON
options = optimoptions('fmincon','ScaleProblem',false);
% Call FMINCON to perform optimization to find optimum values for
% thruster angle and truncation percent for the values given
% above using the function
% AER0SP1KE_C0N for the equality and inequality constraints
[x, fval] = fmincon(@aerospike_main,x0,[],[],[],[],lb,ub,'aerospike_con', options, at, pinf, p0, gamma, numsteps);
  1 Comment
Walter Roberson
Walter Roberson on 7 Dec 2022
For debugging, call
fmincon(@aerospike_main,x0)
and examine the results. See if there is an error message, or if the results are nan or inf or complex-valued.
Also I recommend changing 'aerospike_con' to @aerospike_con

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Dec 2022
For debugging, call
aerospike_main(x0, at, pinf, p0, gamma, numsteps)
and examine the results. See if there is an error message, or if the results are nan or inf or complex-valued.
Also I recommend changing 'aerospike_con' to @aerospike_con
I also recommend you read http://www.mathworks.com/help/matlab/math/parameterizing-functions.html about how to change your call to fmincon. Your current calling syntax is now undocumented, making use of an old feature that is not promised to work anymore.

Categories

Find more on Problem-Based Optimization Setup 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!