matlab 错误分析 求高手指导(偏最小二乘)运行以后,出来的东西是这样的、怎么改呀Error using ==> mtimesInner matrix dimensions must agree.这是一个5个自变量1个因变量的程序,偏最小二乘法的求解问
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 15:27:53
matlab 错误分析 求高手指导(偏最小二乘)运行以后,出来的东西是这样的、怎么改呀Error using ==> mtimesInner matrix dimensions must agree.这是一个5个自变量1个因变量的程序,偏最小二乘法的求解问
matlab 错误分析 求高手指导(偏最小二乘)
运行以后,出来的东西是这样的、怎么改呀Error using ==> mtimesInner matrix dimensions must agree.这是一个5个自变量1个因变量的程序,偏最小二乘法的求解问题源程序是clc,clear load pz.txt %原始数据存放在纯文本文件pz.txt中mu=mean(pz);sig=std(pz);rr=corrcoef(pz);data=zscore(pz);n=5;m=1;x0=pz(:,1:n);y0=pz(:,n+1:end);e0=data(:,1:n);f0=data(:,n+1:end);num=size(e0,1);chg=eye(n);for i=1:nmatrix=e0'*f0'*f0'*e0;[vec,val]=eig(matrix);val=diag(val);[val,ind]=sort(val,'descend');w(:,i)=vec(:,ind(l));w_star(:,i)=chg*w(:,i);t(:,i)=e0*w(:,i);alpha=e0'*t(:,i)/t(:,i)'*t(:,i)';chg=chg*(eye(n)-w(:,i)*alpha');e=e0-t(:,i)*alpha'e0=e;beta=[t(:,1:i),ones(num,1)]\f0;beta(end,:)=[];cancha=f0-t(:,1:i)*beta;ss(i)=sum(sum(cancha,^2));for j=1:numt1=t(:,1:i);f1=f0;she_t=t1(j,:);she_f=f1(j,:);t1(j,:)=[];f1(j,:)=[];beta1=[t1,ones(num-1,1)]\f1;beta1(end,:)=[];cancha=she_f-she_t*beta1;press_i(j)=sum(cancha.^2);endpress(i)=sum(press_i);if i>1Q_h2(i)=1-press(i)/ss(i-1);elseQ_h2(1)=1;endifQ_h2(i)<0.0975fprintf('提出的成分个数r=%d',i);r=i;breakendendbeta_z=[t(:,1:r),ones(num,l)]\f0;beta_z(end,:)=[];xishu=w_star(:,1:r)*beta_z;mu_x=mu(1:n);mu_y=mu(n+1:end);sig_x=sig(1:n);sig_y=sig(n+1:end);for i=1:mch0(i)=mu_y(i)-mu_x./sig_x*sig_y(i)*xishu(:i);endfor i=1:mxish(:,i)=xishu(:i)./sig_x'*sig_y(i);endsol=[ch0;xish]save mydata x0 y0 num xishu ch0 xish
matlab 错误分析 求高手指导(偏最小二乘)运行以后,出来的东西是这样的、怎么改呀Error using ==> mtimesInner matrix dimensions must agree.这是一个5个自变量1个因变量的程序,偏最小二乘法的求解问
%只修改了一点语法错误,修正了向量维数,没对数据做任何修改: function demo_MOL clc;clear all;format long; n=15;dpi=pi/n; x=dpi:dpi:pi; size(x) u=sin(x); t=0.:0.4:40.; [t u]=ode45(@myfun,t,u); uu(:,2:n)=u(:,1:n-1); uu(:,1)=0;uu(:,n+1)=0; x=[0. x];[xx yy]=meshgrid(x,t); surf(xx,yy,uu); xlabel('x');ylabel('t');zlabel('u(x,t)'); end function y=myfun(~,u) n=15; x=zeros(1,n); x(1)=-2*u(1)+u(2); x(n-1)=u(n-2)-2*u(n-1); for i=2:n-2 x(i)=u(i-1)-2*u(i)+u(i+1); end y=x'; end
~