Science and Computers I -- PHY307/607

Lab 4. - Simple Java Animation and Plotting Iterates of the Logistic Map

In the first part of this lab you will learn how to animate your HelloWorldApplet. You will then use another Java applet - the PlotIterateApplet to plot iterates of the logistic map and look for n-cycles.

Animating your HelloWorldApplet

  1. Download the Java code Hwa4.java from the Labs section of the PHY307 homepage. Save it to the directory public_html/PHY307 of your SUnix account. We will modify this code so that the applet when loaded will show a simple animation based on the words Hello World! which will be under control of a button.
  2. Using pico edit the code Hwa4.java. After the line private Font newfont; add the line
    
    private Thread runner;
  3. After the final closing curly brace of the init() method add the following code which will constitute a new method start() which starts the animation
    
    public void start(){
    runner = new Thread(this);
    runner.start();
    }
    
  4. Immediately after this add the following code to define a new method for stopping the animation when you move off the Web page.
    
    public void stop(){
    if(runner!=null)
    runner.stop();
    }
    
  5. Finally locate the template for another new method run() located near the bottom of the code. Type the following code into the main body of this method.
    
    while(true){
    
    ycoord=ycoord+inc;
    if((ycoord==15) || (ycoord==-15))
    inc=-inc;
    
    try{Thread.sleep(10);}
    catch(InterruptedException e){}
    repaint();
    }
    
    
  6. Exit the editor and compile the code with javac. If successful you will have a file Hwa4.class in the same directory. Change the permissions as usual with the command chmod 644 Hwa4.class.
  7. Finally, create a file Hwa4.html (perhaps by copying your Hwa3.html file) to launch the new applet Hwa4.class. Make sure this new file has the correct permissions.
  8. Launch Netscape and check it out!

Plotting iterates of the logistic map

  1. Go to the Labs section of the PHY307 homepage. Load the applet PlotIterate Applet. This is a simple applet that allows you to draw graphs of iterates of the logistic map. Thus a graph of the second iterate of the map would be graph of f2=f(f(x)) while f4=f(f(f(f(x)))) would be the fourth iterate etc. You define which iterate you want to plot by typing an integer into the box marked n (Remember to hit return to register any changes to the text boxes). You will see that the applet plots all the curves (in different colours) for the preceeding iterates also. Thus if you type in n=2 you will see a green curve corresponding to n=2 plus a red curve corresponding to n=1. The value of the parameter a can be typed into the other box. Hitting Plot draws the curve(s). Notice that the black line corresponds to y=x. As we discussed in class intersections of the line with the nth-iterate curve will give the possible values of x in an n-cycle.
  2. Set the parameter a=2.5. Put n=1. Sketch the (red) curve you see. This is a curve of the logistic map itself. Estimate the x-coordinate of the point of intersection of the two curves (there are two intersections - the other one is at x=0)
  3. Now load up the original applet Mapping Applet (you may want to fire up a new Netscape window so you can display both of these applets at once). Type your estimate from the previous question into the x= box (and set the value of a=2.5 also !). Iterate from this value - does the value remain (approximately) the same after a number of iterations. This would be a stable solution to the equation for fixed points x=f(x).
  4. If I start with a value near the other intersection x=0 - say x=0.1 what happens after many iterations of the Mapping Applet. Thus x=0 is said to be an unstable solution of the equation and is not seen under repeated iteration.
  5. Now put n=2 and hit Plot again. Sketch the green curve you see. How many intersections are there between this curve and the line ? You should see that no new intersections are generated at n=2 which were not already present at n=1 for this value of a.
  6. Finally set n=4. Sketch the new n=4 (blue) curve you see. How many intersections are there ? Are they distinct from the intersection for n=1 or n=2 ? This analysis should convince you that for this value of a the simple fixed point solution is the unique, stable solution.
  7. Now set a=3.3. Again put n=1. What is the approximate x-value of the intersection point ?
  8. Go to the Mapping Applet and use this value (and a=3.3) as a starting point for the iteration. Is it still (approximately) preserved under iteration ? You should see that it has now become unstable.
  9. Put n=2 and redraw. How many intersections for the green curve - the n=2 curve are there now ? You should see that one of them corresponds to the value from n=1 but the others are different. Try the others in the Mapping Applet - are they stable as a 2-cycle ?
  10. Put n=4. Are there any new intersections other than you have seen from the 2nd iterate graph ? Clearly any 2-cycle will automatically be a possible 4-cycle.
  11. Finally put a=3.55 and n=2. How many intersections are there ? By plugging approximate values into the Mapping Applet can you say whether they still constitute a stable 2-cycle ?
  12. Put n=4 and repeat. How many intersections are there now ? You should see that 3 of these are common to the n=2 and n=1 curves. They are unstable. The 4-cycle corresponds to the new other points of intersection. Our general conclusion must be that to determine which n-cycle is stable we must look for the value of n after which no new intersections are generated for the larger n iterates. Thus we are looking for the minimal value of n which yields the maximal number of intersections. There will always be exactly n of these which are not in common with the smaller n curves! Phew ...

To get credit for this lab you need to
  1. Email me with the url to your Web page so that I can take a look at your working Hwa4 applet.
  2. Answer the questions posed in the lab -- hand in your answers on paper.
The deadline to get these things to me is next Thursday.

Back to the PHY307 Homepage

This page maintained by Simon Catterall, last updated 20 September, 2000.