In: Mechanical Engineering
Suppose that y = x2, where x is a normally distributed random variable with a mean and variance of µx = 0 and σ2x = 4. Find the mean and variance of y by simulation. Does µy = µ2x? Does σy = σ2x? Do this for 100, 1000, and 5000 trials.
Program plan:
• To find the mean and variance of the given equation where the variable is normally distributed.
Program:
%**********************************************************
%A matlab code is written to find the mean and variance of
%the given equation where the variable is the normally
%distributed number with mean 0 and variance 4.
%**********************************************************
%Declaration of constant
m=100;
%Declaration of 'm' random numbers
x=2.*randn(1,m);
%Computes the value
y=x.^2;
%Computes the mean of array
mu_y=mean(y);
%Displays text
disp('The mean of y is ');
%Displays value
disp(mu_y);
%Computes the standard deviation of the array
variance_y=std(y)^2;
%Displays text
disp('The variance of y is');
%Displays value
disp(variance_y);
Output:
The output is found for three values of ‘m’.
m=100;
>> Untitled
The mean of y is
3.9944
The variance of y is
37.7325
m=1000;
>> Untitled
The mean of y is
3.9331
The variance of y is
29.0860
m=5000;
>> Untitled
The mean of y is
4.0030
The variance of y is
31.4172
The output is found for three values of ‘m’.
m=100;
>> Untitled
The mean of y is
3.9944
The variance of y is
37.7325