Using fmincon for objective function with symbolic variable.
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shivanagouda Biradar
el 1 de Mayo de 2023
Comentada: Shivanagouda Biradar
el 4 de Mayo de 2023
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.
0 comentarios
Respuestas (1)
Walter Roberson
el 1 de Mayo de 2023
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 comentarios
Alan Weiss
el 1 de Mayo de 2023
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
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!