%% SL10 + SL11 - script loanRepayment.m
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

%% SL12 - script loanRepaymentVectorized.m
clear; clc; close all
r = 0.1:0.01:0.2;
A = 1e3;
n = 12;
k = 1:15;

[R, K] = meshgrid(r, k);

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 (-)');

%% SL14 script loanRepayment.m calculates regular repayment
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 26: Relational operators
% having the vector G
G = [pi/2 pi 3/2*pi 2*pi]
% greater than pi
G > pi
% lesser or equal to pi
G <= pi
% not equal to pi
G ~= pi

% try similar operations for H = G'
H = G'; 
% greater than pi
H > pi
% lesser or equal to pi
H <= pi
% not equal to pi
H ~= pi

% find out whether V >= U for V = [-pi pi 1 0] and U = [1 1 1 1]
V = [-pi pi 1 0]
U = [1 1 1 1]
V >= U
