Making Normal Gauss Random variable
If you use randn to making normal random variable, that will be only half success.
Because randn can't create a matrix with a mean of exact 0 and a standard deviation of exact 1.
Also, it is inconvenient to make variable that has mean and deviation that we want.
To solve the problems above, We can simply transform variable that made by randn.
-
First
Get Matrix A and b.
function x=wgauss(mx, vx, nx)
Making function.
mx is 'Average (mean value)' that you want to get.
vx is 'Variance' that you want.
nx is 'Number of Variable'. -
Second
Transform variable that made by randn.
x=sqrt(vx).*((k-km)/sqrt(kv))+mx;
-
Third
Then you can get variable set that has exact value of mean and deviation we want.
- I uploaded only function m-file. So, you should write your own script m-file.
- I am hoping that my code can help other undergraduate students' assignments.