Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- How to use runif(1,1,7) in a program loop?

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-20-2012
11:42 AM

08-20-2012
11:42 AM

This works:

jx:=10 j:=0..jx k:=0..2 x[j,k:=ceil(rnd(7)) x= displays a 3by10 mateix of integers 1,2,..7

This does not work: x[j,k:=ceil(runif(1,1,7)) x= displays a 3by10 matrix of [1,1] in every cell.

ceil(runif(1,1,7)) works by itself but not as I'm using it (above).

Any suggestions will be appreciated.

Ed

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-20-2012
11:55 AM

08-20-2012
11:55 AM

Hi Ed,

Rnd() returns a number so everything is OK,

Runif(,,,) returns a vector , so each element is saved as a 1x1 vector within the array.

In this case you can de-vectorise the number as:

ceil(runif(1,1,7)[0)

which seems to work for me

regards

Andy

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-20-2012
11:55 AM

08-20-2012
11:55 AM

Hi Ed,

Rnd() returns a number so everything is OK,

Runif(,,,) returns a vector , so each element is saved as a 1x1 vector within the array.

In this case you can de-vectorise the number as:

ceil(runif(1,1,7)[0)

which seems to work for me

regards

Andy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-20-2012
12:51 PM

08-20-2012
12:51 PM

Re: How to use runif(1,1,7) in a program loop?

Made my day! Works perfectly.

Thanks Westerman, hope to return the favor some day.

Ed