%% SL 11
clear; clc;
r = 0.1:0.01:0.2; % interest on a loan is vectorized
A = 1e3;
n = 12;
k = 15;

P = r*A.*(1 + r/n).^(n*k) ./ (n*((1 + r/n).^(n*k) - 1));

disp(P.');         % monthly instalments
disp(P.'*n*k - A); % overpayment


%% SL 12
clear; clc; close all;
r = 0.1:0.01:0.2;
A = 1e3;
n = 12;
k = 1:15;

[R, K] = meshgrid(r, k);
% R = r; K = k.'; % from 2016b
P = R*A.*(1 + R/n).^(n*K) ./ ...
   (n.*((1 + R/n).^(n*K) - 1));

surf(R, K, P)
xlabel('r (-)');
ylabel('k (years)');
zlabel('P (-)');

%% SL 14
clear; clc;
r = 0.1:.01:0.2;
A = input('insert A = ');
n = input('insert n = ');
keyboard; % insert new data (A,n), then type „return“)
k = 15;
P = r*A.*(1 + r/n).^(n*k) ./ (n.*((1 + r/n).^(n*k) - 1));
pause; % program will continue after pressing any key
disp(P.'); disp(P.'*n*k - A);

%% SL 18
clear; clc;

%% definitions of variables
r = 0.1:0.01:0.2;
A = input('input A = ');
n = input('input n = ');
k = 15;

%% computation
P = r*A.*(1 + r/n).^(n*k) ./ (n.*((1 + r/n).^(n*k) - 1));

%% dislay results
disp(P.'); disp(P.'*n*k - A);

%% SL 28
A = pi/2:pi/2:2*pi;
A == pi | A == 2*pi
A > pi/2 & A ~= 2*pi
[A A(A > pi/2 & A ~= 2*pi)]

%% SL 30
K = 1:3:20;
L = K(K > 10 & K < 16)

%% SL 31
M = magic(3);
all(M > 2)
any(M >= 8, 2)
all(all(M > 0))
all(M(:) > 0)

%% SL 32
b ~= 0 && a/b > 3

%% SL 39
N = 5; V = 40;
t = linspace(0, N, N*V);
s_t = randn(1, N*V) + ...
   sqrt(2*pi)*sin(2*pi*t);

%% SL 40
A = [1 1 2; 2 3 5];
if all(all(A > 0)) & all(mod(A(1, :), 1) == 0)
   disp('yep');
end

if all(all(A > 0)) && all(mod(A(1, :), 1) == 0)
   disp('yep');
end
