Error using / Matrix dimensions must agree and Forward Linear Prediction

I'm trying to predict the future values of my data sample with the following code:
for n = 1:size(t,1)
if n>=3
X = [Ia(n-1,1) Ia(n-2,1) ; Ia(n-2,1) Ia(n-3,1)];
p = [Ia(n,1) ; Ia(n-1,1)];
C = X/p;
Ia_future(n,1) = C(1,1)*Ia(n,1)+C(2,1)*Ia(n-1,1)
erro(n,1)=Ia(n)+Ia_future(n,1)
end
end
Where Ia is the phase current a and t is the period, both have a length equal to 2400.
It ends up giving the following error in the operation C = X/p (Error using / Matrix dimensions must agree.)
Basically the operations I'm trying to reproduce are the ones in the equations below:
I need to find the error of each predicted value. However, it seems that what I am doing is not right.
x = Ia
fp = error
x^ = Ia_future
The matrix is 2x2 because the order of the prediction I want to get is 2. So I get a future value every 2 values, n>=3.

5 Comments

syms A [2 2]
syms p [2 1]
A\p
ans = 
A/p
Error using / (line 485)
Invalid operands.
Remember that A/p is similar to A*pinv(p) -- in context does it make sense to be taking the pseudo-inverse of the vector instead of the matrix ?
Okay, but even if I do p/X it accuses the same error. I have another similar program with the higher order and it's not giving the same error in the case, so it's bugging my mind.
X=[V_alfa(a-1,1) V_alfa(a-2,1) V_alfa(a-3,1) V_alfa(a-4,1);...
V_alfa(a-2,1) V_alfa(a-3,1) V_alfa(a-4,1) V_alfa(a-5,1);...
V_alfa(a-3,1) V_alfa(a-4,1) V_alfa(a-5,1) V_alfa(a-6,1);...
V_alfa(a-4,1) V_alfa(a-5,1) V_alfa(a-6,1) V_alfa(a-7,1)];
p=[V_alfa(a,1);V_alfa(a-1,1);V_alfa(a-2,1);V_alfa(a-3,1)];
C=X\p;
syms V_alfa [8 1]
a = 8
a = 8
X=[V_alfa(a-1,1) V_alfa(a-2,1) V_alfa(a-3,1) V_alfa(a-4,1);...
V_alfa(a-2,1) V_alfa(a-3,1) V_alfa(a-4,1) V_alfa(a-5,1);...
V_alfa(a-3,1) V_alfa(a-4,1) V_alfa(a-5,1) V_alfa(a-6,1);...
V_alfa(a-4,1) V_alfa(a-5,1) V_alfa(a-6,1) V_alfa(a-7,1)];
p=[V_alfa(a,1);V_alfa(a-1,1);V_alfa(a-2,1);V_alfa(a-3,1)];
C=X\p
C = 
Okay, but even if I do p/X it accuses the same error.
It is not clear what your X is here?
Note that, by definition,
A/B = (B'\A')'
So A\p is not the same as p/A -- you would need (p' / A')'
Ahhh, ok ok. Got it, thank you so much for your patience.

Sign in to comment.

Answers (0)

Categories

Asked:

on 8 Dec 2021

Commented:

on 8 Dec 2021

Community Treasure Hunt

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

Start Hunting!