% M-file for MATLAB 
% Cviceni02 (c02.m Verze:030306)
clc,clear all,close all; % vycisti okno vypisu, pamet promennych a graf. okna

% Logika / Logicke promenne / Logicke funkce v Matlabu
% Pravdivostni tabulka
a=1,b=0         % def. logickych funkci
a|b             % logicky soucet : logicke OR==nebo
a&b             % logicky soucin : logicke AND==a
~b              % logicka negace : logicky NOT
% % Matice (2)
A=magic(3)
max(A)          % 
max(max(A))     % maximalni prvek v matici
min(min(A))     % minimalni prvek v matici
v=[1,2,3]   
B=magic(3)
B(2,2)=0        % prepis 1 prvku v matici
B(2,:)=v        % zmena celeho radku v matici
B(:,3)=v'        % zmena celeho sloupec v matici
C=B(1:2,:)      % submatice / vyrez matice
C(1:2,1:2)=0    % souvisla zmena
CC=[C, C]       % sdruzovani matic
CC=[C; C]       % sdruzovani matic 2
A=magic(5)
A_vyrez=A(4:5,4:5)  % 4 elementy z praveho dolniho rohu matice
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 2A.4 - vyrez matice
A=magic(5);
A_vyrez2=A(1,1:2)  % 1 radek, 1,2 sloupec
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 2A.5 - reseni soustavy rovnic
D=[1,2,3; 4,5,6; 7,8,1];
b=[6;15;16];           % vektor pravych stran
% 1,reseni pres inv. matici 
y=inv(D)*b
x1=y(1,1)
% 2,reseni pres determinanty
detD=det(D);            % determinant
D1=[b,D(:,2:3)];        % submatice D
D2=[D(:,1),b,D(:,3)];
D3=[D(:,1:2),b];
x1=det(D1)/detD         % samostatne promenne x1,x2,x3
x2=det(D2)/detD
x3=det(D3)/detD
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Funkce pro matice
D=[1,2,3; 4,5,6; 7,8,1];
D_exp=expm(D)
D2=sqrtm(D_exp)
D3=logm(D_exp)       % neni rovna matici D,prestoze by mela byt (>> Matlab zaokrouhluje)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IMAGINARNI CISLA
real_cislo=-100;
img_cislo=100+5i;
real(real_cislo), real(img_cislo)
imag(real_cislo), imag(img_cislo)
abs(real_cislo)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 2B.4 - STATISTIKA
data=[1,1.1,1.11,0.98,1.35,0.8,1.25,1.1,1.1,1.2,0.9]
size_data=size(data)
size1=size_data(1,1)    % pocet radku (pro sloupcovy vektor >>> size1 je pocet elementu)
size2=size_data(1,2)    % pocet sloupcu (pro radkovy vektor >>> size2 je pocet elementu)
prumer=sum(data)/size2
prumer2=mean(data)      % pomoci statisticke funkce MEAN
minimum=min(data)
maximum=max(data)
smer_odchyka=std(data)  % pomoci statisticke funkce STD
%  (1/size2-1) se nerovna  (1/(size2-1)) !!!!!
smer_odchyka2=(1/(size2-1)*sum((data-prumer).^2))^(1/2) % podle definice
smer_odchyka2b=sqrt(1/(size2-1)*sum((data-prumer).^2)) % podle definice
cov(data)               % kovariance
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 2B.5 - priklad na submatice
% ......






