2
|
5389 Views
|
8 Replies
|
11 Total Likes
View groups...
Share
GROUPS:

# How do I create a matrix that has a function as its values?

Posted 10 years ago
 I am trying to make a 50x50 matrix that has values in the +1 diagonally and the -1 diagonal that are a function of its position and then take the eigenvalue for the given matrix.For example: for a 5x5 matrix it would be as follows: [(0,x,0,0,0),(x,0,x,0,0),(0,x,0,x,0),(0,0,x,0,x),(0,0,0,x,0)] where x is a represented by the function (i(n-j))^(1/2) Here n is the size of the matrix (5), i is the row number and j is the column number. I also have to do this for a matrix that has the +1,-1 diagonals equal to -1 and then solve for the eigenvalues but have not had any luck doing so. I was wondering if someone could help me out with this. This is how I was attempting to do that problem. 1) a = SparseArray[{Band[{2, 1}] -> -1, Band[{1, 2}] -> -1}, {50, 50}] // MatrixForm 2)Eigenvalues[{a}] Line 1) creates a matrix exactly how it needs to be but, line 2) does not find the eigenvalues for the given matrix (a). Thank you very much for anyone that does pay this any attention. Andrew
8 Replies
Sort By:
Posted 10 years ago
 I am trying to make a 50x50 matrix that has values in the +1 diagonally and the -1 diagonal that are a function of its position and then take the eigenvalue for the given matrix.For example: for a 5x5 matrix it would be as follows: [(0,x,0,0,0),(x,0,x,0,0),(0,x,0,x,0),(0,0,x,0,x),(0,0,0,x,0)] where x is a represented by the function (i(n-j))^(1/2) Here n is the size of the matrix (5), i is the row number and j is the column number. I also have to do this for a matrix that has the +1,-1 diagonals equal to -1 and then solve for the eigenvalues but have not had any luck doing so. I was wondering if someone could help me out with this. This is how I was attempting to do that problem. 1) a = SparseArray[{Band[{2, 1}] -> -1, Band[{1, 2}] -> -1}, {50, 50}] // MatrixForm2)Eigenvalues[{a}]Line 1) creates a matrix exactly how it needs to be but, line 2) does not find the eigenvalues for the given matrix (a). Thank you very much for anyone that does pay this any attention. Andrew
Posted 10 years ago
 You had d = (a + b) // MatrixForm which makes d header become MatrixForm. This works n = 10; (a = SparseArray[{Band[{2, 1}] -> -1}, {n, n}]) // MatrixForm (b = SparseArray[{Band[{1, 2}] -> -1}, {n, n}]) // MatrixForm posa = Position[Normal@a, -1]; repa = -(Last@# ((n + 1) - First@#))^(1/2) & /@ posa; posb = Position[Normal@b, -1]; repb = -(First@# ((n + 1) - Last@#))^(1/2) & /@ posb; (a = ReplacePart[a, Thread[posa -> repa]]) // MatrixForm (b = ReplacePart[b, Thread[posb -> repb]]) // MatrixForm (d = (a + b)) // MatrixForm variable = g d[[1, 1]] += variable d[[n, n]] += variable MatrixForm[d]
Posted 10 years ago
Posted 10 years ago
 I was wondering if you could help me now with a way to add a variable in the (1,1) location and the (n,n) location and then solving for the eigenvalues. Do you mean add a number to the (1,1) and (n,n) locations after doing the above? You mean just like this: variable = 99; a[[1, 1]] += variable; a[[n, n]] += variable; MatrixForm[a] Now you can use Eigenvalue command on it.
Posted 10 years ago
 I was wondering if you could help me now with a way to add a variable in the (1,1) location and the (n,n) location and then solving for the eigenvalues. My professors have no idea how to do this. I REALLY appreciate your help thus far. Thank you, Andrew
Posted 10 years ago
 The problem was when I found the Eigen values they were not given as numbers but as an exact interpretation. If you apply N on it, it gives the numbers. This still leaves me with the question on how I make a matrix with the +1,-1 diagonals as a function of their position. The matrix you had, has -1 on the diagonals? Not -1 and +1. But if you want to replace all those -1 with values given by (i (n - j))^(1/2) where n is the size of the matrix, and i is the row number, and j is the column number, then one way is n = 5; (a = SparseArray[{Band[{2, 1}] -> -1, Band[{1, 2}] -> -1}, {n, n}]) // MatrixForm pos = Position[Normal@a, -1]; rep = (First@# (n - Last@#))^(1/2) & /@ pos; (a = ReplacePart[a, Thread[pos -> rep]]) // MatrixForm ps. there might be a way to do the above directly at the Band level, but right now I do not know and I have a HW I have to finish soon, so have to go. I hope the above does what you wanted.
Posted 10 years ago
 The problem was when I found the Eigen values they were not given as numbers but as an exact interpretation. This still leaves me with the question on how I make a matrix with the +1,-1 diagonals as a function of their position. Thanks for your help Nasser.Andrew
Posted 10 years ago
 Try it like this (a = SparseArray[{Band[{2, 1}] -> -1, Band[{1, 2}] -> -1}, {50, 50}]) // MatrixForm To protect a from the wrapper MatrixForm
Community posts can be styled and formatted using the Markdown syntax.