Skip to main content
1-Visitor
February 24, 2021
Solved

matlab randn function in mathcad

  • February 24, 2021
  • 2 replies
  • 2961 views

How to generate random values in Mathcad exactly like randn function generates in matlab?

Best answer by Werner_E

@SK_9833315 wrote:

How to generate random values in Mathcad exactly like randn function generates in matlab?


That depends on how you would define "exactly" 🙂

If your goal is to create a couple of normal distributed random numbers, rnorm(n,0,1) may be all you need, as shown by Francesco.
In Matlab the output of randn is either a single scalar or a multidimensional matrix (n x 1 vector being only a special case of it). Mathcad on the other hand will only create a  n x 1 vector. So this is a limitation, but on the other hand its easier in Mathcad to use different  values for mean and standard deviation.

 

To create single scalars and matrices  in Mathcad you will have to use some additional bits of code.

Here are some examples:

Werner_E_0-1614184678155.png

 

If you use these more often, it may be convenient to create some functions to do the job:

Werner_E_1-1614184746088.png

 

 

2 replies

21-Topaz II
February 24, 2021

rnorm ?:

rnorm.jpgrnorm.jpg

Werner_E25-Diamond IAnswer
25-Diamond I
February 24, 2021

@SK_9833315 wrote:

How to generate random values in Mathcad exactly like randn function generates in matlab?


That depends on how you would define "exactly" 🙂

If your goal is to create a couple of normal distributed random numbers, rnorm(n,0,1) may be all you need, as shown by Francesco.
In Matlab the output of randn is either a single scalar or a multidimensional matrix (n x 1 vector being only a special case of it). Mathcad on the other hand will only create a  n x 1 vector. So this is a limitation, but on the other hand its easier in Mathcad to use different  values for mean and standard deviation.

 

To create single scalars and matrices  in Mathcad you will have to use some additional bits of code.

Here are some examples:

Werner_E_0-1614184678155.png

 

If you use these more often, it may be convenient to create some functions to do the job:

Werner_E_1-1614184746088.png

 

 

1-Visitor
February 25, 2021

Thanks it was helpful