% M-file for MATLAB 
% Cviceni10 (c10.m Verze:030512) - Kapitola 10: Symbolicky toolbox
clc,clear all,close all; % vycisti okno vypisu, pamet promennych a graf. okna 

sym a                       % vytvori sym. objekt 'a' (ans)
sym('b')                    % vytvori sym. objekt 'b' (ans)
syms d e f                  % vytvori sym. objekty i v pameti/workspace: d=sym('d')
sym(1/10,'f')               % konstanty a format cisla 
sym(1/10,'r')

f=sin(2*a)                  % def. funkce
diff(f)                     % derivace funkce 
diff(f,2)                   % 2ha derivace == diff(diff(f))     
int(f)                      % integrace funkce

pause
clear all,clc
% Reseni linearni a kvadraticke rovnice (SOLVE)
syms x                       % vytvori sym. promennou 'x'
x=solve('2*x - x = -3')      % (1 numericky koren, ale do symbolicke promenne!)
% x=solve(2*x-x+3)           % 2. alternativni zapis (prevod na jednu stranu)
% f=2*x-x+3,x=solve(f)       % 3. alternativni zapis
xx=double(x)                 % prevod symbolicke promenne (v M6.5 je aut. konverze)

x=solve('x^2 + x = 3')       % (2 koreny)

% Reseni soustavy 2 rovnic o 2 neznamych (x,y)
pause
clear all,clc
syms x y
[x,y] = solve('4*x + 5*y = 3','8*x + 10*y = 6')         % linearne zavisle = ma nekonecno reseni ;)
[x,y] = solve('4*x + 5*y = 3','x - 4*x + 3 = 0')        % linearni => ma reseni 
[x,y] = solve('x^2 + x*y + y = 3','x^2 - 4*x + 3 = 0')  % nelinearni => ma 2 reseni
[x,y]           % zobrazeni "tech" dvou reseni 

pause
clear all,clc
% Reseni dif. rovnice (DSOLVE)
% OZNACENI: dy/dx => Dy  (y')
%                 => D2y (y'')
x = dsolve('Dx = -a*x')                         % s pocatecni podminkou x(0)=0 [dsolve('Dx = -a*x','x(0)=0')]
x = dsolve('Dx = -a*x','x(0)=10')               % s pocatecni podminkou x(0)=10
y = dsolve('(Dy)^2 + y^2 = 1','y(0) = 0')       % 
y = dsolve('(D2y)^2 + y^2 = 1','y(0) = 0')      % 

% zjednoduseni vysledku
simple((cos(x))^2+(sin(x)^2))
simplify((cos(x))^2+(sin(x)^2))

% zkraasleni vysledku 
diff(log(x)/sqrt(2*x))
pretty(diff(log(x)/sqrt(2*x)))

