From: Kevin on 7 May 2010 06:22 I am trying to run the function t= M/(R/n), where R is a random number generated between 15 and 25. What function do i use to run this simulation 10,000 times and calculate the mean and std error from 306. This is what i have so far M=74 n=88 No=306 R= RandomReal[{15,23}] t= M/(R/n) t = x; Do[t = M/(R/n), {10000}] Everything is working for me except how to run the simulation 10,000 times
From: Bob Hanlon on 8 May 2010 07:06 M = 74; n = 88; No = 306; R = RandomReal[{15, 23}, {10000}]; t = M/(R/n); mu = Mean[t] 348.482 No - mu -42.4819 StandardDeviation[t] 43.0218 Bob Hanlon ---- Kevin <kxcarmichael250(a)hotmail.com> wrote: ============= I am trying to run the function t= M/(R/n), where R is a random number generated between 15 and 25. What function do i use to run this simulation 10,000 times and calculate the mean and std error from 306. This is what i have so far M=74 n=88 No=306 R= RandomReal[{15,23}] t= M/(R/n) t = x; Do[t = M/(R/n), {10000}] Everything is working for me except how to run the simulation 10,000 times
From: Bill Rowe on 8 May 2010 07:07 On 5/7/10 at 6:28 AM, kxcarmichael250(a)hotmail.com (Kevin) wrote: >I am trying to run the function t= M/(R/n), where R is a random >number generated between 15 and 25. What function do i use to run >this simulation 10,000 times and calculate the mean and std error >from 306. >M=74 >n=88 >No=306 >R= RandomReal[{15,23}] You do not want to use Set here. with this code, RandomReal[{15,23}] will evaluate and the result will be assigne to R. All future references to R will use this value, not a new random value. To get a new random value every time R is used this last should be r:= RandomReal[{15,23}] Note also, I've used a lower case letter rather than the upper case you chose. All internal Mathematica symbols start with an upper case letter and several consist of a single upper case letter. By using lower case letters for your variables you are guaranteed they will not conflict with pre-existing Mathematica names. >t= M/(R/n) This assigns a fixed value to t >t = x; This assign whatever x evaluates to t and does nothing useful given the rest of your code >Do[t = M/(R/n), {10000}] This assigns the same fixed value of t that was used earlier and does it 10,000 times. >Everything is working for me except how to run the simulation 10,000 >times Your code is valid Mathematica syntax and will run without error. But it certainly does not solve the problem you've indicated you are trying to solve. The simplest way I can think of to solve your problem is to do r=RandomReal[{15,23},10000]; That generates a list of 10,000 random reals between 15 and 23 and assigns it to r. Now the mean and standard deviation can be easily computed as: Mean[74/(r/88)] StandardDeviation[74/(r/88)] or as the difference from 306 Mean[74/(r/88) - 306] StandardDeviation[74/(r/88) - 306] Also note, I've used Set (=) when defining r. If SetDelayed (:=) were used here, the list of random values would used for computing the mean would be different than those used for computing the standard deviation.
From: Joe Hays on 8 May 2010 07:08 I would use a FOR loop and collect the generated points in a preallocated vector like, M=74; n=88; T = Range[10000]; For[i=1, i<=10000, i++, R= RandomReal[{15,23}]; T[[i]]= M/(R/n); ]; myMean = Mean[T]; However, this is very much a procedural programming approach. I'm sure the Mathematica experts helping on this list can provide a more efficient approach... Joe On Fri, May 7, 2010 at 6:28 AM, Kevin <kxcarmichael250(a)hotmail.com> wrote: > I am trying to run the function t= M/(R/n), where R is a random number > generated between 15 and 25. What function do i use to run this simulation > 10,000 times and calculate the mean and std error from 306. > > This is what i have so far > M=74 > n=88 > No=306 > R= RandomReal[{15,23}] > t= M/(R/n) > t = x; Do[t = M/(R/n), {10000}] > > Everything is working for me except how to run the simulation 10,000 times > >
From: Bill Rowe on 9 May 2010 07:51 On 5/8/10 at 7:08 AM, hays.joe(a)gmail.com (Joe Hays) wrote: >I would use a FOR loop and collect the generated points in a >preallocated vector like, >M=74; >n=88; >T = Range[10000]; >For[i=1, i<=10000, i++, >R= RandomReal[{15,23}]; >T[[i]]= M/(R/n); >]; >myMean = Mean[T]; >However, this is very much a procedural programming approach. I'm >sure the Mathematica experts helping on this list can provide a more >efficient approach... One thing about efficiency. Doing: myMean = Mean[M/(RandomReal[{15,23}, 10000]/n)] is far more efficient than the loop in terms of execution speed. But the For loop, is far more efficient in terms of memory used since the loop does not need memory for a large array.
|
Pages: 1 Prev: Giving several functions the same argument Next: 2D phase unwrapping |