Code verification for multiple nonlinear constraints

2 次查看(过去 30 天)
Hi everyone,
I am using fmincon and I have a couple of nonlinear equality constraints. I wish to know which of the codes below is correct for the constraint.
function [c,ceq] = const(x)
c = [];
ceq(1) = x(1)'*x(1) + x(2)'*x(2) + x(3)'*x(3)+ x(4)'*x(4) + x(5)'*x(5) ...
+x(6)'*x(6) - 1;
ceq(2) = x(7)'*x(7) + x(8)'*x(8) + x(9)'*x(9)+ x(8)'*x(10) + ...
x(11)'*x(11) +x(12)'*x(12) - 1;
end
OR
function [c,ceq] = const(x)
c = [];
f1 = x(1)'*x(1) + x(2)'*x(2) + x(3)'*x(3)+ x(4)'*x(4) + x(5)'*x(5) ...
+x(6)'*x(6) - 1;
f2 = x(7)'*x(7) + x(8)'*x(8) + x(9)'*x(9)+ x(10)*x(10) + x('11)*x(11) ...
+x(12)'*x(12) - 1;
ceq = [f1,f2];
end
Which of the above codes is the correct way to write the constraints?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver-Based Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by