I am looking to generate an 8x8 tridiagonal matrix with random integers, how do I do this?
10 views (last 30 days)
Show older comments
n = 10
full(gallery('tridiag',n,rand,rand,rand))
0 Comments
Answers (2)
Guillaume
on 9 Feb 2016
Edited: Guillaume
on 9 Feb 2016
You're nearly there. Rather than passing a scalar, pass 3 random vectors. If you want integers, use randi to generate them:
n = 8; %size of matrix
range = [1 50]; %range of integers
full(gallery('tridiag', n, randi(range, 1, n-1), randi(range, 1, n), randi(range, 1, n-1)))
himanshu kumar
on 6 Oct 2017
n = 10;
x=round(10*rand()); % random integer Value between [0 10]
y=round(10*rand()); % random integer Value between [0 10]
z=round(10*rand()); % random integer Value between [0 10]
full(gallery('tridiag',n,x,y,z))
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!