Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Rand and sum of #s
Replies: 2   Last Post: Jan 31, 2013 5:46 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jos

Posts: 1,266
Registered: 10/24/08
Re: Rand and sum of #s
Posted: Jan 31, 2013 5:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Sean " <swalsh@nmt.edu> wrote in message <kecmk0$ln5$1@newscl01ah.mathworks.com>...
> So I'm using this code
> % Create a vector of 53 random #s and analyze them.
> r = rand([53,1])
> % The sum of all the random numbers
> sum=sum(([53,1]))
> disp(result)
>
> But it doesn't seem to be working.
> I'm new to ML
> How do I find the sum (and product) of the random numbers?


SUM is the name of a function that expects an input. Such an input can be numbers directly
sum([1 2 3])
or these numbers can be stored in a variable
myvariable = [3 4 5]
sum(myvariable)

You may wish to store the result of SUM into a new variable
myresult = sum(...) % replace ...

Be careful how you name your variables. If the happen to be the same name as functions (as in your code above), that function is no longer available until you CLEAR the variable.

RAND is a also function, DISP too ... I do suggest you read the Getting Started section of the documentation and good luck in ML-ing

hth
~ Jos


Date Subject Author
1/31/13
Read Re: Rand and sum of #s
Jos
1/31/13
Read Re: Rand and sum of #s
dpb

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.