clear all; close all; clc;
sizeTitle=20;
sizeLegend=20;
sizeX=20;
sizeY=20;
osy=20;

%% Graf gama funkce 
Q=-5:0.0001:5;
Q2=gamma(Q);
figure(01);
plot(Q,Q2,'b-','LineWidth',2);
ylim([-10 10]);
xlim([-5 5]);
xax=xlabel('x');
yax=ylabel('Gama(x)');
grid on;
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (gca, 'fontsize', osy)
set(gca,'XTick', [-5 -4 -3 -2 -1 0 1 2 3 4 5]);
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);

%% Graf Laguerrovych polynomu a Laguerovych funkci
X=0:0.01:15;
LP(1,:)=LaguerrePolN( 0, 1, 1, X );
LP(2,:)=LaguerrePolN( 1, 1, 1, X );
LP(3,:)=LaguerrePolN( 2, 1, 1, X );
LP(4,:)=LaguerrePolN( 3, 1, 1, X );
LP(5,:)=LaguerrePolN( 4, 1, 1, X );
for i = 1:5
LF(i,:)=LP(i,:).*exp(-X./2);
end

figure(11);
plot(X,LP,'LineWidth',2);
grid on;
ylim([-20,20]);
xlim([0,14]);
xax=xlabel('x');
yax=ylabel('Ln(x)');
tax=title('Zobecnene Laguerrovy polynomy radu n, alpha=0');
lax= legend('n=0','n=1','n=2','n=3','n=4','location','southwest'); 
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (lax, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy);
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);

figure(12);
plot(X,LF,'LineWidth',2);
grid on;
ylim([-1,1]);
xlim([0,14]);
xax=xlabel('x');
yax=ylabel('ln(x)');
tax=title('Zobecnene Laguerrovy funkce radu n, alpha=1');
lax=legend('n=0','n=1','n=2','n=3','n=4');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (lax, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);

%%Graf M-L funkci
x=0:0.01:2;
MLF(1,:)=zeros(1,length(x));
MLF(2,:)=zeros(1,length(x));
MLF(3,:)=zeros(1,length(x));
MLF(4,:)=zeros(1,length(x));
MLF(5,:)=zeros(1,length(x));
MLF(6,:)=zeros(1,length(x));
for k=0:1:100
MLF(1,:)=MLF(1,:)+x.^k/gamma(k+1);
MLF(2,:)=MLF(2,:)+x.^k/gamma(2*k+1);
MLF(3,:)=MLF(3,:)+x.^k/gamma(3*k+1);
MLF(4,:)=MLF(4,:)+x.^k/gamma(k+3);
MLF(5,:)=MLF(5,:)+x.^k/gamma(2*k+3);
MLF(6,:)=MLF(6,:)+x.^k/gamma(3*k+3);
end
figure(13)
%plot(x,MLF11,'LineWidth',2,x,MLF21,'LineWidth',2,x,MLF31,'LineWidth',2,x,MLF13,'LineWidth',2,x,MLF23,'LineWidth',2,x,MLF33,'LineWidth',2);
plot(x,MLF,'LineWidth',2);

grid on;
xax=xlabel('t');
yax=ylabel('E\\alpha,\\beta(t)');
tax=title('Mittag-Lefflerovy funkce');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('E1,1(t)=e^t','E2,1(t)','E3,1(t)','E1,3(t)','E2,3(t)','E3,3(t)','location','northwest');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)


%% Grafy derivaci jednotlivych funkci
alpha=[-1.5 -0.5 -0.1 0 0.1 0.5 1.5];
X=0:0.01:10;
Ex=zeros(7,length(X));
for i=1:7
  Const(i,:)=X.^(-alpha(i))./gamma(1-alpha(i));
  X1(i,:)=X.^(1-alpha(i))./gamma(2-alpha(i));
  X2(i,:)=2.*X.^(2-alpha(i))./gamma(3-alpha(i));
  Sx(i,:)=sin(X +(alpha(i)).*pi/2);
  Cx(i,:)=cos(X +(alpha(i)).*pi/2);
  for k=0:100
    Ex(i,:)=Ex(i,:) + (X.^(k-alpha(i))./gamma(k-alpha(i)+1));
  end
end

figure(21);
plot(X,Const,'LineWidth',2);
grid on;
ylim([-2,2]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace konstanty');
set(gca,'XTick', [0 1 2 3 4 5 6 7 8 9 10]);
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\alpha=1,5','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)


figure(22);
plot(X,X1,'LineWidth',2);
grid on;
ylim([0,10]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace x');
set(gca,'XTick', [0 1 2 3 4 5 6 7 8 9 10]);
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\\alpha=1,5','location','northwest');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX);
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(23);
plot(X,X2,'LineWidth',2);
grid on;
ylim([0,10]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace x^2');
set(gca,'XTick', [0 1 2 3 4 5 6 7 8 9 10]);
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\\alpha=1,5','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(24);
plot(X,Sx,'LineWidth',2);
grid on;
ylim([-1,1]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace sin(x)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\\alpha=1,5');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(25);
plot(X,Cx,'LineWidth',2);
grid on;
ylim([-1,1]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace cos(x)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\\alpha=1,5');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(26);
plot(X,Ex,'LineWidth',2);
grid on;
xlim([0,3]);
ylim([0,10]);
xax=xlabel('x');
yax=ylabel('f(x)');
tax=title('Derivace e^x (a=0)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('\\alpha=-1,5','\\alpha=-0,5','\\alpha=-0,1','\\alpha=0','\\alpha=0,1','\\alpha=0,5','\\alpha=1,5','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

%% Grafy prvni priklad
x=0:0.01:5;
ZLT=zeros(1,length(x));
ZLT1=zeros(1,length(x));
ZLT2=zeros(1,length(x));
lambda = 7;
for k=0:1:120
  if(k==40)
    ZLT1(:)=ZLT(:);
  elseif(k==80)
    ZLT2(:)=ZLT(:);
  end
  ZLT=ZLT+0.5.*( ( (-3).^k .*(x.^(0.6.*k-0.4)))./gamma(0.6*k+0.6))+2.5.*( ( (-7).^k .*(x.^(0.6.*k-0.4)))./gamma(0.6*k+0.6)) -2.*( ( (-4).^k .*(x.^(0.6.*k-0.4)))./gamma(0.6*k+0.6));
end
ZLT(ZLT>100000)=100000;
ZLT1(ZLT1>100000)=100000;
ZLT2(ZLT2>100000)=100000;
ZLT(ZLT<-100000)=-100000;
ZLT1(ZLT1<-100000)=-100000;
ZLT2(ZLT2<-100000)=-100000;
[su c]=tf2g([1 3 2],[1 14 61 84],0.6,5,lambda,x);
clear tmp;
tmp(1,:)=ZLT1;
tmp(2,:)=ZLT2;
tmp(3,:)=ZLT;


figure(31)
plot(x,tmp,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 1.1]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Analyticky vypoctene g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('N=40','N=80','N=120','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(32)
plot(x,su,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 1.1]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Aproximace g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
%l=legend('N=40','N=80','N=120','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
%set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)
clear tmp;
tmp(1,:)=ZLT;
tmp(2,:)=su;


figure(33)
plot(x,tmp,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 1.1]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Porovnani vysledku vypoctu g(t)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('Analyticky','Aproximace','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

%% Grafy druhy priklad
x=0:0.01:10;
lambda=2.3;
[su,c]=tf2g([1 5 4],[1 7 16 12],1,5,lambda,x);
ZLT=-2*exp(-3.*x)+3*exp(-2.*x)-2.*x.*exp(-2.*x);

figure(41)
plot(x,ZLT,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 10]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Analyticky vypoctene g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
%l=legend('N=40','N=80','N=120','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
%set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)

figure(42)
plot(x,su,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 10]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Aproximace g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
%l=legend('N=40','N=80','N=120','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
%set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)
clear tmp;
tmp(1,:)=ZLT;
tmp(2,:)=su;

figure(43)
plot(x,tmp,'LineWidth',2);
grid on;
ylim([-0.5 1.5]);
xlim([0 10]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Porovnani vysledku vypoctu g(t)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend('Analyticky','Aproximace','location','southeast');
set (yax, 'fontsize', sizeY)
set (xax, 'fontsize', sizeX)
set (tax, 'fontsize', sizeTitle)
set (l, 'fontsize', sizeLegend)
set (gca, 'fontsize', osy)
ch=chyba(ZLT,su,x(2)-x(1));


%% treti priklad
x=0:0.01:10;
ZLT=zeros(1,length(x));
ZLT1=ZLT;
ZLT2=ZLT;
sigma = 6.5;
for k=0:1:120
  if(k==40)
    ZLT1(:)=ZLT(:);
  elseif(k==80)
    ZLT2(:)=ZLT(:);
  end
  ZLT=ZLT+( (-7).^k .* x.^(1.3*k+0.3)./gamma(1.3*k+1.3) );
end
[su c]=tf2g([1],[1 7],1.3,5,sigma,x);
ZLT(ZLT>100000)=100000;
ZLT1(ZLT1>100000)=100000;
ZLT2(ZLT2>100000)=100000;
ZLT(ZLT<-100000)=-100000;
ZLT1(ZLT1<-100000)=-100000;
ZLT2(ZLT2<-100000)=-100000;

clear tmp;
tmp(1,:)=ZLT1;
tmp(2,:)=ZLT2;
tmp(3,:)=ZLT;

figure(51)
plot(x,tmp,'LineWidth',2);
grid on;
ylim([-0.1 0.5]);
xlim([0 10]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Analyticky vypoctene g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend("N=40","N=80","N=120","location","southeast");
set (yax, "fontsize", sizeY)
set (xax, "fontsize", sizeX)
set (tax, "fontsize", sizeTitle)
set (l, "fontsize", sizeLegend)
set (gca, 'fontsize', osy)

figure(52)
plot(x,su,'LineWidth',2);
grid on;
ylim([-0.1 0.5]);
xlim([0 3]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Aproximace g(t) systemu');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
%l=legend("N=40","N=80","N=120","location","southeast");
set (yax, "fontsize", sizeY)
set (xax, "fontsize", sizeX)
set (tax, "fontsize", sizeTitle)
%set (l, "fontsize", sizeLegend)
set (gca, 'fontsize', osy)

clear tmp;
tmp(1,:)=ZLT;
tmp(2,:)=su;

figure(53)
plot(x,tmp,'LineWidth',2);
grid on;
ylim([-0.1 0.5]);
xlim([0 3]);
xax=xlabel('t');
yax=ylabel('g(t)');
tax=title('Porovnani vysledku vypoctu g(t)');
set (gca,'xcolor', [0 0 0]);
set (gca,'ycolor', [0 0 0]);
l=legend("Analyticky","Aproximace","location","southeast");
set (yax, "fontsize", sizeY)
set (xax, "fontsize", sizeX)
set (tax, "fontsize", sizeTitle)
set (l, "fontsize", sizeLegend)
set (gca, 'fontsize', osy)
ch3=chyba(ZLT,su,x(2)-x(1));
