Question

In: Electrical Engineering

Write a MATLAB function that will generate chi-square random variables with v degrees of freedom by...

Write a MATLAB function that will generate chi-square random variables with v degrees of freedom by generating v standard normal, squaring them and then adding them up. This uses the fact that is chi-square with v degrees of freedom. Generate some random variables and plot in a histogram. The degrees of freedom should be an input argument set by the user.

Solutions

Expert Solution

Matlab Code:

clc;clear;
v = input('Enter the value of v \n')
R = randn(1,v)

for i = 1:1:length(R)
X(i) = 0;
for j = 1:1:i
X(i) = X(i) + R(i)^2;
  
end
end
X
figure;
hist(X)
grid on

---------------------------------

Command Window:

----------------------------------------

Enter the value of v
100

v =

100


R =

Columns 1 through 12

-0.2444 -1.4851 -0.3562 0.3545 1.8349 0.8977 0.2523 0.9840 -0.5146 -1.3107 -0.6873 -1.1855

Columns 13 through 24

0.9824 -0.1353 -1.1900 -0.2073 -0.8456 -0.3143 1.4243 1.4915 -0.7440 -0.3744 0.4241 0.1141

Columns 25 through 36

-0.5111 1.0223 -1.4192 2.5467 -0.3580 0.4013 -0.7062 -1.0207 1.1340 0.0385 0.2309 0.1257

Columns 37 through 48

0.6963 1.7395 0.6654 0.6875 1.2390 0.8987 -1.1501 -0.2642 -1.6252 0.5816 1.9025 1.5801

Columns 49 through 60

0.9210 -0.9379 -0.7372 0.1798 -0.1318 0.8679 1.3144 -0.2511 -0.0718 1.0952 0.4893 -1.6802

Columns 61 through 72

-0.8115 -0.7522 -1.3259 -0.1815 0.1314 1.3938 0.7062 1.1628 -0.7537 0.3219 1.6357 -0.6478

Columns 73 through 84

0.6733 1.2736 -1.0398 0.4880 -0.9068 -0.4747 -0.6661 -0.5020 -0.3089 -0.8369 -0.6283 0.5009

Columns 85 through 96

1.6703 -1.5417 -0.2720 0.3416 0.4844 0.9527 0.1314 -1.7419 0.6678 0.8982 -0.5493 -0.3175

Columns 97 through 100

-0.5827 -0.1642 -0.9351 1.1881


X =

Columns 1 through 12

0.0597 4.4108 0.3806 0.5027 16.8345 4.8351 0.4456 7.7465 2.3830 17.1781 5.1964 16.8639

Columns 13 through 24

12.5461 0.2565 21.2429 0.6876 12.1561 1.7781 38.5429 44.4901 11.6258 3.0835 4.1369 0.3125

Columns 25 through 36

6.5305 27.1745 54.3802 181.5961 3.7158 4.8317 15.4600 33.3361 42.4336 0.0505 1.8662 0.5691

Columns 37 through 48

17.9381 114.9792 17.2664 18.9080 62.9368 33.9190 56.8772 3.0708 118.8545 15.5622 170.1155 119.8415

Columns 49 through 60

41.5664 43.9831 27.7156 1.6807 0.9211 40.6780 95.0194 3.5314 0.2935 69.5700 14.1243 169.3750

Columns 61 through 72

40.1730 35.0822 110.7579 2.1079 1.1226 128.2223 33.4154 91.9505 39.1951 7.2545 189.9625 30.2139

Columns 73 through 84

33.0897 120.0238 81.0906 18.0952 63.3096 17.5768 35.0501 20.1619 7.7283 57.4331 32.7676 21.0760

Columns 85 through 96

237.1285 204.4161 6.4370 10.2716 20.8804 81.6846 1.5700 279.1521 41.4692 75.8283 28.6660 9.6774

Columns 97 through 100

32.9346 2.6426 86.5729 141.1599

>>

------------------------------------


Related Solutions

What is the critical value for a chi-square test with 13 degrees of freedom at the...
What is the critical value for a chi-square test with 13 degrees of freedom at the 1 percent level of significance? If the chi-square test statistic were 16.98, what would you conclude regarding the null hypothesis? What would you conclude if the chi-square value were 68.03? (30 points)
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
QUESTION 10 For a chi-square goodness-of-fit test, what is the number of degrees of freedom, if...
QUESTION 10 For a chi-square goodness-of-fit test, what is the number of degrees of freedom, if the number of categories in the distribution is 9? what is the critical value for a 1% level of significance?
7.2 Question 1 Give the degrees of freedom for the chi-square test based on the two-way...
7.2 Question 1 Give the degrees of freedom for the chi-square test based on the two-way table. D E F G Total A 39 34 43 34 150 B 78 89 70 93 330 C 23 37 27 33 120 Total 140 160 140 160 600 Degrees of freedom = b. Find the expected count and the contribution to the chi-square statistic for the (Group 2, Yes) cell in the two-way table below. Yes No Group 1 733 255 Group...
If 15 observations are taken independently from a chi-square distribution with fifteen degrees of freedom, find...
If 15 observations are taken independently from a chi-square distribution with fifteen degrees of freedom, find the probability that at most ten of the 15 observations are less than 10. Show your work.
Give Chi square, degrees of freedom, probability and accept/reject. Round all numbers to two decimals throughout....
Give Chi square, degrees of freedom, probability and accept/reject. Round all numbers to two decimals throughout. Make sure to show all your work: In corn, purple kernels are dominant over yellow kernels, and full kernels are dominant over shrunken kernels. A corn plant with purple, full kernels is crossed with a plant having purple, full kernels. The following progeny are obtained: Purple, full                   100 Purple, shrunken          36 Yellow, full                   30 Yellow, shrunken          8 Determine the genotypes of the parents and...
Suppose that x2 follows a chi-square distribution with 30 degrees of freedom. Compute P(17≤x2≤ 46). Round...
Suppose that x2 follows a chi-square distribution with 30 degrees of freedom. Compute P(17≤x2≤ 46). Round your answer to at least three decimal places. Suppose again that x2 follows a chi-square distribution with 30 degrees of freedom. Find k such that P(x2≥ k) = 0.01.   Round your answer to at least two decimal places. Find the median of the chi-square distribution with 30 degrees of freedom. Round your answer to at least two decimal places.
Assume that random variable x^2 has a chi-squared distribution with v degree of freedom. Find the...
Assume that random variable x^2 has a chi-squared distribution with v degree of freedom. Find the value of “A” for the following cases 1) P(X^2 <=A) =.95 when v = 6 2) P(X^2>=A) =.01 when v = 21 3) P(A <= X^2 <= 23.21)= .015 when v = 10.
Let X1 and X2 be two independent random variables having a chi-squared distribution with degrees of...
Let X1 and X2 be two independent random variables having a chi-squared distribution with degrees of freedom n1 and n2, respectively. Let Y1 = (X1) / (X1 + X2) and Y2 = X1 + X2 (a) Find the joint p.d.f. of Y1 and Y2 (b) Find the marginal p.d.f. of each of Y1 and Y2 (c) Are Y1 and Y2​​​​​​​​​​​​​​ independent ? Justify your answer.
Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT