% M-file for MATLAB 
% Cviceni07_08 (c07_08.m Verze:030512) - Kapitoly 7,8: Grafika 2D,3D
clc,clear all,close all; % vycisti okno vypisu, pamet promennych a graf. okna

% Pro uplny zacatek
colormap(hsv(64))
z = cplxgrid(30);
cplxmap(z,(z.^4-1).^(1/4));
title('(z^4-1)^(1/4)')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 7A.1 - zaklady 2D grafiky - vlastnosti objektu 
% Definice umístìní grafického okna a jeho vlastností

figure;
% otevreni okna
% pozice okna
set(gcf,'Units','Normal','Position',[0.4,0.5,0.5,0.3])
% pozice souradneho systemu
s1=axes('Position',[0.1,0.1,0.8,0.7])
plot(sin(0:pi/10:2*pi))
% graf fce
% zjisti vlastnosti grafickeho okna
get(gcf)
% zjisti vlastnosti grafu v ramci okna
get(s1)
% Vybrane vlastnosti objektu s1 a jejich prenastaveni
% Color [x y z] barva plochy grafu
set(s1,'Color',[1 0 0]), pause
% cervena
set(s1,'Color',[0 1 0]), pause
% zelena
set(s1,'Color',[0 0 1]), pause
% modra

% Box on/off obrys grafu
set(s1,'Box','off'), pause, set(s1,'Box','off')
% Dalsi, napr. pro popis grafu
% FontName 'jmeno', FontSize [velikost],
% LineWidth [velikost], NextPlot 'replace'
% Visible on/off viditelnost grafu
% XColor, YColor, ZColor barva os, vztahuje se i na grid
% Nelze menit barvu cary grafu, je to jiny objekt!!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 7A.2 - zaklady 2D grafiky - prikaz subplot

% a) 2 grafy pod sebou
   subplot(211), plot(sin(0:pi/10:2*pi))
   subplot(212), plot(cos(0:pi/10:2*pi))
% b) 2 grafy vedle sebe
   figure;
   subplot(121), plot(sin(0:pi/10:2*pi))
   subplot(122), plot(cos(0:pi/10:2*pi))
% c) 4 grafy
   figure;
   subplot(221), plot(sin(0:pi/10:2*pi))
   subplot(222), plot(cos(0:pi/10:2*pi))
   subplot(223), plot(2*sin(0:pi/10:2*pi))
   subplot(224), plot(2*cos(0:pi/10:2*pi))
% d) 3 g. spodni vetsi
   figure;
   subplot(221), plot(sin(0:pi/10:2*pi))
   subplot(222), plot(cos(0:pi/10:2*pi))
   subplot(212), plot(2*cos(0:pi/10:2*pi))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 7B.1
syms x y		% definice symbolickych objektu (promennych) 		
y=cos(x/3)		% def. funkce 
y_d=diff(y)		% prvni derivace funkce
y_d2=diff(y_d)		% y_d2=diff(diff(y))

x=0:pi/10:2*pi;			% prepsani symb. promenne x vektorem
y=subs(y)			% symbolicka substituce
y_d=subs(y_d);y_d2=subs(y_d2);	

% plot(y)			% copak,ze to vlastne vykreslime?

figure
subplot(131),plot(x,y)
subplot(132),plot(x,y_d)
subplot(133),plot(x,y_d2) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 3D grafika

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Priklad 8A.1 - zaklady 3D grafiky - vlastnosti objektu 
% f(x,y)=-x exp(-x^2-y^2) 
% x=-2:.1:2, y=-2:.1:2 
clear all, close all 
[x,y]=meshgrid(-2:.1:2); % generace bodu 
z=-x.*exp(-x.^2-y.^2); % definice funkce 
% nejjednodussi a nejmene hezke, carove zobrazeni 
  plot3(x,y,z), pause 
% zobrazeni v barvach 
  mesh(x,y,z),title('graf fce'),xlabel('x'),ylabel('y') 
% zmìna barevne skaly 
  pause, colormap([0 0 1]) % modry 
% navíc prumet do roviny x,y 
  pause, figure, meshc(x,y,z) 
% povrch, vypada jako pevne teleso 
  pause, figure,surf(x,y,z) 
% a jeste prida prumet do roviny x,y 
  pause, surfc(x,y,z) 
% totez, ale s urcitym nasvetelenim objektu, default 45 stupnu 
  pause, surfl(x,y,z) 
% vlastni nasvetleni pomoci s=[azimut, elevace] 
  pause, s=[80,10]; surfl(x,y,z,s) 
% lze vtvorit surface jako objekt a dal s nim pracovat 
  s1=surface(x,y,z); get(s1) 
% prumet do roviny 
  contour(x,y,z) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%











% demo matlab graphics
