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 ]
dpb

Posts: 7,881
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
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.