Error using mtimes Inner matrix dimensions must agree !!
1 次查看(过去 30 天)
显示 更早的评论
hi hope anyone can help me "Error using ==> mtimes Inner matrix dimensions must agree. Error in ==> Untitled at 28 y(t)=teta'*phi(:,t);" the code
- clear all
- close all
- clc
- N=1700;
- i=1:N;
- u(i)=sin(0.1*i)+sin(0.2*i)+sin(0.3*i)+sin(0.4*i)+sin(i)+sin(2*i)+sin(3*i)+sin(4*i);
- % identification
- %y(t)=-a1y(t-1)-b1y(t-2)+c1u(t-1)
- a1=0.5;b1=0.45;c1=0.8;
- teta0=zeros(N,3);
- %teta0=zeros(3,3);
- F(1)=0.01;
- F=zeros(1,N);
- %phi0=[0 0 0];
- y0(1)=0;
- a0=0;
- b0=0;
- c0=0;
- y(1)=0;
- y(2)=0;
- y0(2)=0;
- F(1)=0;
- for t=3:N ;
- phi(:,t)=[-y(t-1) -y(t-2) u(t-1)];
- phi0(:,t)=[y0(t-1) -y0(t-2) u(t-1)]';
- teta=[a1 b1 c1];
- y(t)=teta'*phi(:,t);
- y0(t)=teta0(t-1,:)'*phi(:,t);
- e(t)=y(t)-y0(t);
- teta0(t,:)=teta0(t-1,:)+(F(t-1)*phi(:,t)*e(t))'/(1+phi(:,t)'*F(t-1)*phi(:,t));
- F(t)=F(t-1)-((F(t-1)*phi(:,t-1)*phi(:,t-1)'*F(t-1))/(1+phi(:,t-1)'*F(t-1)*phi(:,t-1)'));
- end ;
- teta0(N,:)
2 个评论
Star Strider
2016-5-17
Norton Antivirus identifies your upload site as a know dangerouw website, and blocks it.
Use the brown-framed green landscape picture icon instead to upload it here.
the cyclist
2016-5-17
Also, please upload code, not a screenshot of code (which we cannot copy & paste and run if we want to).
回答(2 个)
Elias Gule
2016-5-17
Are you doing elementwise multiplication? If so, then replace the '*' operator with '.*' operator, Such that
phi0(:,t)=[y0(t-1) -y0(t-2)*u(t-1)]';
changes to
phi0(:,t)=[y0(t-1) -y0(t-2).*u(t-1)]';
0 个评论
Star Strider
2016-5-17
You had several errors that I discovered. Changing lines 28, 29 and 32 to:
y(t)=teta*phi(:,t);
y0(t)=teta0(t-1,:)*phi(:,t);
. . .
F(t)=F(t-1)-((F(t-1)*phi(:,t-1)'*phi(:,t-1)*F(t-1))/(1+phi(:,t-1)'*F(t-1)*phi(:,t-1)));
will do the matrix calculations without throwing any errors, and producing scalar results, as your scalar assignments require.
I leave it to you to determine if it gives the correct results.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!