% SL6:
%---------------------------------------
% skript loanRepayment.m
clear; clc;

%%
r = 0.1:.01:0.2;
A = input('zadejte A = ');
n = input('zadejte n = ');
k = 15;

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

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

% SL12:
G = [pi/2 pi 3/2*pi 2*pi]
G > pi
G <= pi
G ~= pi

H = G'; % then analogously

V = [-pi pi 1 0]
U = [1 1 1 1]
V >= U

% SL16:
A = [pi/2 pi 3/2*pi 2*pi]
A == pi | A == 2*pi
A > pi/2 & A ~= 2*pi
A = [A A(A > pi/2 & A ~= 2*pi)]

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

% SL19: 
M = magic(3);
all(M > 2)
any(M' >= 8)
all(all(M > 0))

% SL20:
a = 1; b = 1.1;
b ~= 0 && a/b > 3

% SL24: 
%% script calculates factorial of N
close all; clear all; clc;

N = 6;
F = 1;
for n = 1:N
    F = F*n;
end

% SL28:
%% script calculates sum from 1 by 1 to 100
close all; clear all; clc;

n = 100; % calculate up to 100
k = 1;   % start with 1
s = 0;   % allocation for final sum
while k <= n
   s = s + k; % add current value to the sum
   k = k + 1; % move to the next value
end

% SL32:
%% script fills a matrix
close all; clear all; clc;

M = 100;
N = 20;
A = zeros(M, N);
for m = 1:M
    for n = 1:N
        A(m,n) = (m*n)/4 + m/(2*n);
    end
end

% SL34
%% script shows current on a half-wave dipole
close all; clear all; clc;

N   = 101;
om0 = 2*pi;
x   = linspace(-pi/2, pi/2, N);
t   = linspace(0, 4*pi, N);
I0  = cos(x);
for n = 1:N
    I = I0*exp(1j*om0*t(n));
    figure(1);
    plot(x, real(I));
    axis([x(1) x(end) -1 1]);
    pause(0.1);
end

% SL44:
%% sorting by values
close all; clear all; clc;

r = 2*rand(8, 1)-1;
Pos = []; % allocation
Neq = []; % allocation
for n = 1:length(r)
    if r(n) >= 0
        Pos(end+1) = r(n); 
    else 
        Neq(end+1) = r(n); 
    end
end

% SL44:
%% sorting by values - logical indexing
close all; clear all; clc;

r = 2*rand(8, 1)-1;
Pos = r(r >= 0);
Neq = r(r < 0);
