%clear

%      1. Find the results of three expressions and determine the type: 2/sin\left(0\right);2sin\left(\pi \right)/arctg\left(0\right);\text{ }\left\lbrack 1\text{ }\text{ }\text{ }\text{ }2;\pi \text{ }\sqrt{−1}\right\rbrack

a=2/sin(0),  b=2*sin(pi)/atan(0), c=[1 2; pi sqrt(-1)] 

%                 Type control:

isreal(a), isfinite([a,b]), isreal(c), imag(c)

%            2. Solve the system using the Gauss method:
% \left\lbrack \begin{array}{c}
% 7 & 0 & −1\\
% 1 & −1 & 12\\
% 1\ldotp 5 & −1 & 1\ldotp 5
% \end{array}\right\rbrack ∗\text{ }\left\lbrack \begin{array}{c}
% x\\
% y\\
% z
% \end{array}\right\rbrack =\left\lbrack \begin{array}{c}
% −1\ldotp 6\\
% 26\ldotp 5\\
% −4\ldotp 5
% \end{array}\right\rbrack
%                                         A*X=b, X=[x y z]'

A=[7,0,-1;1,-1, 12; 1.5,-1,1.5], b=[-1.6;26.5;-4.5]
det(A)
X=A\b

%                                 accuracy of the solution (8.8818e-16~0):

norm(A*X-b)

%      3. Construct a block-diagonal matrix R, which consists of a magic square of the 4th order,

R1=magic(4)

% a random integer matrix A of the third order with elements greater than two:

R2=randi([2,11],3)

% and a matrix of the second order B, whose elements are sines of the elements of the same size matrix C, C is obtained randomly, its elements are uniformly distributed on the segment [0,1].

B=sin(rand(2)) % C=rand(2)

% Construct R block diagonal:

R=blkdiag(R1,R2,B)

% Determine the number of non-zero elements of R.

NumberNonzero=nnz(R)

% Visualize the resulting matrix graphically, designate the non-zero elements of which with red triangles of the agreed size. Determine the number of elements less than 0.5 of the resulting matrix, write this value in the window title for spy

Rgt05=R>0.5, NRgt05=sum(sum(Rgt05))
spy(R,'r>',14), title(['R: Number Nonzero elements greate 0.5 are ',num2str(NRgt05)])

%     4. Edit the matrix R (see p.3) so that you get a matrix A (m,n) such that n is equal to the number of columns of the maximum block of the matrix R, and the number of rows is m. Place all blocks starting from the first column of the resulting matrix A, and leave the rows of the blocks unchanged. Show the structure of A using spy. Replace zero elements with ones and make sure (spy) that the editing is done correctly.
% Explanation: there are 4 columns in maximum block.

n=4, [m,k]=size(R); A=zeros(m,4); A(1:n,1:n)=R1; A(n+1:n+3,1:3)=R2; A(n+3+1:end,1:2)=B
A(A==0)=1, spy(A,'m',24)