Matlab 统计作业 代写: CS2035 Statistical Function Programming

这是一份统计(statistics)作业,要用用Matlab代写。需要随机生成uniform distribution 和 normal distribution,然后观察它们的histogram。需要自己实现两个小函数计算两种分布的skewness和kurtosis,公式分别如下:
skewness

kurtosis
Introduction

You are to write 4 MatLab functions for this assignment. All your functions should be coded in a single file called ass1 2017.m. The first function in this file is called ass1 2017 with a single input parameter num x. There are no output parameters. num x speci-fies the number of random numbers to be computed and stored in variables x (uniformly distributed random numbers) or y (for normally distributed random numbers). Note that parameter num x is originally a character string and so has to be converted to an inte-
ger (num x=str2num(num x)) before any calculations can be done with it. For example, str2num(’123456’) return the number 123456 as its output. You call your program from the command line, for example ass1 2017 1000000 will set num x to 1000000. bf x and y can be computed as x=rand(num x,1,’double’) and y=randn(num x,1,’double’) respectively.

One possible set of histograms you might obtain are shown in Figure 1 below.

Your program should perform the following tasks:

1. The ass1 2017 function first plots titled histograms of x=rand(num x,n) and y=randn(num x,n) using the MatLab built-in hist function. The title of the his-
tograms should indicate the value of num x. To generate the title you have to use string concatenation to construct the appropriate string for the title, for example, one title string, stg, might be stg=[’num x=’ num2str(num x) ]’ (but you can do better than this). After the histogram is plotted, use the MatLab function title(stg) to title your plot with your stg.

2. Next, the ass1 2017 function should compute the skewness and kurtosis values of x and y using MatLab built-in functions, skewness and bf kurtosis. Then, using the 2nd and 3rd functions that you write, namely my skewness and my kurtosis, you should again compute these values for x and y. You should get the same values. Your functions should use arrays and should not use any other MatLab functions (other than sqrt) in their calculations. This means, for example, that you must compute the average of x and y with your own code and not use mean(x) or mean(y). If you need the sum of some array x, you need to sum the elements of x explicitly in a loop and not use sum(x).

From MatLab online documentation:

Skewness is a measure of the asymmetry of the data around the sample mean. If skewness is negative, the data are spread out more to the left of the mean than to the right. If skewness is positive, the data are spread out more to the right. The skewness of the normal distribution (or any perfectly symmetric distribution) is zero.

Next, you must code a 4th function generate distribution with header:

[x,min_x1,max_x1,min_x2,max_x2]=generate_distribution(low_bound_x,high_bound_x,num_x).

This function computes num x uniformly distributed random numbers between low bound x and high bound x. Output parameter x contains these numbers. min x1 and max x1 contain the minimum and maximum values returned by rand(num x,1,’double’). Note that these are not necessarily 0 and 1 but numbers quite close to these values. We can scale x to be precisely between 0 and 1 by using the relationship x=(x-min x1)/(max x1- min x1). in this case x is rescaled by the vectorized MatLab statement just given.

The minimum and maximum of scaled x are saved in output parameters min x2 and max x2. These should be precisely 0 and 1. Note that the real reason in having gener-
ate distribution the before and after min and max values of x returned is so that you have experience with a function that returns more than 1 parameter.

Lastly, you must scale x to be between low bound x and high bound x. Ensure that low bound x is indeed less than high bound x before any calculation is done.

Print a fatal error message and quit the program if this condition (low bound x < high bound x) is not satisfied (just exit the function using the return statement). Use an if-then-else statement to code this. Multiplying x by (high bound x-low bound x) makes x be between 0 and (high bound x-low bound x). Adding low bound x fin-ishes the calculation as the x values are now between low bound x and high bound x.

After generate distribution has be executed, print out the values of min x1 and max x1 and min x2 and max x2 and low bound x and high bound x. Also print out the average and median of x using mean and median.

Given this scaled x value, use sum(x) to add its values. Compare this sum to the addition of the sorted values of x (sum(sort(x))). Compute the difference of the two sums. Write a comment in your code explaining why this difference occurs (why it is not 0) and which sum you expect to be more accurate.

Lastly consider the number 1.0e64. Note that e means exponent, that is 1.0e64 is 1.0×1064 in scientific notation. This is a large number. Store it in variable b. Determine another variable a that is non-zero and yet when added to b yields a+b=b. Verify this addition in your program. a is a relative zero for b.

kamisama wechat
KamiSama