Hw in matlab about joint probability >

Click For Summary

Discussion Overview

The discussion revolves around a homework problem involving the joint probability distribution of discrete random variables X and Y, specifically focusing on coding this distribution in MATLAB. Participants explore issues related to the implementation of the code and the visualization of the joint cumulative distribution function (CDF).

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant shares their attempt to code the joint distribution in MATLAB but encounters issues with the implementation.
  • Another participant questions the clarity of the original homework statement and asks for more specific instructions on what to do with the provided information.
  • A suggestion is made to use a larger grid for evaluating the 2D function to avoid inaccuracies in the CDF due to limited sampling.
  • It is proposed to avoid using the built-in heaviside function in MATLAB and instead create a custom unit step function to better represent the probability distribution.
  • Participants mention various MATLAB functions for 3D plotting, suggesting that the surf function could be useful for visualizing the joint distribution.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to implement the joint distribution in MATLAB, particularly regarding the use of the heaviside function and the grid size for sampling. The discussion remains unresolved as no consensus is reached on the optimal coding strategy.

Contextual Notes

Some limitations are noted, such as the potential inaccuracies in the CDF due to the choice of grid size and the behavior of the heaviside function in MATLAB. There are also unresolved questions regarding the specific requirements of the homework task.

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 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K