how to develop n order matrix?

i wish to make a matrix of nth order fromm K=[2000,-1000,0,0;-1000,2000,-1000,0;0,-1000,2000,-1000;0,0,-1000,1000; so on to nth order]
can anyone please help me with this ...

3 件のコメント

Jan
Jan 2021 年 3 月 19 日
編集済み: Jan 2021 年 3 月 19 日
The explanation is not clear yet. What do you call "n.th order"?
It is getting a liitle bit easier to guess, if you post the matrix in 2D:
K = [2000, -1000, 0, 0; ...
-1000, 2000, -1000, 0; ...
0, -1000, 2000, -1000; ...
0, 0, -1000, 1000;
But why is the last element 1000 and not 2000?
Jasneet Singh
Jasneet Singh 2021 年 3 月 19 日
編集済み: Jan 2021 年 3 月 19 日
its because last element is not hinged or fixed. so, there is only 1 force=1000 acting on it.
Walter Roberson
Walter Roberson 2021 年 3 月 19 日
K=[2000,-1000,0,0;-1000,2000,-1000,0;0,-1000,2000,-1000;0,0,-1000,1000]
K = 4×4
2000 -1000 0 0 -1000 2000 -1000 0 0 -1000 2000 -1000 0 0 -1000 1000

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

回答 (2 件)

Jan
Jan 2021 年 3 月 19 日
編集済み: Jan 2021 年 3 月 19 日

0 投票

With some guessing: You want a tridiagonal matrix with the right bottom element changed. Then:
n = 4;
K = diag(repmat(2000, 1, n)) + ...
diag(repmat(-1000, 1, n-1), 1) + ...
diag(repmat(-1000, 1, n-1), -1)
or
K = zeros(n, n);
nn = n * n;
n1 = n + 1;
K( 1:n1:nn) = 2000;
K(n1:n1:nn) = -1000;
K( 2:n1:nn-n) = -1000;
or
K = toeplitz([2000, -1000, zeros(1, n - 2)])
or
K = full(gallery('tridiag', n, -1000, 2000, -1000))
or
K = conv2(eye(n), [-1000, 2000, -1000], 'same')
any finally:
K(n, n) = 1000;
Or directly:
K = diag([repmat(2000, 1, n - 1), 1000]) + ... % Last element adjusted
diag(repmat(-1000, 1, n - 1), 1) + ...
diag(repmat(-1000, 1, n - 1), -1)

7 件のコメント

Jasneet Singh
Jasneet Singh 2021 年 3 月 19 日
can you please specify how you did this ?
Jan
Jan 2021 年 3 月 19 日
編集済み: Jan 2021 年 3 月 19 日
How I did what?
I've added changing the last element to 1000.
Jasneet Singh
Jasneet Singh 2021 年 3 月 19 日
i mean from where can i learn this codes from to make my life easier? like one you have used recenty for coding..
Jan
Jan 2021 年 3 月 19 日
編集済み: Jan 2021 年 3 月 19 日
In your case it helps to recognize, that you want almost a "tridiagonal matrix". Then asking an internet search engine for "Matlab tridiagonal" finds matching code snippets. But if you do not know the term "tridiagonal", it is really hard to find matching keywpord. Then asking here in the forum is a very good method to let others find the keywords and to learn MATLAB. This is the purpose of this forum.
Jasneet Singh
Jasneet Singh 2021 年 3 月 22 日
for omegaf_4=[0:1:80] % forcing frequency w4 form 1:80 with a resolution of 1Hz
F_b=[0;0;1;0];
D4=(-(omegaf_4^2).*M+K+(i*omegaf_4.*C));
d=(F_b.*D4^-1) % amplitude(d) for mass4 from the system
for d=(F_b.*D4^-1);
x= (abs(F_b./d)*1)
omegaf_4=[0:1:80]
end
can u help me plot values from 80 different matrices as a function of omegaf_4?
Jasneet Singh
Jasneet Singh 2021 年 3 月 22 日
specifically for x w.r.t omega..
Jan
Jan 2021 年 3 月 22 日
This is a new question. Please post it as a new thread.

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

Walter Roberson
Walter Roberson 2021 年 3 月 19 日

0 投票

n = 7;
MD = 2000*ones(1,n);
SD = -1000*ones(1,n-1);
K = diag(MD) + diag(SD,1) + diag(SD,-1)
K = 7×7
2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000
Or:
n = 7;
K = zeros(n,7);
K(1:n+1:end) = 2000;
K(2:n+1:end) = -1000;
K(n+1:n+1:end) = -1000;
K
K = 7×7
2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000 -1000 0 0 0 0 0 -1000 2000

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2021 年 3 月 19 日

コメント済み:

Jan
2021 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by