%% SL14
% script evaluates two hyperbolic 
%  functions and plot them
x  = linspace(-1, 1, 51);
f1 = sinh(x);
f2 = cosh(x);
plot(x, f1, 'bs-');
hold on;
plot(x, f2, 'rd--');
ylim([-1.5 1.5]);
legend('f_1(x)=sinh(x)', 'f_2(x)=cosh(x) ', ...
'Location', 'best');
xlabel('x'); 
ylabel('f_1(x), f_2(x)');
grid on;

%% SL17
close all; clear; clc;
t1 = -1:0.2:1;
t2 = -1:0.1:1;
t3 = -1:0.01:1;
f1 = t1.*sin(pi/2*(1+20*t1));
f2 = t2.*sin(pi/2*(1+20*t2));
f3 = t3.*sin(pi/2*(1+20*t3));
figure;
hold on; grid on;
plot(t1, f1, 'r');
plot(t2, f2, 'g');
plot(t3, f3, 'b');
legend('0.2', '0.1', '0.01');

%% SL18
close all; clear; clc
x = -(3/2)*pi:pi/100:(3/2)*pi;
y = tan(x);
z = y.*(abs(y) < 1e10);
figure;
plot(x, y);
hold on;
plot(x, z, '--r', 'LineWidth', 2);
axis([-(3/2)*pi, (3/2)*pi, -40, 40]);
legend('Original', 'Limited values');
xlabel('x [rad]');
ylabel('tan(x) [-]');

%% SL28
L = 1e5;
tosses = randi(8, 1, L);
histogram(tosses);

%% SL30
N = 1e4; % number of series
M = 1e3; % number of throws in one set
throws = randi([0 1], M, N)*2-1; % generate numbers -1 and 1
noOnesOverAverage = sum(throws); % is vector
figure(1);
histogram(noOnesOverAverage,60); % 60 bins

% economy code
N = 1e4; M = 1e3;
histogram(sum(randi([0 1], M, N)*2-1), 60);

%% SL31
figure(2);
histogram(0 + 31.62*randn(N,1), 60);
