Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab Programming help! Please provide the code for following question. Write a

ID: 2080139 • Letter: M

Question

Matlab Programming help! Please provide the code for following question.

Write a program that asks for a real square matrix A and a real vector v,and does the following parts (via using loops) and displays the results:
(a) Finds and prints the trace (summation of the diagonal elements).

(b) Determines if A is a symmetric matrix.

(c) Determines if A is a diagonal matrix.

(d) Sorts rows in ascending order (from left to right), and columns in descending order (from up to down). The sorting should be based onthe magnitude (norm) of rows/columns. You can use the command norm.

(e) Finds the upper and lower triangular parts A. For the upper triangular part of A, the lower triangular elements are zero (except diagonal elements), and vice versa.

(f) Calculates the vector u=Av.


Run the program for the following example, and display all parts

A= [4, 17, 2, 5; -10, 6, -12, 3; 0, 3,4, 8; 11, 2, -5, 9];

v= [3; 6; 7; 8];

Explanation / Answer

Matlab Code:

A = input('Enter square matrix: ');
v = input('Enter v matrix:');
trace1 = 0;
for i=1:length(A)
trace1 = trace1+A(i,i);
end
fprintf('Trace of given matrix: %d ',trace1);
if A==transpose(A)
disp('given matrix is symmetric matrix');
end
for i=1:length(A)
for j=1:length(A)
if i~=j
if A(i,j)==0
ind = 0;
else
ind = 1;
end
else
if A(i,i)==0
ind =1;
end
end
  
end
end
if ind==1
disp('Given matrix is not diagonal matrix');
else
disp('Given matrix is diagonal matrix');
end
utA = triu(A);
disp('Upper traingular matrix:');
disp(utA);
ltA = tril(A);
disp('lower traingular matrix:');
disp(ltA);
u = A*v;
disp('u matrix');
disp(u);

Enter square matrix:
[4, 17, 2, 5; -10, 6, -12, 3; 0, 3,4, 8; 11, 2, -5, 9];
Enter v matrix:[3; 6; 7; 8];
Trace of given matrix: 23
Given matrix is not diagonal matrix
Upper traingular matrix:
4 17 2 5
0 6 -12 3
0 0 4 8
0 0 0 9

lower traingular matrix:
4 0 0 0
-10 6 0 0
0 3 4 0
11 2 -5 9

u matrix
168
-54
110
82

>>