필터 지우기
필터 지우기

Using fmincon for objective function with symbolic variable.

조회 수: 9 (최근 30일)
Shivanagouda Biradar
Shivanagouda Biradar 2023년 5월 1일
댓글: Shivanagouda Biradar 2023년 5월 4일
clc
clear all
syms l12 l13 l14 l23 l24 l34 ...
l15 l16 l111 l112 l113 l114 ...
l27 l28 l215 l216 ...
l39 l310 l12 l13 l14 ...
l23 l24 ...
l34
a=1;
[r12star, r13star, r14star, r23star, r24star, r34star, L] = polygen(a);
Lapval=L;
t=det(Lapval([2:16],[2:16]));
r12=det(Lapval([3:16],[3:16]))/t;
r13=det(Lapval([2,4:16],[2,4:16]))/t;
r14=det(Lapval([2,3,5:16],[2,3,5:16]))/t;
r23=det(Lapval([1,4:16],[1,4:16]))/t;
r24=det(Lapval([1,3,5:16],[1,3,5:16]))/t;
r34=det(Lapval([1,2,5:16],[1,2,5:16]))/t;
rdstar=[r12star; r13star; r14star; r23star; r24star; r34star];
rd=[r12;r13;r14;r23;r24;r34];
[c,ceq] = pol_cons(x);
nonlcon = @pol_cons;
fun = @(x)transpose((rdstar-rd))*(rdstar-rd);
x0 = [1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon);
Here r12, r13, r14, r23, r24 and r34 are the function of symbolic variables as defined in at the start in code. r12, r13, r14, r23, r24 and r34 are huge polynomial functions in symbolic variable, which are also the unknowns to be optimized, r12star, r13star, r14star, r23star, r24star and r34star are known real numbers. How to manage such problems.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 5월 1일
fmincon does not care how you do the computation, but the value you return from the function must be a finite scalar real value, double precision or single precision.
You should probably use matlabFunction with the 'vars' option
  댓글 수: 2
Alan Weiss
Alan Weiss 2023년 5월 1일
For an example showing how to do what Walter suggests, see Calculate Gradients and Hessians Using Symbolic Math Toolbox.
Alan Weiss
MATLAB mathematical toolbox documentation
Shivanagouda Biradar
Shivanagouda Biradar 2023년 5월 4일
Thank you very much @Walter Roberson and @Alan Weiss. This is working.

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by