MATLAB: How to build a matrix with “sum” function in its elements

MATLABmpc

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

Best Answer

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