Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a FORTRAN program to generate a sequence of points obtained by reading val

ID: 3630943 • Letter: W

Question

Write a FORTRAN program to generate a sequence of points obtained by reading values for n and r and playing the chaos game with those values.

For more information on the chaos game, please refer to this site:
http://mathworld.wolfram.com/ChaosGame.html

The program does not have to produce any graphical output. It must simply generate a list of several thousand coordinates of the C point in comma-separated form. The first 15 points should not be printed in the file. The output should look like this:

x1,y1
x2,y2,
x3,y3
....

Hint: Fortran has a random number generating function named RAND(x). If x is a non-zero value, it generates an initial number. Subsequently (inside a loop), every call to RAND(0) generates a new random number in the sequence.

The numbers generated are real numbers between 0 (inclusive) and 1 (exclusive). That is a number in the interval [0,1). To get an integer between 1 and n, we can compute the integral part of RAND(0)*n+1

Explanation / Answer

Perhaps you should be a bit more specific about what your actual question is, 'please help' is a bit general in scope.

That said, if what you need are a bunch of random numbers following your criterion, something like this could be used:

('seed' could be any value, like the program could ask the user to enter a number, their age, or whatever, but to assure best randomness from run to run; one could use an internal function call that returns the computer clock time in millisecond; this will ensure that subsequent run of the program are differently seeded. As for 'svrlth' -- SeVeRaL THousand -- that would be the initial parameter you need, augmented by the 15 values you want to disregard)

init=RAND(seed)
x=0.
y=0.

DO i=1,svrlth
vertex=IFIX(RAND(0)*FLOAT(n+1))
x=x+r*(vertx(vertex)-x)
y=y+r*(verty(vertex)-y)
IF(i > 15) WRITE(chnl,5000) x,y
5000 FORMAT(F10.8,',',F10.8)
ENDDO


What is also needed, and not presented here, is the initial generation of the 'vertx' and 'verty' arrays, which contain the x and y coordinates of the 'n' vertex, and would have to be populated.
The call to the random number generator selects the vertex, and the value of x and y are updated from the previous iteration, using the 'r' value that would have to be initialized.
The IF statement prevents output of the first 15 cases.




Edit: you populate the initial 'vertx' and 'verty' array by putting the x and y coordinates of vertex. For N=4, that would be x=0, y=0 for the first, x=1, y=0 for the second, x=1, y=1 for the 3rd, and x=0, y=1 for the 4th.
You just need to make a generic loading case that calculates the location of the vertex for any reasonnable value of 'N'. What are the limits, by the way? Should your program cater for N=78 of something as absurdedly large as that?
As for the random number generator, the point is that a computer is not random, Ever. The pseudo-random function is one that will always give you the same sequence if it starts from the same seed. The internal calculation takes the result of the last call to RAND, and uses it to computer the next value; but the equation make it seem very unrelated (cahotic) from the previous, so it jumps seemingly randomly between 0 and 1. If you do not specify a seed, you start a sequence as if the seed was 0. If you specify a seed, the only way to get the same sequence is to use the same seed all the time. With a seed, which is an integer, there are theoretically 2^32 different values that could initiate the sequence; this means 4.3 billion different sequences, and little chance that two would be the same one after the other.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote