Code verification for multiple nonlinear constraints

1 Ansicht (letzte 30 Tage)
Oladunjoye
Oladunjoye am 27 Mär. 2014
Bearbeitet: Oladunjoye am 27 Mär. 2014
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?

Antworten (0)

Kategorien

Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by