How to convert an optimization variable to symbolic variable?

조회 수: 10 (최근 30일)
B. Berk
B. Berk 2022년 8월 9일
댓글: B. Berk 2022년 8월 9일
Hi everyone,
I need to convert an optimization variable that created by 'optimvar' command to a symbolic variable. I couldn't find any converter funtion for this one. I have a polynom consists of optimization variables, and i want to replace found values of some optimization variables in this polynom. If you know any other method for doing this, please let me know.

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 9일
It does not appear to be documented, but use optimexpr2fcn() on the optimization expression, to get back a function handle to a .m that it will write in your current directory. The resulting function will expect only a single input that is a vector, all of the inputs concatenated together.
For example,
x = optimvar('x',3,2);
y = optimvar('y',1,2);
expr = sum(x,1) - 2*y;
syms X [3 2]
syms Y [1 2]
h = optimexpr2fcn(expr)
h = function_handle with value:
@exprfcn
h([X(:); Y(:)])
ans = 
  댓글 수: 1
B. Berk
B. Berk 2022년 8월 9일
I did a lot of research, however, couldn't see this optimexpr2fcn function. Looks like it wil solve my problem. If I can't solve it, I'll write here again if you don't mind.
Sincerely thanks.

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

추가 답변 (1개)

Matt J
Matt J 2022년 8월 9일
You can use the evaluate() command to substitute in values.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 8월 9일
However you can only evaluate at double, not at symbolic locations.

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by