Tri-diagonal Matrix with varying diagonals
Show older comments
I am trying to create a tri-diagonal matrix with ones and a diagonal that changes according to a function.
Right now I have
z=zeros(99,1); z(1)=25; z(2)=1; A=toeplitz(z)
where the 25 is just a placeholder number for now. The value of 25 is what I want to change according the following for loop of
n = 99;
h = 0;
for i = 1:n
h = h + 1/n;
z = (2 + (0.1)*(h)^2)/.01
end
This gives 99 values from 200 to 210, but they change by a non-constant amount.
One thought I had was to put these output into a vector and then just use the diag() command and add the other diag(1)'s to it. But when I use the code
vector = [z]
it only returns the last value of 210 to me, not all 99 different values.
How would I go about changing all of the diagonals to be the number output by the for loop? Preferably, I would also like the a_11 and a_99 to also just be 1 instead of the values of the function, if possible.
Thank you very much.
1 Comment
Kevin Osborn
on 4 Nov 2021
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!