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!

 채택된 답변

Walter Roberson
Walter Roberson 2022년 12월 30일

0 개 추천

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)

추가 답변 (1개)

John D'Errico
John D'Errico 2022년 12월 30일
편집: John D'Errico 2022년 12월 30일

0 개 추천

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

Kenneth
Kenneth 2022년 12월 30일
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!

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

제품

릴리스

R2022a

질문:

2022년 12월 30일

댓글:

2022년 12월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by