Hw in matlab about joint probability >

AI Thread Summary
The discussion focuses on coding a joint probability distribution for discrete random variables X and Y in MATLAB, specifically addressing issues with the provided code. Users suggest expanding the grid for X and Y to achieve a more accurate representation of the joint cumulative distribution function (CDF) by using finer sampling intervals. Additionally, it is recommended to avoid MATLAB's heaviside function due to its potential inaccuracies in probability calculations and to consider creating a custom unit step function. Finally, various 3D plotting functions in MATLAB, such as surf and meshgrid, are highlighted as useful tools for visualizing the joint distribution. Overall, the conversation emphasizes improving the code for better accuracy and visualization in MATLAB.
maiad911
Messages
2
Reaction score
0

Homework Statement


i'd try to write the code for this question :(Discrete random variable X & Y have a joint distribution : Fx,y(x,y)=0.1u(x+4)u(y-1)+0.1u(x+3)u(y+5)+0.17u(x+1)u(y-3)+0.05u(x)u(y-1)+0.18u(x-2)u(y+2)+0.23u(x-3)u(y-4)+0.12u(x-4)u(y+3)


Homework Equations


I try this code in MATLAB but it doesn't work :
>> x=[-4 -3 -1 0 2 3 4];
>> y=[1 -5 3 1 -2 4 -3];
>> [X Y] = meshgrid(x,y);
>> Z =0.1.*heaviside(x+4).*heaviside(y-1)+0.15.*heaviside(x+3).*heaviside(y+5)+0.17.*heaviside(x+1).*heaviside(y-3)+0.05.*heaviside(x).*heaviside(y-1)+0.18.*heaviside(x-2).*heaviside(y+2)+0.23.*heaviside(x-3).*heaviside(y-4)+0.12.*heaviside(x-4).*heaviside(y+3);


The Attempt at a Solution


please can you figure where is the problem ?
 
Physics news on Phys.org
maiad911 said:

Homework Statement


i'd try to write the code for this question :(Discrete random variable X & Y have a joint distribution : Fx,y(x,y)=0.1u(x+4)u(y-1)+0.1u(x+3)u(y+5)+0.17u(x+1)u(y-3)+0.05u(x)u(y-1)+0.18u(x-2)u(y+2)+0.23u(x-3)u(y-4)+0.12u(x-4)u(y+3)

Homework Equations


I try this code in MATLAB but it doesn't work :
>> x=[-4 -3 -1 0 2 3 4];
>> y=[1 -5 3 1 -2 4 -3];
>> [X Y] = meshgrid(x,y);
>> Z =0.1.*heaviside(x+4).*heaviside(y-1)+0.15.*heaviside(x+3).*heaviside(y+5)+0.17.*heaviside(x+1).*heaviside(y-3)+0.05.*heaviside(x).*heaviside(y-1)+0.18.*heaviside(x-2).*heaviside(y+2)+0.23.*heaviside(x-3).*heaviside(y-4)+0.12.*heaviside(x-4).*heaviside(y+3);

The Attempt at a Solution


please can you figure where is the problem ?

Homework Statement


Homework Equations


The Attempt at a Solution

The question you stated is a statement. What are you supposed to do in MATLAB with that given information?
 
Last edited:
i want the sketch for the joint cdf in matlab
 
A few things to mention:
You want to have a large grid of values to evaluate your 2d function. You do not want only the values where you have a jump in your cdf. So forget your definition of x and y. Instead, say [X Y] = meshgrid(-6:.01:6, -6:01:6); Or something similar. You want to have a nice xy sampling of your function, so size your x and y appropriately. If your function is grainy or inaccurate, you can bump up the step in between samples.

Second, you may want to avoid using the heaviside definition in MATLAB and simply write your own unit step. In probability, we think of gaining all of the probability at the exact instant the impulse is evaluated. For example, if you had two impulses, one nonzero at x = 1 and the other at x = 3, both of height .5, you would expect p[x <= 1] = .5. You would not expect it to be .25 (which the MATLAB heaviside will give you). Since there are hundreds of points, and only a few of them will invoke the 1/2 definition of the MATLAB heaviside (in conjunction to being right next to a multitude of 1.0 evaluations), it may not be an issue. Just do the plot and make sure you don't see an odd half step before each real step.

Third, there are numerous functions in MATLAB to do 3d plots for various applications. I just ran a Google search and arrived to surf(X,Y,Z). I also plugged in a meshgrid and your function, and it created what I would expect. Here is a reference of a list of 3d plotting functions native to MATLAB:
http://www.mathworks.com/help/techdoc/ref/mesh.html

Use the navigator on the left to explore your options.
 

Similar threads

Replies
1
Views
2K
Replies
2
Views
2K
Replies
10
Views
2K
Replies
3
Views
2K
Replies
6
Views
2K
Replies
7
Views
2K
Replies
4
Views
3K
Replies
1
Views
273
Back
Top