Problem with optimization function fcn2optimexpr
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Andrea Mazzetto
il 14 Giu 2021
Commentato: Andrea Mazzetto
il 15 Giu 2021
Hi, everyone.
I guess I have a simple problem but there's something that i miss. I'm experiencing this error when i try to optimize a function with 8 optimization variables:
"Error using fcn2optimexpr (line 103)
Function evaluation failed while attempting to determine output size. See error cause below. The function might contain an error, or might not be
well-defined at the automatically-chosen point. To specify output size without function evaluation, use 'OutputSize'.
Error in curvatura_V7 (line 27)
obj = fcn2optimexpr(@objfun,rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4);
Caused by:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix
powers, use '.^'."
The function is as follows:
function erroredistanza = objfun(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4)
deltay = 60;
deltax = 3;
tau0 = 90;
tau0 = deg2rad(tau0);
dmin = 3;
roi1=0;
si1=0;
PSI1 = @(roi1,rof1,si1,sf1,s) tau0 + ((rof1*si1-roi1*sf1)/(si1-sf1))*s + ((roi1-rof1)/(si1-sf1))*(s^2)/2;
PSI2 = @(rof1,rof2,sf1,sf2,s) ((rof2*sf1-rof1*sf2)/(sf1-sf2))*s + ((rof1-rof2)/(sf1-sf2))*(s^2)/2;
PSI3 = @(rof2,rof3,sf2,sf3,s) ((rof3*sf2-rof2*sf3)/(sf2-sf3))*s + ((rof2-rof3)/(sf2-sf3))*(s^2)/2;
PSI4 = @(rof3,rof4,sf3,sf4,s) ((rof4*sf3-rof3*sf4)/(sf3-sf4))*s + ((rof3-rof4)/(sf3-sf4))*(s^2)/2;
funx1 = @(roi1,rof1,si1,sf1,s) integral(@(s) cos(PSI1(roi1,rof1,si1,sf1,s)),0,sf1);
funx2 = @(rof1,rof2,sf1,sf2,s) integral(@(s) cos(PSI2(rof1,rof2,sf1,sf2,s)),sf1,sf2);
funx3 = @(rof2,rof3,sf2,sf3,s) integral(@(s) cos(PSI3(rof2,rof3,sf2,sf3,s)),sf2,sf3);
funx4 = @(rof3,rof4,sf3,sf4,s) integral(@(s) cos(PSI4(rof3,rof4,sf3,sf4,s)),sf3,sf4);
funy1 = @(roi1,rof1,si1,sf1,s) integral(@(s) sin(PSI1(roi1,rof1,si1,sf1,s)),0,sf1);
funy2 = @(rof1,rof2,sf1,sf2,s) integral(@(s) sin(PSI2(rof1,rof2,sf1,sf2,s)),sf1,sf2);
funy3 = @(rof2,rof3,sf2,sf3,s) integral(@(s) sin(PSI3(rof2,rof3,sf2,sf3,s)),sf2,sf3);
funy4 = @(rof3,rof4,sf3,sf4,s) integral(@(s) sin(PSI4(rof3,rof4,sf3,sf4,s)),sf3,sf4);
funx = @(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) funx1(roi1,rof1,si1,sf1) + funx2(rof1,rof2,sf1,sf2) + funx3(rof2,rof3,sf2,sf3) + funx4(rof3,rof4,sf3,sf4);
funy = @(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) funy1(roi1,rof1,si1,sf1) + funy2(rof1,rof2,sf1,sf2) + funy3(rof2,rof3,sf2,sf3) + funy4(rof3,rof4,sf3,sf4);
fun2x =@(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) funx(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) - deltax;
fun2y =@(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) funy(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) - deltay;
fun3x =@(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) fun2x(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4).^2;
fun3y =@(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) fun2y(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4).^2;
d =@(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) sqrt(fun3x(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) + fun3y(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4));
erroredistanza = d(rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4) - dmin;
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!