%% SPLS/2e MATLAB
% Chapter B
clear; close all;
%% Ex. B.1
abs(-2+1j)
angle(-2+1j)*180/pi
%% Ex. B.2
real(2*exp(1j*pi/3))
imag(2*exp(1j*pi/3))
2*exp(1j*pi/3)
%% Ex. B.3
z1 = 3+4j; z2 = 2+3j;
z1*z2
z1 = 5*exp(1j*53.1*pi/180); z2 = sqrt(13)*exp(1j*56.3*pi/180);
abs(z1/z2)
angle(z1/z2)*180/pi
%% Ex. B.6
C = abs(-3+4j)
theta = angle(-3+4j)*180/pi
%% Ex. B.7
x1 = det([3 1 1;7 3 -1;1 1 1])/det([2 1 1;1 3 -1;1 1 1])
%% Sec. B.7.2
z = -3-4j
z_real = real(z); z_imag = imag(z);
z_mag = sqrt(z_real^2 + z_imag^2)
z_mag = sqrt(z*conj(z))
z_mag = abs(z)
z_rad = angle(z)
z_deg = angle(z)*180/pi
z_rad = atan2(z_imag,z_real)
cos(1j)
log(-1)
%% Sec. B.7.3
k = 0:2:11
k = 11:-10/3:0
k = 0:11
k = 0:2; w = exp(1j*(pi/3 + 2*pi*k/3))
k = 0:99; w = exp(1j*(pi/100 + 2*pi*k/100));
w(5)
k(5)
w(98:100)
t = 0:0.2/500:0.2-0.2/500;
f = sin(2*pi*10*t+pi/6);
f(1)
%% Sec. B.7.4, Fig. B.12
plot(t,f);
xlabel('t'); ylabel('f(t)')
%% Sec. B.7.4, Fig. B.13
plot(real(w),imag(w),'o');
xlabel('Re(w)'); ylabel('Im(w)'); axis equal
%% Sec. B.7.5, Fig. B.14
g = exp(-10*t);
h = f.*g;
plot(t,f,'-k',t,h,':k');
xlabel('t'); ylabel('Amplitude');
legend('f(t)','h(t)');
%% Sec. B.7.6
r = [1 0 0]
A = [2 3;4 5;0 6]
c = r'
B = [c A]
B(1,2)
B(1:2,2:3)
B(2,:)
A = [1 -2 3;-sqrt(3) 1 -sqrt(5);3 -sqrt(7) 1]; y = [1;pi;exp(1)];
x = inv(A)*y
x1 = det([y,A(:,2:3)])/det(A)
alpha = (0:10);
t = (0:0.001:0.2)';
T = t*ones(1,11);
H = exp(-T*diag(alpha)).*sin(2*pi*10*T+pi/6);
plot(t,H); xlabel('t'); ylabel('h(t)');
%% Sec. B.7.6
% [R,P,K] = residue(B,A)
[R,P,K] = residue([1 0 0 0 0 pi],[1 -sqrt(8) 0 sqrt(32) -4]); 
R = R.', P = P.', K