Hw in matlab about joint probability >

In summary: I am sure one will work for you.In summary, the problem is likely in the way you are defining your x and y values and possibly in the way you are using the heaviside function. Also, consider looking up different 3d plotting techniques in MATLAB.
  • #1
maiad911
2
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
  • #2
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:
  • #3
i want the sketch for the joint cdf in matlab
 
  • #4
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.
 
  • #5


Hi there,

I am sorry to hear that your code is not working. Without knowing the exact error message you are getting, it is difficult for me to pinpoint the exact problem. However, here are a few suggestions that may help you in solving the issue:

1. Make sure you are using the correct syntax for the heaviside function. In MATLAB, the syntax is "heaviside(x)" and it returns 0 for x < 0, 0.5 for x = 0, and 1 for x > 0.

2. Check your variables and make sure they are defined correctly. In your code, you have defined x and y as vectors, but in the homework statement, they are described as discrete random variables. Make sure you are using the correct variables in your code.

3. Double check your calculations. It is possible that there may be a mistake in the calculations, which is causing the code to not work properly.

I hope these suggestions help you in solving the issue. If you are still having trouble, I would recommend reaching out to your instructor or a classmate for assistance. Good luck!
 

What is joint probability in Matlab?

Joint probability in Matlab refers to the probability of two or more events occurring simultaneously. It is calculated by multiplying the individual probabilities of each event.

How do I calculate joint probability in Matlab?

To calculate joint probability in Matlab, you can use the built-in function "jointp" which takes in the probability distribution of each event as input.

Can I visualize joint probability in Matlab?

Yes, you can visualize joint probability in Matlab using tools such as histograms, scatter plots, or contour plots.

What is the difference between joint probability and conditional probability in Matlab?

Joint probability refers to the probability of two events occurring together, while conditional probability refers to the probability of one event occurring given that another event has already occurred. They can both be calculated in Matlab using different functions.

How is joint probability useful in data analysis?

Joint probability is useful in data analysis as it allows us to understand the relationship between multiple variables and their likelihood of occurring together. It can also help in identifying patterns and making predictions based on the data.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
865
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
840
  • Engineering and Comp Sci Homework Help
Replies
7
Views
875
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
801
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top