MATLAB: Need Help making a nxn symmetric matrix arrayfor loopmatrix My symmetric matrix should look like [1 0 0 0 0..n no. of zeroes; 1 -2 1 0 0 0..n; 0 1 -2 1 0 0 ..; for n no of rows] Best Answer Making a guess at what you really want, you could build it in pieces, e.g.,n = size of matrix;A = zeros(n);A(1:n+1:end) = -2; % The diagonalA(2:n+1:end) = 1; % The lower diagonalA(n+1:n+1:end) = 1; % The upper diagonalA(1,1) = 1; % Different value for the (1,1) spot.An alternative method could employ the spdiags function to build the matrix. Related SolutionsMATLAB: Hello how to create this matrix with specific diagonals Use toeplitz:>> n = 5;>> toeplitz([2,-1,zeros(1,n-2)])ans = 2 -1 0 0 0 -1 2 -1 0 0 0 -1 2 -1 0 0 0 -1 2 -1 0 0 0 -1 2 MATLAB: How to construct the n*n matrices, like below: diag(vector_of_2s) - diag(vector_of_ones, 1) - diag(vector_of_ones, -1) Related QuestionHot to create a matrix with elements which moves to right as row increasesNeed help creating an arrayIs there a way to assign a value to multiple diagonals in a matrixHow to Assemble the matrix shown in the image on Matlab for any number of nodesHow to make a for loop with matrices using n
Best Answer