필터 지우기
필터 지우기

Incorrect dimensions for matrix multiplication

조회 수: 4 (최근 30일)
Gautami Golani
Gautami Golani 2019년 3월 7일
댓글: Adarsh Ghimire 2019년 3월 9일
%Load the data
load data.mat;
%Extracting first 500 points
z = [y(1:500) u(1:500)];
%Plotting the data
figure(1)
idplot(z);
%Using sampling interval of 80ms
figure(1)
idplot(z, 1:500, 0.08);
%Reserving the remaining data
zr = [y(501:1000) u(501:1000)];
%Removing constant levels and making data zero mean
z = dtrend(z);
zr = dtrend(zr);
%Loss function calaculation
V = arxstruc(z, zr, struc(2,2, 1:10));
value = V(1,:);
nk_value = min(value);
V = arxstruc(z, zr, struc(1:5, 1:5, 3));
%Searching for settled-in point
nns = selstruc(V);
i=1;
%Model structure
for na = 1:5
for nb = 1:5
val(i,:) = na+nb;
th = arx(z,[na, nb, 3]);
mse(i,:) = [th.Report.Fit.MSE];
a = th.a;
b = th.b;
ysim = idsim(zr(:, 2), th);
i=i+1;
matx = [val mse];
A = matx;
[A1u,~,idx] = unique(A(:,1));
MinVals = accumarray(idx, A(:,2), [], @(x)min(x));
Result = [A1u, MinVals];
m_one = Result(:,1);
m_two = Result(:,2);
figure(2)
plot(m_one, m_two)
title('Complexity vs Loss Function');
xlabel('Complexity');
ylabel('Loss Function');
end
end
%A-parameter and B-parameter
th = arx(z,[4 4 3]);
th = sett(th, 0.08);
present(th);
A=th.a
B=th.b
%Least Square Estimation
i = 1;
for k=6:length(z)
phi(i,1:5) = [-z(k-1,1) -z(k-2,1) z(k-3,2) z(k-4,2) z(k-5,2)];
i = i+1;
end
Y = z(6:end,1);
L = inv(phi'*phi)*phi*Y;
Getting an error that says 'Incorrect dimensions for matrix multiplication.'
Can anyone explain why this error comes up?
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 3월 7일
This code requires idplot(), which existing in the MATLAB 3 (1987) to MATLAB 5 (1997) timeframe and which was removed from MATLAB before R13. A copy of the source appears to be at http://research.jisao.washington.edu/vimont_matlab/System/idplot.html

댓글을 달려면 로그인하십시오.

답변 (1개)

Adarsh Ghimire
Adarsh Ghimire 2019년 3월 7일
편집: Adarsh Ghimire 2019년 3월 7일
L = inv(phi ' * phi ) * phi' * Y;
your phi matrix dimension has to transposed to multiply with y. As i went through your code, I found that
dimensions:
phi = (z-6) x 6
and y = (z-6)x1
so transposing your phi and multiply with y will get you 6x1 matrix which can multiply with inverse result of 6x6 so you get 6x1 matrix as your L.
  댓글 수: 6
Gautami Golani
Gautami Golani 2019년 3월 8일
I found out the size of phi and Y. The sze of phi is 500 5 and that of Y is 495 1.i
Adarsh Ghimire
Adarsh Ghimire 2019년 3월 9일
then you manage the dimension

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by