Why are the return results of the fcn2optimexpr function different between MATLAB2019b and MATLAB2023b?

조회 수: 2 (최근 30일)
My codes is for solving a optimization programming ,therefore, the uplevel objective function needs to the optimal value of the downlevel objective function. I adopt Problem-based optimization way to describe the problem,fcn2optimexpr function is used to construct the uplevel objective function . The key code part is as follows:
..................
x = optimvar('x',2,1,'Type','continuous','LowerBound',0,'UpperBound',1);
[f,exitflag] = fcn2optimexpr(@mubiaofunction,x)
prob = optimproblem('ObjectiveSense','min');
prob.Objective = f;
.................
function [f,exitflag]=mubiaofunction(x)
y = optimvar('y',2,1,'Type','continuous','LowerBound',0,'UpperBound',1);
end
It can be seen that I want to construct an optimization express f for function mubiaofunction(x), this function obtain solution results of the downlevel optimization problem about variables y, however when I run the code in MATLAB2023b, the output display is:
It can be seen the f only contains uplevel variables x
when I run the same code in MATLAB2019b, the output display is:
I can judge that the results of MATLAB2019b are correct, However, I need to call the ga function to solve this Problem-based optimization model. As far as I know, The solve function can only be called ga in matlab2023b version, so how should I solve this puzzle I raised?

채택된 답변

Alan Weiss
Alan Weiss 2024년 2월 15일
I think that you need to turn off static analysis:
[f,exitflag] = fcn2optimexpr(@mubiaofunction,x,Analysis="off")
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Du Wei
Du Wei 2024년 2월 16일
It's a great honor to get your help.I just tested it and confirmed that your suggestion can solve the problem. I would like to express my sincere thanks to you!
Best Wishes! Du Wei

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by