필터 지우기
필터 지우기

How to build a matrix with "sum" function in its elements?

조회 수: 2 (최근 30일)
Mohamed Abdullah
Mohamed Abdullah 2020년 4월 9일
편집: Walter Roberson 2020년 4월 10일
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
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 4월 9일
Is it imposed on you that you must use a for loop, rather than a vectorized solution like I show?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 10일
편집: Walter Roberson 2020년 4월 10일
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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 4월 9일
sxb = C(b) .* cumsum(A.^(1:p)) .';
You might then want to
Sub = flipud(hankel(flipud(sxb)))
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 4월 9일
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
Mohamed Abdullah 2020년 4월 10일
편집: Mohamed Abdullah 2020년 4월 10일
I think the only way to make the dimension of 'Sxb' as (PX1) is to deal with the whole block 'Sxb' as a cellarray block containing matrices.for example, let's say p=3, A matrix has size of (mXm) with m=3 and Cb matrix has size of (qXm) with q= 2. if we dealt with 'Sxb' as a Matrix, the final size of it will be (qXp,m):
Sxb=[C*A;
C*A^2+C*A;
C*A^3+C*A^2+C*A];
I have succeeded to build 'Sxb' with for loop as follows:
Sxb=cell(3,1);
>> Sxb{1,1}=zeros(2,3);
>> for p=1:1:3
Sxb{p,1}= C*A^p+Sxb{1,1};
Sxb{1,1}=Sxb{p,1};
end
but I still need some help to figure out how to build the other two blocks 'Sub' and 'Sdb'.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by