How to use "recursiveLS( )" and "step( )" functions
10 views (last 30 days)
Show older comments
I have a model in this way:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397234/image.png)
Where
are output variables and P is the input. All of the variables are column vectors.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397239/image.png)
This is my design matrix:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397244/image.gif)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397249/image.png)
N: total number of samples in my experiment.
I want to estimate the regression coefficients to calculate the next outputs
. I wrote this code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397254/image.png)
function rls = l_rls(T1, T2, P, lambda)
T1, T2 are vectors with the measured outputs and P is a vector of the measured input
N = length(P);
X = [ones(N-1, 1), T1(1:N-1), T2(1:N-1), P(2:N), P(1:N-1)]; %Design matrix
ncoef = size(X,2);
Y = [T1(2:end), T2(2:end)]; %These is my output matrix.
rls = recursiveLS(ncoef, lambda);
[A, Tst] = step(rls, Y, P)
end
However, when I run this code, I get this error message:
Error using recursiveLS/validateInputsImpl
Error in signal dimensions. The number of elements in the input signal u
(regressors) (5819) must match with the NumberOfParameters property (5).
Error in l_rls (line 10)
[As, Ts] = step(rls,Y,P);
If I change the line with "step" function:
[A, Tst] = step(rls, Y, X);
The error message is now:
Error using recursiveLS/validateInputsImpl
Error in signal dimensions. The input signal u (Regressors) must be a vector.
Error in l_rls (line 10)
[A, Tst] = step(rls,Y,X);
I can't understand how to use "step( )" function to obtain coefficients and estimated outputs.
3 Comments
Mario Malic
on 31 May 2023
There are not many people who use this toolbox, unfortunately and I am new with it.
You probably are not calling the function correctly, if I understood correctly the documentation, size of ncoef and lambda has to be the same.
If you want to do step, try iddata function, then estimate parameters by some of the functions like idgrey, nlarx, era and then apply step.
Take this with grain of salt because I don't understand completely what are we doing with these functions.
Answers (1)
Valeria Alejandra
on 27 Aug 2024 at 12:15
Edited: Valeria Alejandra
on 27 Aug 2024 at 12:42
I think the parameters of the function are wrong. You should use your output vector and a regressors vector. You are using your input as regressor vector
[A, Tst] = step(rls, Y, P);
The regressors are the elements of the equation. For example, in this model
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1760734/image.png)
there are two coeficients (one for each element of the equation), and the regresors of the system will be those elements, so
ncoef = 2; % a_1 and a_2 (two elements)
H = [u(t), u(t-1)]; % notice that it is a vector of two elements
Then, I would code it this way
rls = recursiveLS(ncoef);
for t = 2:Length(P) % where "P" is your vector of measurements
y = y(t); % Im not sure about this, but here you have to put your output vector
H = [u(t), u(t-1)]; % notice that this is an array of two elements
%(the same size than the number of parameters)
[params, output] = rls(y, H); % I think is the same than [params, output] = step(rls, y, P)
end
Or something like that haha
0 Comments
See Also
Categories
Find more on Preprocess Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!