How to build a matrix with "sum" function in its elements?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohamed Abdullah
el 9 de Abr. de 2020
Editada: Walter Roberson
el 10 de Abr. de 2020
Hello everyone, I am building an mpc controller in matlab rather than using the built in 'mpc command'. I am facing some difficulties in building the mpc's matrices I thought about using for loop.my question is how to use for loop to generate these matrices? ...thanks in advance
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283206/image.png)
2 comentarios
Walter Roberson
el 9 de Abr. de 2020
Is it imposed on you that you must use a for loop, rather than a vectorized solution like I show?
Respuesta aceptada
Walter Roberson
el 10 de Abr. de 2020
Editada: Walter Roberson
el 10 de Abr. de 2020
Outline, not checked in detail against Su,b matrix requirements
CAn = Cb;
TCAn = 0;
TCAB = 0;
for K = 1 : p
%Sub
CAB = CAn * Bu;
TCAB = TCAB + CAB;
%now store TCAB into appropriate locations in Sub
insert storage code here
%Sxb
CAn = CAn * A;
TCAn = TCan + CAn;
%now store TCAN into appropriate locations in Sxb
end
0 comentarios
Más respuestas (1)
Walter Roberson
el 9 de Abr. de 2020
sxb = C(b) .* cumsum(A.^(1:p)) .';
You might then want to
Sub = flipud(hankel(flipud(sxb)))
3 comentarios
Walter Roberson
el 9 de Abr. de 2020
If Cb is a matrix, then Sx,b would not be p x 1 as required by the diagram -- not even if A is also a matrix.
If A is a matrix, then for A^2 to exist then A would have to be a square matrix, same number of rows and columns. Call that m x m . Then if Cb is q x r, in order for Cb * A^2 to be scalar, either Cb and A are scalar, or else r = m and q x m * m x m -> q x m would have to be scalar, which could only happen if q = m = 1 so both scalar.
The logic is a bit different if A^n is intended ot indicate A.^n (each element individually raised to the power.) In such a case, if A is m x n then A.^2 would be m x n, and Cb * A^2 could be scalar if Cb is 1 x m and A is m x 1. Is that what is happening?
Mohamed Abdullah
el 10 de Abr. de 2020
Editada: Mohamed Abdullah
el 10 de Abr. de 2020
Ver también
Categorías
Más información sobre Model Predictive Control Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!