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

1)write and test code to generate the squate matrix A for a user specified N whe

ID: 2993564 • Letter: 1

Question

1)write and test code to generate the squate matrix A for a user specified N where


       1 2 3 ..............N

       2 3 4 ..............N+1

A=  3 4 5 ..............N+2

       ...

       ....

       N N+1 N+2 ......2N-1


That is A(i,J)= i+j-1.

Hint if A=ones(3,3) and D=diag{[1 2 3] then c=D*A will produce Mat Lab output [1 1 1;2 2 2;3 3 3] and R=A*D [1 2 3;1 2 3; 1 2 3].


2) generatethe matrix B(i,j)= 1/(i,j-1) then for a 3x3, B= 1    1/2 1/3

                                                                                                 1/2 1/3 1/4

                                                                                                 1/3 1/4 1/5


use dot notation



3) Tabulate the determinant of B for N=1,2 .....5.

Hint use mat lab help to find dederminant function

please explain the steps with commments

Explanation / Answer

clear all;
clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% PART 1 %%%%%%%%%%%%%%%%%%%%%%
%Use input function to take user specified N
N = input('ENTER THE INDEX NUMBER');

%Initialize matrix A according with all elements = 0
% Here zeros(i,j) generates a matrix of size ixj with zero elements
A = zeros(N,N);

%Use two for loops - one for row and other for column

for(row = 1:N)
    for(column = 1:N)
        A(row,column) = row + column - 1;
    end
end

%For printing just type the variable without semicolon
%Semicolon suppresses display on terminal
A

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% PART 2 %%%%%%%%%%%%%%%%%%%%%%

%Initialize the B matrix as zero like before
B = zeros(N,N);

%Use two for loops - one for row and other for column

for(row = 1:N)
    for(column = 1:N)
        B(row,column) = 1/(row + column - 1);
    end
end
B

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% PART 3 %%%%%%%%%%%%%%%%%%%%%%

%Determinant is found using the function det

det(B)