필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Adapting an objective function to use it in fmincon when having nonlinear constrains in lsqnonlin.

조회 수: 1 (최근 30일)
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개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by