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

通讯/手机编程

开发平台:

Matlab

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