MATLAB:: Create a matrix with one through 15 on the diagonal. First create a one row 15 column matrix with 1 through 15 in it. Then use the “diag” command .
% Matlab script to create a matrix with one through 15 on the diagonal.
% create a row vector from 1 to 15 in steps of 1
v = (1:15);
% diag command to place the elements of input vector v in the main
diagonal of a
% square matrix of size number of elements in v and the other
elements of
% the matrix are 0.
diagonal_1_15 = diag(v);
% display the resultant matrix
disp(diagonal_1_15);
%end of script
Output:
Get Answers For Free
Most questions answered within 1 hours.