How to use a matrix as input for NLARX
3 views (last 30 days)
Show older comments
Based on the text (see below in italic) for NLARX I would like to use a matrix to provide the u en y (input/output).
Comma-Separated Matrix Pair
Specify data as a comma-separated pair of real-valued matrices that contain input and output time-domain signal values. When you specify matrix-based data, the software assumes a sample time of 1 second. You can change the sample time after estimation by setting the property sys.Ts.
- For SISO systems, specify data as a pair of Ns-element numeric column vectors that contain uniformly sampled input and output time-domain signal values. Here, Ns is the number of samples.
- For MIMO systems, specify u,y as an input/output matrix pair with the following dimensions:
- u — Ns-by-Nu, where Nu is the number of inputs.
- y — Ns-by-Ny, where Ny is the number of outputs.
For multiexperiment data, specify data as a pair of Ne-by-1 cell arrays of matrices, where Ne is the number of experiments. The sample times of all the experiments must match.Single Matrix
Specify data as a single real-valued matrix with Ny+Nu columns that contain the output signal values followed by the input signal values. Note that this order is the opposite of the order used for the comma-separated matrix pair form of data. When you specify matrix-based data, the software assumes a sample time of 1 second. You can change the sample time after estimation by setting the property sys.Ts.
Also I want the matrix built up such that each line has a many inputs/outputs as the orders given in teh NLARX.
So in principal I have a x amount of meausurements (number of lines in the matrix) and the number input and output(columns) is equal to the orders
I have written a small code to test this but I get an error message.
Code:
Input_A = (1:5); Output_B = (5:-1:1);
Data = [Output_B Input_A];
Total_Data = [Data; Data];
for counter = 1:50
Total_Data = [Total_Data; Data];
end
sys_1 = nlarx(Total_Data,[5 5 1]);
Error:
>> sys_1 = nlarx(Total_Data,[5 5 0]);
Error using nlarx (line 409)
The number of inputs and outputs of the model must match that of the data.
0 Comments
Accepted Answer
Cris LaPierre
on 3 Apr 2023
Edited: Cris LaPierre
on 3 Apr 2023
I think this line in the Comma-Separated Matrix Pair description is the issue: "specify data as a pair of Ns-element numeric column vectors"
You have specified your Input_A and Output_B as row vectors. I think if you make them column vectors, the error is resolved.
Input_A = (1:5)'; % Transpose so this is a column vector
Output_B = (5:-1:1)'; % Transpose so this is a column vector
Data = [Output_B Input_A];
Total_Data = [Data; Data];
for counter = 1:50
Total_Data = [Total_Data; Data];
end
sys_1 = nlarx(Total_Data,[5 5 1])
11 Comments
Rajiv Singh
on 10 Apr 2023
15 inputs and 15 output channels can be difficult to model using a single system. I would suggest looking closely at the dynamics to see if some channels can be removed (using PLCA, PLS etc). Another thing to try would be to create a separate model for each output.
That said, the easiest way to crate regressors would be using commands such as linearRegressor, polynomialRegressor, etc.
Example:
uvars = "u"+(1:15);
yvars = "y"+(1:15);
R1 = linearRegressor([uvars, yvars],1:3)
R2 = polynomialRegressor(uvars,1:2:7,2,false,true)
R3 = polynomialRegressor(yvars(1:4),1:3,3)
etc.
model = idnlarx(yvars,uvars,[R1;R2;R3],idSigmoidNetwork)
model2 = nlarx(udata, ydata, model)
If you want to use an order matrix to generate the (linear) regressors, please look at the right syntax to use on the idnlarx, or nlarx reference page. Basically, order matrix has the form N = [na nb nk], where na is Ny-by-Ny matrix, and nb/nk are Ny-by-Nu matrices (where Ny denotes the number of outputs, and Nu denotes the number of inputs).
If you run into any errors, please post reproduction steps.
Rajiv
More Answers (0)
See Also
Categories
Find more on Nonlinear ARX Models 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!