function []=propagation(sigma)
%propagation d'erreur
% exemple du cours  x'=x^2+3x -2y+5
% function []=propagation(sigma)
mu = [0 0];
cov = sigma*[1 0  ; 0 2 ]; 

R = chol(cov);
z = repmat(mu,2000,1) + randn(2000,2)*R;
figure;plot(z(:,1),z(:,2),'+r')
title('Echantillonnage de la v.a. initiale');

%transformation
u= z(:,2).^2 +3*z(:,1)-2*z(:,2) +5;
figure;plot(u,'+g');
title('Les données transformées');

figure; hist(u,100);hold on;
h=hist(u,100);

% affichage de la distribution
figure; histogram(u,'normalization','probability')

% 
% h1=h/sum(h);
% figure; bar(h1,'DisplayName','normalise');hold on;

%affichage de la distribution propagée
e_pred=5;
J=[3, -2];
cov_pred=J*cov*J';

r = sqrt(cov_pred);
z = repmat(e_pred,2000,1) + randn(2000,1)*r;
% h_pred=hist(z,100);
% h_pred_norm= h_pred/sum(h_pred);
% figure; bar(h_pred_norm);


% affichage de la distribution
figure; ht1=histogram(u,'normalization','probability','BinLimits',[-20, 40]);hold on;
title('Comparaison des deux distributions ');
ht2=histogram(z, 'normalization','probability','BinLimits',[-20, 40]);
ht1.NumBins=100;
ht2.NumBins=100;

