function [c, cjac] = confun(mode, ncnln, n, needc, x, cjac, nstate) % Routine to evaluate the nonlinear constraints and their 1st derivatives. % Function Body if nstate % First call to confun. Set all Jacobian elements to zero. cjac = zeros(ncnln,n); end if needc(1) > 0 if mode == 0 || mode == 2 c(1) = x(1) * x(1) + x(2) * x(2) + x(3) * x(3) + x(4) * x(4); end if mode == 2 cjac(1,1) = x(1) * 2.0; cjac(1,2) = x(2) * 2.0; cjac(1,3) = x(3) * 2.0; cjac(1,4) = x(4) * 2.0; end end if needc(2) > 0 if mode == 0 || mode == 2 c(2) = x(1) * x(2) * x(3) * x(4); end if mode == 2 cjac(2,1) = x(2) * x(3) * x(4); cjac(2,2) = x(1) * x(3) * x(4); cjac(2,3) = x(1) * x(2) * x(4); cjac(2,4) = x(1) * x(2) * x(3); end end endfunction