cost_est.asv
上传用户:doryuen
上传日期:2013-10-30
资源大小:23k
文件大小:1k
源码类别:

通讯/手机编程

开发平台:

Matlab

  1. function [cost, theta]=cost_est(A,b,p)
  2. %
  3. %
  4. %
  5.         limda=limda_est(A,b,p)
  6.         flag(1:length(limda))=0;
  7.         if limda(1) ~= -1
  8.             for m=1:length(limda)
  9.                 t_theta(:,m)=inv(A'*A+limda(m)*p)*A'*b;
  10.                 if t_theta(3,m)>0
  11.                     flag(m)=1;
  12.                 end
  13.             end
  14.             
  15. %             for m=1:length(limda)
  16. %                 if t_theta(3,m)<0  % || abs(theta(1)^2+theta(2)^2-theta(3)^2)>50
  17. %                     cost=-1;
  18. %                     theta=[-1 -1 -1]';
  19. %                 else
  20. %                     cost=(A*t_theta(:,m)-b)'*(A*t_theta(:,m)-b);
  21. %                     theta=t_theta(:,m);
  22. %                 end
  23. %             end
  24.         else
  25.             theta=[-1 -1 -1]';
  26.             cost=-1;
  27.         end
  28.         
  29.             
  30.