%% SL3 - Complex power delivered to the system
Z = 50*[1+1j,    0,   2; ...
           0, 2-1j, -1j; ...
           2,  -1j,   3]
V = [1; 1; -1];

I = Z\V
P = 1/2 * I' * V
isPassive = real(P) >= 0

%% SL9: Element-wise Operations II
x = 0:pi/20:2*pi;
f1 = sin(x);
f2 = cos(x).^2;
f3 = f1 + f2;
plot(x, f1, x, f2, x, f3)

%% SL10: Element-wise Operations III
clear; clc;
x = linspace(0, 5*pi, 1e5);
f4 = (-cos(3*x)) ./ ...
(cos(x) .* sin(x - pi / 5) - pi);
plot(x, f4)

%% SL14: Indexing in MATLAB II
N1(end:-1:1)
N2(:, 2:2:end)
N3(1:2:end, :)
N2(2, [2 4 5])
A = reshape(1:12, 3, 4).'
A = zeros(3, 4), A(:) = 1:12, A = A.'

%% SL15: Indexing in MATLAB III
A([1, end], [1, end])     

%% SL17: Deleting, Adding and Replacing Matrices
% (solution to the problems on right)
A([2:3 5], :) = B([1 1 1], :)
A([2:3 5], :) = B(ones(1, 3), 1:6)
A([2:3 5], 1:5) = B(ones(1, 3), :)

