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: 9,850
Registered: 6/7/07
Re: Rand and sum of #s
Posted: Jan 31, 2013 5:46 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 1/30/2013 8:58 PM, Sean wrote:
> 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)


Well, there is no variable "result" and you've aliased the builtin
function 'sum()' and how would you expect that sum() would have known
you wanted 'r' as it's input when you gave it a vector of two integers???

Start w/ the "Getting Started" section tutorial and work your way
through some beginning steps...

For the question you've asked,

r=rand(53,1); % don't need the [] to make inputs a vector
s=sum(r); % sum up the values you got...
disp(s) % or forget trailing ";" & ML will echo automagically


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.