Constructing Matrix in Matlab with Specific Requirements

31 Views Asked by At

I need to construct a matrix A whose diagonal is a[i,i]= 2; the sub-diagonals a[i+1,i] = a[i,i+1] = −1/2. All other entries of A are zero. The size must be changeable, I need to make one with dimensions of 50, 100, and 200. I know how to create A matrix with a diagonal of 2 of any size, but not sure how to do the sub-diagonals. Any help would be appreciated.