Michael Grosswald wrote:
> I'm trying to generate random matrices whose entries are from the normal distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each
> entry. How can I correct this or am I going about this the wrong way.
> I'm still a MATLAB beginner so go easy on me!
Well,
lookfor normal
returns
>> lookfor normal
RANDN Normally distributed random numbers.
...
SPRANDN Sparse normally distributed random matrix.
...
which might look interesting... :)
As for the question on squaring terms in an array (or vector), look at
".*" instead of "*"
This will take your matrix and square it element by element.
.* is similar.
Doug
"Michael Grosswald" <michaelgrosswald@yahoo.co.uk> wrote in message <h9tpd6$bh9$1@fred.mathworks.com>...
> I'm trying to generate random matrices whose entries are from the normal distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each entry. How can I correct this or am I going about this the wrong way.
>
> I'm still a MATLAB beginner so go easy on me!
> I'm trying to generate random matrices whose entries are from the normal
> distribution.
>
> Something like this:
>
> (1/(sqrt(2*pi)))*exp(-(1+99*rand(5))^2/2)
>
> Isn't going to work because squaring a matrix doesn't square each entry.
> How can I correct this or am I going about this the wrong way.
Michael, if you square the matrix, this will give you values of the normal
density function evaluated at random points. I encourage you to try the
advice from dbp instead of squaring the matrix in this formula.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.