Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to do a matrix from a loop for several values of a constant?

1 回表示 (過去 30 日間)
Germán Loredo
Germán Loredo 2017 年 9 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
So I am trying to have a 4x10 matrix called Y by using a for loop for each value of a. I just don't know how to do it. I know I could do this manually by defining y1 with a=.5, y2 with a=.9,...y4 with a=1.1 and running the loop for each one but I want the computer do it all. This for solving a more complex problem. Thanks in advance!
e=rand(1,10);
a=[.5,.9,1,1.1]
y=ones(1,10);
for i=2:10;
y(i)=a*y(i-1)+e(i-1); %I want a matrix of Y which contains this loop for each value
of a stated above.
end

回答 (1 件)

Jose Marques
Jose Marques 2017 年 9 月 9 日
Hello Germán Loredo! Try this:
clear all;
close all;
clc;
e=rand(1,10)
a=[.5,.9,1,1.1]
y=ones(4,10);
for i=1:10;
for k=1:4
y(k,i)=a(k)*y(i)+e(i); %I want a matrix of Y which contains this loop for each value
end
end
  10 件のコメント
Germán Loredo
Germán Loredo 2017 年 9 月 9 日
編集済み: Germán Loredo 2017 年 9 月 10 日
This result goes along with: When a>=1, E(y)should go to infinite when n goes infinite. As when a<1 E(y) converge to a number when n goes to infinity.
Jose Marques
Jose Marques 2017 年 9 月 9 日
Nice! = D

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by