• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. clc, clear
2. % Create three distribution objects with different parameters
3. pd1 = makedist('Uniform','lower',2,'upper',6);
4. pd2 = makedist('Uniform','lower',2,'upper',4);
5. pd3 = makedist('Uniform','lower',5,'upper',6);
6. % Compute the pdfs
7. x = -1:.01:9;
8. pdf1 = pdf(pd1,x);
9. pdf2 = pdf(pd2,x);
10. pdf3 = pdf(pd3,x);
11. % Sum of uniforms
12. pdf = (pdf1 + pdf2 + pdf3);
13. % Plot the pdfs
14. figure;
15. stairs(x,pdf,'r','LineWidth',2);
16.
17. pdf = pdf/sum(pdf);
18.
19. % MATLAB R2018b
20. pd1 = makedist('Uniform',2,6);
21. pd2 = makedist('Uniform',2,4);
22. pd3 = makedist('Uniform',5,6);
23. a = 0.25;
24. b = 0.35;
25. c = 1 - a - b;    % a + b + c = 1
26.
27. pdfMix =@(x) a.*pdf(pd1,x) + b.*pdf(pd2,x) + c.*pdf(pd3,x);
28.
29. Xrng = 0:.01:8;
30. plot(Xrng,pdfMix(Xrng))
31. xlabel('X')
32. ylabel('Probability Density Function')
33.
34. N = 80000;                  % Number of samples
35. X1 = random(pd1,N,1);       % Generate samples
36. X2 = random(pd2,N,1);
37. X3 = random(pd3,N,1);
38.
39. X = X1 + X2 + X3;           % Convolution
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top