1)write and test code to generate the squate matrix A for a user specified N whe
ID: 2993554 • 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
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
Explanation / Answer
##a)
N = input('Enter a number : ');
D=ones(N,N);
A=zeros(N,N);
for i=1:N
A(i,i)=i;
end
C=D*A;
for i=1:N
for j=1:N
C(i,j)=C(i,j)+i-1;
end
end
C
OUTPUT--
Enter a number : 3
C =
1 2 3
2 3 4
3 4 5
b)
N = input('Enter a number : ')
D=ones(N,N);
A=zeros(N,N);
for i=1:N
A(i,i)=i;
end
C=D*A;
for i=1:N
for j=1:N
C(i,j)=C(i,j)+i-1;
end
end
B=ones(N,N)./(C);
format rat
B
OUTPUT--
Enter a number : 3
B =
1 1/2 1/3
1/2 1/3 1/4
1/3 1/4 1/5
c)for N=1:5
D=ones(N,N);
A=zeros(N,N);
for i=1:N
A(i,i)=i;
end
C=D*A;
for i=1:N
for j=1:N
C(i,j)=C(i,j)+i-1;
end
end
B= ones(N,N);
for i=1:N
for j=1:N
B(i,j)=1/(C(i,j));
end
end
Z(N)=det(B);
end
fprintf('number determinant ')
for i=1:5
fprintf('%d %.20f ',i,Z(i))
end
Output---
number determinant
1 1.00000000000000000000
2 0.08333333333333331500
3 0.00046296296296296135
4 0.00000016534391534393
5 0.00000000000374929513
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.