%% SL 5
clear;
N = 6;
F = 1;
for n = 1:N
    F = F*n;
end

prod(1:N)

%% SL 9
clear;
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

sum(1:N)

%% SL 13
% script fills a matrix
close all; clear;
M = 100;
N = 20;
A = nan(M, N);
for m = 1:M
    for n = 1:N
        A(m,n) = (m*n)/4 + m/(2*n);
    end
end
pcolor(A); % plot

%% SL 14
close all; clear;
M = 100;
N = 20;
m = (1:M).';
n = 1:N;
A = (m.*n)/4 + m./(2*n);
pcolor(A)

%% SL 15
% script shows current on a half-wave dipole
close all; clear;
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

%% SL 23
clear, clc
nStudents = 40;
points = randi(100, nStudents, 1);
A = 0; B = 0; C = 0;
for iS = 1:nStudents
   if points(iS) >= 80
      A = A+1;
   elseif points(iS) >= 35
      B = B+1;
   else
      C = C+1;
   end
end

A2 = sum(points >= 80);
B2 = sum(points >= 35 & points < 80);
C2 = sum(points < 35);


%% SL 24
clear, clc
z = rand(1) + 1j*rand(1) - 1/2 * (1 + 1j);
if real(z) >= 0 % I. or IV. quadrant
    if imag(z) >= 0
        disp('I. quadrant');
    else
        disp('IV. quadrant');
    end
else % II. or III. quadrant
    if imag(z) >= 0
        disp('II. quadrant');
    else
        disp('III. quadrant');
    end
end

%% SL 26
clear, clc
grade = 4;
switch grade
   case 1
      reward = 1000;
   case 2
      reward = 500;
   case 3
      reward = 200;
   case 4
      reward = 50;
   otherwise
      reward = 0;
end
disp(reward)

%% SL 27
clear, clc
s1 = 4;
s2 = 3;
type = 'hyp';
switch type
    case 'hyp'
        c = sqrt(s1^2 + s2^2);
    case 'leg'
        a = sqrt(max(s1, s2)^2 - min(s1, s2)^2);
    otherwise
        c = 0; a = 0;
end

%% SL 28
% same as any(vec)

%% SL 29
% same as all(all(mat)) OR all(mat(:))