%% SL 10
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);