% wykorzystuje statistics toolbox
mu=9.81; sigma=0.1; dt=0.01; from_x=9.2; to_x=10.4;
x=from_x:dt:to_x;
y=normpdf(x, mu, sigma);
figure(1);plot(x,y);
line([9.81 9.91], [1 1]); text(9.81,1.3, '\sigma=0,1')

figure(2);clf;
mu=0; sigma=1; dt=0.01; from_x=-5; to_x=5;
x=from_x:dt:to_x;
y=normpdf(x, mu, sigma);
plot(x,y); 
x1=norminv(0.05, mu, sigma);
x1=2*mu-x1;
set(gca,'xlim',[from_x to_x], 'xtick', [0 x1], 'tickdir', 'out'); 
x_ind=ceil((x1-from_x)/dt)
line([x1 x1], [0 4], 'linestyle', ':')
p1=patch([x(x_ind) x(x_ind:floor((to_x-from_x)/dt)) ],...
 [0 y(x_ind:floor((to_x-from_x)/dt))], 'y', 'linestyle', 'none', 'erasemode', 'none');

figure(3)
plot(x,y)
x1=norminv(0.05/2, mu, sigma);
x_ind=ceil((x1-from_x)/dt)
x2=2*mu-x1;
set(gca,'xlim',[from_x to_x], 'xtick', [x1 0 x2], 'tickdir', 'out'); 
p1=patch([x(1:x_ind) x(x_ind)],...
 [y(1:x_ind) 0], 'y', 'linestyle', 'none', 'erasemode', 'none');
x_ind=ceil((x2-from_x)/dt)
p2=patch([x(x_ind) x(x_ind:floor((to_x-from_x)/dt))],...
 [0 y(x_ind:floor((to_x-from_x)/dt))], 'y', 'linestyle', 'none', 'erasemode', 'none');
line([x1 x1], [0 4], 'linestyle', ':'); line([x2 x2], [0 4], 'linestyle', ':'); 

figure(4);from_x=-.5;to_x=1.5;
x=from_x:dt:to_x;
x_ind1=ceil((x1-from_x)/dt);
x2=-x1;
x_ind2=ceil((x2-from_x)/dt);
y=normpdf(x, 0, sigma);
y1=normpdf(x, 10.3-9.81, 0.4);

%subplot 121
plot(x,y);hold on; plot(x,y1,'-.')
p2=patch([x(x_ind1) x(x_ind1:x_ind2) x(x_ind2)],...
 [0 y1(x_ind1:x_ind2) 0], 'y', 'linestyle', 'none', 'erasemode', 'none');
line([x1 x1], [0 4], 'linestyle', ':'); line([x2 x2], [0 4], 'linestyle', ':'); 
set(gca,'xlim',[from_x to_x], 'xtick', [x1 x2], 'tickdir', 'out'); 

%subplot 122
figure(5)
plot(x,y);hold on; plot(x,y1,'-.')
line([x1 x1], [0 4], 'linestyle', ':'); line([x2 x2], [0 4], 'linestyle', ':'); 
p2=patch([x(x_ind2) x(x_ind2:floor((to_x-from_x)/dt)) x(floor((to_x-from_x)/dt))],...
 [0 y1(x_ind2:floor((to_x-from_x)/dt)) 0], 'y', 'linestyle', 'none', 'erasemode', 'none');
p1=patch([x(1) x(1:x_ind1) x(x_ind1) ],...
 [0 y1(1:x_ind1) 0], 'y', 'linestyle', 'none', 'erasemode', 'none');
set(gca,'xlim',[from_x to_x], 'xtick', [x1 x2], 'tickdir', 'out'); 
%ylabel('b)','rotation',0)

normcdf(-.19,0,.1)