- #1

azdang

- 84

- 0

Let A be the nxn matrix with elements a

_{ij}= -1 for i > j, a

_{ii}=a

_{in}=1, 1<=i<=n, and zero everywhere else.

The only thing I've been successful with is to do this:

B=eye(n,n);B(1:n,n)=1; (This puts 1's on the diagonal and in the last column)

C=tril(-ones(n,n),-1); (This creates a lower triangular matrix with -1's below the diagonal)

Then, A = B+C.

I am sure there must be a more efficient way to construct this matrix that my teacher is expecting, but I'm not sure what it is. Does anyone who has experience with MATLAB know how I might be able to do this? Thank you!