The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

Posts: 1,268
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 " <> wrote in message <kecmk0$ln5$>...
> 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]

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

~ Jos

Date Subject Author
Read Re: Rand and sum of #s
Read Re: Rand and sum of #s

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.