comparison scripts/optimization/qp.m @ 19833:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children f1d0f506ee78
comparison
equal deleted inserted replaced
19832:a1acca0c2216 19833:9fc020886ae9
271 endif 271 endif
272 272
273 if (! isempty (A_lb) && ! isempty (A_ub)) 273 if (! isempty (A_lb) && ! isempty (A_ub))
274 rtol = sqrt (eps); 274 rtol = sqrt (eps);
275 for i = 1:dimA_in 275 for i = 1:dimA_in
276 if (abs (A_lb(i) - A_ub(i)) < rtol*(1 + max (abs (A_lb(i) + A_ub(i))))) 276 if (abs (A_lb(i) - A_ub(i))
277 < rtol*(1 + max (abs (A_lb(i) + A_ub(i)))))
277 ## These are actually an equality constraint 278 ## These are actually an equality constraint
278 tmprow = A_in(i,:); 279 tmprow = A_in(i,:);
279 A = [A;tmprow]; 280 A = [A;tmprow];
280 b = [b; 0.5*(A_lb(i) + A_ub(i))]; 281 b = [b; 0.5*(A_lb(i) + A_ub(i))];
281 n_eq = n_eq + 1; 282 n_eq = n_eq + 1;
304 Ain(idx,:) = []; 305 Ain(idx,:) = [];
305 306
306 n_in = numel (bin); 307 n_in = numel (bin);
307 308
308 ## Check if the initial guess is feasible. 309 ## Check if the initial guess is feasible.
309 if (isa (x0, "single") || isa (H, "single") || isa (q, "single") || isa (A, "single") 310 if (isa (x0, "single") || isa (H, "single") || isa (q, "single")
310 || isa (b, "single")) 311 || isa (A, "single") || isa (b, "single"))
311 rtol = sqrt (eps ("single")); 312 rtol = sqrt (eps ("single"));
312 else 313 else
313 rtol = sqrt (eps); 314 rtol = sqrt (eps);
314 endif 315 endif
315 316
406 endif 407 endif
407 408
408 endfunction 409 endfunction
409 410
410 411
411 %% Test infeasible initial guess (bug #40536) 412 ## Test infeasible initial guess (bug #40536)
412 %!testif HAVE_GLPK 413 %!testif HAVE_GLPK
413 %! 414 %!
414 %! H = 1; q = 0; # objective: x -> 0.5 x^2 415 %! H = 1; q = 0; # objective: x -> 0.5 x^2
415 %! A = 1; lb = 1; ub = +inf; # constraint: x >= 1 416 %! A = 1; lb = 1; ub = +inf; # constraint: x >= 1
416 %! x0 = 0; # infeasible initial guess 417 %! x0 = 0; # infeasible initial guess