Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting Probability Distribution Functions with limits

Subject: Plotting Probability Distribution Functions with limits

From: Zac

Date: 26 Sep, 2010 01:00:19

Message: 1 of 3

Hi,

I am plotting the data

4*exp(-2*x - y)

as a probability density function. It has limits of

0<x and 0<y<2x

I can't figure out how to tell Matlab these limits. The 'greater than zero' one is easy enough, I just make my meshgrid to go between zero and out to where it gets less interesting.

In my desperation I even tried to multiply the whole function by

(((2*x-y)/abs(2*x-y))+1)/2

(i.e make all values zero at the points where y is greater than 2x) but this didn't work.

I can't get the pdf function to do any better.
Any help on how to get this to work would be appreciated.

Thank you,

Zac

Subject: Plotting Probability Distribution Functions with limits

From: Roger Stafford

Date: 26 Sep, 2010 02:17:04

Message: 2 of 3

"Zac " <30988z2@gmail.com> wrote in message <i7m5v3$adi$1@fred.mathworks.com>...
> Hi,
>
> I am plotting the data
>
> 4*exp(-2*x - y)
>
> as a probability density function. It has limits of
>
> 0<x and 0<y<2x
>
> I can't figure out how to tell Matlab these limits. The 'greater than zero' one is easy enough, I just make my meshgrid to go between zero and out to where it gets less interesting.
>
> In my desperation I even tried to multiply the whole function by
>
> (((2*x-y)/abs(2*x-y))+1)/2
>
> (i.e make all values zero at the points where y is greater than 2x) but this didn't work.
>
> I can't get the pdf function to do any better.
> Any help on how to get this to work would be appreciated.
>
> Thank you,
>
> Zac
- - - - - - - - -
  I assume you are trying to make a surface plot of this function with the surf function. Just define the auxiliary variable t = y/(2*x) and make a meshgrid of x and t. Then convert to x and y.

 [X,T] = meshgrid(linspace(0,interesting),linspace(0,1));
 Y = 2*X.*T;
 Z = 4*exp(-2*X-Y);
 surf(X,Y,Z)

where 'interesting' is the large value you mentioned.

  I don't know if 'surf' will be upset having a hundred coincident pairs of X and Y all exactly equal to zero. If so, you could fudge the plot a tiny bit away from zero.

Roger Stafford

Subject: Plotting Probability Distribution Functions with limits

From: Zac

Date: 27 Sep, 2010 01:44:05

Message: 3 of 3

Worked perfectly, thanks heaps.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us