%% SL 12
%% script evaluates two hyperbolic 
%  functions and plot them
x  = linspace(-1, 1, 51);
f1 = sinh(x);
f2 = cosh(x);
figure;
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;

%% SL 25
x  = 0:2:50;
y1 = exp(0.05*x).*sin(x);
y2 = exp(0.01*x).*cos(x);

figure('Color', 'w');
subplot(2, 2, 1);
stem(x, y1, 'MarkerFaceColor', 'blue'); hold on;
stem(x, y2, 'MarkerFaceColor', 'red', 'Marker', 'square'); grid on;
legend('e^{x/20}sin(x)', 'e^{x/100}cos(x)', 'Location', 'Northwest');
xlabel('x'); ylabel('y1, y2'); title('Display using STEM');
 
subplot(2, 2, 2);
plot(x, y1, 'bo-', x, y2, 'g*--');
legend('f_1 (x)', 'f_2 (x)', 'Location', 'Southwest');
xlabel('0:2:50'); ylabel('y_1 = f_1(x), y_2 = f_2(x)');
title('Display using PLOT');
 
subplot(2, 2, [3, 4]);
stairs(x, y1, 'LineWidth', 2); hold on; grid on;
stairs(x, y2, 'Color', 'r', 'Marker', 'x', 'LineWidth', 2);
title('Display using STAIRS');


%% SL 34
CH = repmat(eye(2), 4, 4);

figure;
imagesc(CH);
colormap gray;


%% SL 40
myLineObj = plot(0:10);

% get function
myLineWidth = get(myLineObj, 'LineWidth');
% set function
set(myLineObj, ...
   'Color', 'g', ...
   'LineStyle', ':', ...
   'LineWidth', myLineWidth + 1.5);


%% SL 41
myLineObj = plot(sin(0:0.2:2*pi));

myLineObj.Color	= 'r';
myLineObj.LineStyle	= 'none';
myLineObj.Marker	= '^';


%% SL 46
L = 1e2;

L = 1e5;
tosses = randi(6, 1, L);
histogram(tosses);


%% SL 47
clear; close all; clc;
N     = round(logspace(1, 5, 10)); % number of shots
hits  = nan(size(N)); % number of hits
my_pi = nan(size(N)); % approximations of pi
shots = 2*rand(N(end), 2) - 1; % generation of shots
R     = hypot(shots(:, 1), shots(:, 2)); % radii
 
for iShot = 1:length(N)
   hits(iShot)  = sum(R(1:N(iShot)) <= 1);
   my_pi(iShot) = 4*hits(iShot)/N(iShot);
end


figure;
semilogx(N, my_pi, 'x--', ...
   'linewidth',2);
xlim([N(1) N(end)]);
hold on; grid on;
xlabel('shots','FontSize', 15);
ylabel('approximation of \pi', ...
   'FontSize', 15);
line([N(1) N(end)], [pi pi], ...
   'color', 'r', 'linewidth', 2);
