How to set up a repeating series of terms

조회 수: 4 (최근 30일)
Bethany Bloomfield
Bethany Bloomfield 2021년 11월 1일
답변: Prateek Rai 2021년 11월 6일
Hi all
For the below code, I'm trying to set up a series where instead of just the most recent value of k, it increases the size of the matrix every time it runs, so it would be Xt = [ones(t-h+1,1), Lt*yt, Lt^2*yt, ... Lt^k*yt]
for k = 1:p
Xt = [ones(t-h+1,1), Lt^k*yt];
end
I know this code will only use the most recent value of k, so how would I be able to create it the way I described before? I'm pretty new to coding in general so apologies if this is a silly question.
  댓글 수: 3
Bethany Bloomfield
Bethany Bloomfield 2021년 11월 1일
Thank you very much.
I have a similar question with a different bit of code.
for k = 1:p
yhat(t-T0+1,:) = [1, y(t), y(t-k)]*betahat + uhat(end)*psi'
end
I can't quite get the 3rd solution working there, this is my code but it gives an incorrect dimensions error when trying to multiply the matrices
yhat(t-T0+1,:) = [1, y(t), y(t-(1:p))]*betahat + uhat(end)*psi'
DGM
DGM 2021년 11월 1일
I don't know what size any of these are, nor what the goal is.

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

답변 (1개)

Prateek Rai
Prateek Rai 2021년 11월 6일
To my understanding, you want to set up a repeating series of terms so that,
Xt = [ones(t-h+1,1), Lt*yt, Lt^2*yt, ... Lt^k*yt].
Here is a possible workaround:
cat = [];
for k = 1 : p
cat = [cat, Lt^k*yt];
Xt = [ones(t-h+1,1), cat];
end

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by