MATLAB: Hi, can someone help me generate a square matrix with all its elements one, exept its diagonal? As the following diagonalones ans = 2 1 1 1 1 3 1 1 1 1 4 1 1 1 1 5 Best Answer A suggestion:M = diag(1:4)+1 Related SolutionsMATLAB: Help me echelon matrix I suspect, after experimenting with multiple m, that the echelon form of this particular matrix is independent of m, e.g.,>> m=1; A = [1 2 3 4;2 -1 1 1;-1 4 3 2;1 2 0 m]; rref(A)ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1>> m=10; A = [1 2 3 4;2 -1 1 1;-1 4 3 2;1 2 0 m]; rref(A)ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 MATLAB: Creating a diagonalmatrix with diag and add a value to it Try this. It shows an example with symbolic variables to show that it creates the correct matrix. You can try it with k as a numeric vectork = sym('k', [1, 8]);A = diag(k(2:end-1),1) + diag(k(2:end-1),-1) + diag(k(1:end-1)+k(2:end));Result>> AA =[ k1 + k2, k2, 0, 0, 0, 0, 0][ k2, k2 + k3, k3, 0, 0, 0, 0][ 0, k3, k3 + k4, k4, 0, 0, 0][ 0, 0, k4, k4 + k5, k5, 0, 0][ 0, 0, 0, k5, k5 + k6, k6, 0][ 0, 0, 0, 0, k6, k6 + k7, k7][ 0, 0, 0, 0, 0, k7, k7 + k8] Related QuestionHow to create a symmetric random matrixPermuting elements in an symmetrical matrix with restricted outcomesConstruct tri or penta diagonal matrix from an exisiting matrixAccess Diagonal Matrix Element
Best Answer