How do I take square roots of certain entries of a tridiagonal matrix?

2 views (last 30 days)
So I have a 50 by 50 tridiagonal matrix. The entries along the main diagonal are 0 and the entries above and below are -square root (k(N-k) where N is 50 and k is an integer from 1 to 50. I am completely new to matlab and have no programming experience. Can someone please help?

Accepted Answer

Guillaume
Guillaume on 3 Mar 2015
N = 50;
v = 1:N-1; %a 50x50 matrix only have 49 elements above and below diagonal
m = full(gallery('tridiag', -sqrt(v.*(N-v)), zeros(1, N), -sqrt(v.*(N-v))))
  3 Comments
Guillaume
Guillaume on 3 Mar 2015
Paste it in the command window, or a script, or a function, and try.
Also look up gallery documentation, particularly, the 'tridiag' option.
Once you've constructed your tridiagonal matrix, you can use it any way you see fit.

Sign in to comment.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!