From equation to matrix with for loop
古いコメントを表示
How can somone change equation into matrix with a for loop? For example if you have something like this:
for i = 1:10
1*x(i) + 2*x(i+1) + 3*x(i+2) = y(i)
end
So, if I were to do this by hand it would be like for i =1
[ 1 2 3 ] * [ x(1) x(2) x(3)]' = y(1)
and for i = 2 you will have
[ 1 2 3 ] * [x(2) x(3) x(4)]' = y(2)
so how can I structure this in a way it gives me a matrix that looks like this:
[ 1 2 3 0; 0 1 2 3] * [x(1) x(2) x(3) x(4)]' = [y(1); y(2)]
2 件のコメント
Bopha NEAK
2021 年 9 月 18 日
for i = 1:10
1*x(i) + 2*x(i+1) + 3*x(i+2) = y(i)
end
Image Analyst
2021 年 9 月 18 日
@Bopha NEAK, You can't have the y be on the right side of the equal sign. It must be on the left. See my answer below.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!