Code verification for multiple nonlinear constraints

2 views (last 30 days)
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?

Answers (0)

Community Treasure Hunt

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

Start Hunting!