Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Adapting an objective function to use it in fmincon when having nonlinear constrains in lsqnonlin.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear community, I need to find best fitting parameters to a 3D set of points for which I'm using fmicon. I've been able to solve this problem with lsqnonlin but now I need to impose a nonlinear inequality, therefore, I can't no longer use lsqnonlin. Here my first attempt
clear all
filename='3_POSTERIOR.csv';
data = csvread(filename);
x = data(:,1); y = data(:,2); z = data(:,3);
fun = @(a) a(1)*x.^2+a(2)*x.*y+a(3)*x.*z+a(4)*x+a(5)*y.^2+a(6)*y.*z+a(7)*y+a(8)*z.^2+a(9)*z+a(10);
fun = sum(fun(a).*fun(a));
x0 = [1,1,1,1,1,1,1,1,1,1];
a = fmincon(fun,x0);
And the error I'm getting is Undefined function or variable 'a'. In an attempt to fix it, I created a symbolic vector called a, but I get a different error:
Index exceeds matrix dimensions.
Error in sym/subsref (line 881)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in Prueba_1 copy>@(a)a(1)*x.^2+a(2)*x.*y+a(3)*x.*z+a(4)*x+a(5)*y.^2+a(6)*y.*z+a(7)*y+a(8)*z.^2+a(9)*z+a(10)
Error in Prueba_1 copy (line 9)
fun = sum(fun(a).*fun(a));
I'm pretty sure I'm defining the sum of squares function in a wrong way, but I really don't know. Any help will be appreciated.
Thanks.
0 Kommentare
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!