How to build a growing square matrix with the following values?

1 回表示 (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 2 月 17 日
編集済み: Ibro Tutic 2017 年 2 月 17 日
I am working on some code to find the condition of a spring matrix. I know the matrix in question, but I am not sure how to create a for-loop to make a bigger matrix after every iteration. In general, the matrix looks something this:
Considering the simple case where k1=k2=kn=1.
How would I go about constructing this matrix, computing a condition, then constructing a bigger matrix, computing the condition, and so on?

採用された回答

Akira Agata
Akira Agata 2017 年 2 月 17 日
I think this code will generate the matrix.
n = 10;
k = ones(n+1,1);
for kk = 1:n
A = - diag(k(1:kk)) - diag(k(2:kk+1));
if kk>1
A = A + diag(k(2:kk),-1) + diag(k(2:kk),1);
end
% To display the matrix for each loop
A
end
The value k_1 ~ k_n in your picture corresponds to the array k in this script.
  1 件のコメント
Ibro Tutic
Ibro Tutic 2017 年 2 月 17 日
編集済み: Ibro Tutic 2017 年 2 月 17 日
Thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by