悬赏 100 个论坛币 未解决
师门传承的求条件期望matlab程序,对数据要求很高,经常出现呢Warning: Matrix is singular to working precision. 错误,现在请求高手帮忙看下是什么问题:
%输入:ck为窗宽矩阵,d为数据矩阵,其中最后列为条件项
%输出:mpz期望矩阵,uz原数值与期望的差值矩阵,mppz偏导数矩阵
程序如下:
hah=size(d);
n=hah(1);%the number of the observations
ll=hah(2);
llk=ll-1;
mpz=zeros(n,llk);
mppz=zeros(n,llk);
u=zeros(n,llk);
for nm=1:llk
%input data in it
x=d(:,ll);
y=d(:,nm);
h=ck(nm);
mp=zeros(n,1);
mpp=zeros(n,1);
p=ones(n,1);
for i=1:n
x0=[p x-x(i)];
w=zeros(n);
for j=1:n
e=((x(j)-x(i))/h)^2;
w(j,j)=0.75*(1-e)*(e<1);
end
a=inv(x0'*w*x0)*(x0'*w*y);
mp(i)=a(1);%It is the estimator of m(x)
mpp(i)=a(2);
end
u=y-mp;
mpz(:,nm)=mp;
mppz(:,nm)=mpp;
uz(:,nm)=u;
end