%% SL 21
A = [-1 1; 1 -2]
B = [1 2 3; 4 5 6; 7 8 9]

%% SL 28
a = 3.24; alpha = pi/7;
a*sin(alpha)^2 + a*cos(alpha)^2 - a

a = 14; b = 28;
log10(a) + log10(b) - log10(a*b)

T = [1/2 1/3 1/4 1/5; 6 7 8 9; 0.2 0.3 0.4 0.5];
sum(T, 2)


%% SL 29
u = [1 2 3]; v = [3 2 1];
u*transpose(v), v * transpose(u)
v.'*u, u.'*v
dot(u, v), cross(u, v)

%% SL 31
T = 10 + 4*randn(7, 7);
trace(T)

U = [1 2 3; 0 2 0; ...
0 -2 -1];
det(U)

A = [1 2 3; 4 5 6; 7 8 1];
b = [6 15 16].';
x = inv(A)*b;
% OR
x = A \ b;

%% SL 36
z = 1 + 1j;
s = conj(z);
% OR
s = z'

Z = abs(z)
phi = angle(z)
phi_deg = phi/pi * 180
zm = Z*(cos(phi) + 1j*sin(phi))

%% SL 38
F = [2 2] + [1 -3] + [2 0] + [2 -1.5]
Fn = F / norm(F)

%% SL 39
clear, clc;
w1 = [1 2 3 4]
w2 = [-2 -3 -4]
w3 = [-2; -3; -4]
w4 = w1^2, w5 = w2 - w1

w3*3, w1 - 3
w1 + [5 5 5 5]
w6 = 5*w1 - [3 5 6] - w2

norm(w1)
sqrt(w1*w1.')

norm(w1)
sqrt(dot(abs(w1), abs(w1)))

%% SL40
a = 2; b = 5; c = 3;
D = b^2 - 4*a*c;
x1 = (-b + sqrt(D))/(2*a);
x2 = (-b - sqrt(D))/(2*a);

roots([-2 -5 -3])
roots([2 5 3])

%% SL 41
a = 3; b = 4;
c = hypot(a, b)
c = sqrt(a^2 + b^2)
c = sqrt([a, b]*[a; b])
c = sqrt(sum([a^2, b^2]))
c = sqrt(dot([a, b], [a, b]))

%% SL 42
v = [1; 2; 3];
a1 = pi/3; 
R = [cos(a1) 0 -sin(a1);...
0 1 0;...
sin(a1) 0 cos(a1)];
v2 = R * v

%% SL 43
r = 1 + 10*rand(1)
round(r)
ceil(r)
floor(r)
fix(r)
fix(100*r)/100
rem(r, 0.1)

%% SL 44
Z = [1+1j, sqrt(2)] 
Zz = abs(Z)
sqrt(Zz*Zz.')
% or
sqrt(sum(Zz.^2))
% or with indexing
sqrt(Zz(1)^2 + Zz(2)^2)

norm(Z)
sqrt(dot(Z, Z))
hypot(Z(1), Z(2))