PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/other/Matlab/detection/solve_saddle.m

http://github.com/jbeezley/wrf-fire
Objective C | 38 lines | 36 code | 2 blank | 0 comment | 3 complexity | f4474a787deeee7ef495e2ff9f2d13ad MD5 | raw file
Possible License(s): AGPL-1.0
  1. function delta=solve_saddle(C,H,F,V,invA)
  2. %
  3. % delta=solve_saddle(C,H,F,V,invA)
  4. %
  5. % solve the saddle point problem
  6. %
  7. % A*delta + C*lambda = A*H + F
  8. % C'*delta = V
  9. %
  10. % input:
  11. % C column vector, may be given as matrix
  12. % H column vector, may be given as matrix
  13. % F column vector, may be given as matrix
  14. % invA function to multiply by the inverse of square matrix A
  15. % if the inputs are not column vectors they are reshaped into columns
  16. % for computations and the output reshaped back
  17. % eliminate delta and compute lambda:
  18. % delta = inv(A)*(A*H + F - C*lambda) = H + inv(A)*(F - C*lambda)
  19. % V = C'*delta
  20. % V = C'*(H + inv(A)*(F - C*lambda))
  21. % V = C'*(H + inv(A)*F) - C'*inv(A)*C*lambda
  22. % C'*inv(A)*C*lambda = C'*(H + inv(A)*F) - V
  23. % lambda = C'*inv(A)*C \ (C'*(H + inv(A)*F) - V)
  24. %
  25. invA_C = invA(C);
  26. invA_F = invA(F);
  27. R = H+invA_F;
  28. S=C(:)'*invA_C(:);
  29. lambda = S \ (C(:)'*R(:) - V);
  30. delta = R - invA_C*lambda;
  31. err_C=big(C(:)'*delta(:))/(big(C)*big(delta));
  32. tol=100*eps*sqrt(prod(size(C)));
  33. if err_C > tol,
  34. warning(['Large relative error ',num2str(err_C),' in the constraint'])
  35. end
  36. end