![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Adopt a function that generate random values to a programHey guys:
I am writting a program to analysis beam deflection with random beam stiffness. I have written most of it except that I need to adopt a function what will generate random stiffness values. I really have no idea how to put it into my program. I have tseted it with a simple multipication program but it doesn't compile pleae give me some advice thanks. CPP / C++ / C Code:
Last edited by admin : 02-May-2007 at 23:27.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#2
|
||||
|
||||
Re: Adopt a function that generate random values to a programYou've been asked to use code tags at least 5 times, and read the Guidelines at least twice. Do you have a problem following suggestions? If so, programming is not a good area for you...
__________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#3
|
|||
|
|||
Re: Adopt a function that generate random values to a programQuote:
Here's what I think I see: 1. You are given a function double RandInvNormal(double mean, double stdev). 2. You call the function with values of mean and stdev, and the function returns a number that somehow represents a sample from a random process with the specified statistical properties. 3. The function calls the library function rand() and returns a value. 4. You want to write a main() function that calls the function in such a way as to test it. You are also given a way to "seed" the library function rand() according to system time. A simple test for starters might be to generate a sequence of numbers and test the mean and the standard deviation of the sample set. That is not necessarily adequate, since it wouldn't actually tell you anything about how closely the distribution of the numbers would match a set of numbers that came from a "real" random process with the specified statistical properties, but it's a start. Here's the skeleton of the program: 1. Define values of mean and standard deviation of the desired samples. 2. Seed the library function rand() 3. Make a loop that calls RndInvNormal() a lot of times and accumulates the returned values in such a way that you can calculate the sample mean and sample standard deviation of the sequence of numbers returned by the function. For starters, maybe you just want to call the function 20 times and print out the results. Look at the numbers that it gives you and decide whether they are a reasonable set of sample values. Run the program several times and see if the numbers look "OK". Here's the skeleton of the program: Here is a program that calls the function one time and prints out the result: CPP / C++ / C Code:
Now, the value of the seed for rand() comes from system time, which changes once per second, so if you run this program several times at least a second apart, you will get numbers from the function. Better yet, make a loop that has only the function call statement and print statement, so that a single program run will give you as many values as you want. I gave it a mean of 1.0 and a standard deviation of 1.0. You give it whatever you want. Values from a few runs: Code:
If you get a set of numbers that "seem to be OK", then maybe you will want to make more sophisticated tests of the "randomness" properties (or, maybe, not). Regards, Dave |
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| floating point decimal to ascii conversion | crazypal | C Programming Language | 5 | 18-Apr-2007 04:59 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| Nested for loop with function | Tori | CPP / C++ Forum | 11 | 08-Nov-2004 13:02 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The