フィルターのクリア

Using fmincon for objective function with symbolic variable.

9 ビュー (過去 30 日間)
Shivanagouda Biradar
Shivanagouda Biradar 2023 年 5 月 1 日
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 Center および File ExchangeSolver 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