0

I want to plot the following on the same piece of paper.

The pdf of exponential distribution with parameter 5 The pdf of t distribution with parameter 15

I don't know how to draw the pdf but know how to plot several figure on the same piece of paper by using command subplot()

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
user2983722
  • 215
  • 1
  • 3
  • 11
  • if you define some x, e.g. x = linspace(-10,10,1e3); then you could calculate pdf(x) and plot it. Which step isn't clear for you? – Chris Nov 16 '13 at 11:22
  • @Chris `x=linspace(-10,10,1e3),pdf = exppdf(x,10),plot(pdf)` . Is that right? The figure seems something wrong. – user2983722 Nov 16 '13 at 12:16
  • 1
    Well, it's just that the exponential distribution is defined for x >= 0. Other than that you can also try plot(x,pdf). – Chris Nov 16 '13 at 12:20

1 Answers1

0

Method 1: Use built-in functions (requires Statistics toolbox)
Using exppdf() and tpdf() is easy but requires the Statistics Toolbox. If you don't have those functions then you can always directly code the PDF functions (Student's t and Exponential) as in Method 2 below.

Note that MATLAB parameterizes the Exponential distribution by the mean which is the inverse of the rate (lambda).

lambda = 5;     
nu = 15;

Xrng = 0:.01:2;
Yrng = -5:.01:5;    

figure
subplot(1,2,1)
plot(Xrng,exppdf(Xrng,1/lambda),'k-')
subplot(1,2,2)
plot(Yrng,tpdf(Yrng,nu),'b-')

Method 2: Hard-code PDF functions directly (no toolbox required)
You can always directly code the PDF functions (Student's t and Exponential).

fexph =@(x) lambda*exp(-lambda*x);
fth =@(x) (1/(sqrt(nu)*beta(0.5,0.5*nu)))*((1+((x.^2)./nu)).^(-0.5*(nu+1)));


figure
subplot(1,2,1)
plot(Xrng,fexph(Xrng),'k-')
subplot(1,2,2)
plot(Yrng,fth(Yrng),'b-')
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41