Plotting fmincon with varying constraint

Hi all. I've got a function which I'm trying to minimize subject to a nonlinear constraint. I've been able to get this to work, but now I want to vary the constraint and plot the minimum as a function of this new parameter. I.e., I want to plot subject to the constraint The parameter a should take values in . I can provide the files I'm working with upon request, but so far I've just been working with fmincon as provided in the documentation. Any advice is appreciated, thanks in advance!

 Accepted Answer

See http://www.mathworks.com/help/matlab/math/parameterizing-functions.html for how to create an anonymous function of one variable (to pass to fmincon) that in turn calls a different function with an extra parameter
nonlcon = @(x) your_nonlcon_function(x, current_alpha_value)

More Answers (1)

John D'Errico
John D'Errico on 30 Dec 2022
Edited: John D'Errico on 30 Dec 2022
You already know how to use fmincon. And surely you understand how to use a for loop.
  1. Set up a loop, varying a over the indicated domain.
  2. Call fmincon with the current value of a in the constraint, saving the results into a vector.
  3. After the loop has terminated, plot the results as a function of a.
Don't just provide the files, then asking us to write the complete code to solve your problem. Surely you can do exactly what I just explained in that basic algorithm. If then you have a problem, show what you tried. Explain where you are confused.

1 Comment

Having been on the other side, I know the frustration -- my intent was not to ask for someone to write the code but rather to refer me to appropriate documentation, if it existed. I thought about your suggestion beforehand, but I didn't think it'd be possible since I've defined my constraint in one script and I'm running fmincon in another. When I add a loop it just returns the minimization for the final value of a in the domain. In any case, I've used @Walter Roberson's answer to resolve this, and I think I can use a for loop now to finish. Thanks!

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 30 Dec 2022

Commented:

on 30 Dec 2022

Community Treasure Hunt

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

Start Hunting!