Science and Computers -- PHY307/607

Lab 10. - Complex numbers and Julia Sets

Modifying Simple.java to do maps of complex numbers

  1. First, login to SUnix and change to the directory public_html/PHY307. Create a new directory called Complex and modify its permissions with the chmod command so as to make it viewable through Netscape.
  2. Copy the .java files in the old directory Simple to this new directory (cp Simple/*.java Complex).
  3. Change to the Complex directory and rename the file Simple.java to Complex.java (type mv Simple.java Complex.java).
  4. We will change the Map object to handle maps of complex numbers. Use pico to start editing the file Map.java. Change the line
    private double x;
    to
    private double x,y;
    Similarly change the line private double a; to private double a,b;. The real part of our complex number z will be called x and its imaginary part is y. Similarly, the parameter a is replaced by a complex number a+ib.
  5. We need to modify the iterate() method to calculate complex number multiples and adds. Replace the contents of the existing iterate()method (the stuff between the beginning and ending curly braces) with the code
    
    double xnew,ynew;
    xnew=x*x-y*y+a;
    ynew=2*y*x+b;
    x=xnew;
    y=ynew;
    return;
  6. We also need to modify the method setA() to set both the real and imaginary parts of the complex parameter a+ib. Replace the entire method with a new one whose definition looks like
     
    public void setA(double c, double d){
    a=c;
    b=d;
    return;
    }
    
  7. Similarly, delete the old method setX() and replace it with
    
    public void setX(double c, double d){
    x=c;
    y=d;
    return;
    }
    
  8. Finally, we need to add one new method to return the value of the imaginary part of the number. Add a new method getY() which looks almost exactly like the method getX() but returns the value of the imaginary part y. Exit and save the new file Map.java.
  9. Back at the SUnix prompt, fire up pico again to edit the file Complex.java. Change the name of the class from Simple to Complex in line 2.
  10. Replace the line mymap.setA(2.5) with the new one mymap.setA(-0.5,0.5).
  11. Similarly, replace the call mymap.setX(0.3) with the new call mymap.setX(0.0,0.0). What is the initial value of the complex number z=x+iy ?
  12. Finally, in paint() after the line g.drawString("x is "+mymap.getX(),100,125); add a line to print the imaginary part y
     
    g.drawString("y is "+mymap.getY(),125,135);
    Also, change the number 100 to 125 in the command for drawing the x value.
  13. In the method action() make sure that after the line containing the method call mymap.iterate() you have a call to the method repaint();. Exit pico saving your changes.
  14. Finally, create a file called Complex.html and inside it place the line
    
    < applet code=Complex.class width=300 height=300 > < /applet >
    
    .
  15. Compile the files and change file and directory permissions as per usual.
  16. Point Netscape at this new applet. Hit the iterate button. What are the real and imaginary parts of the complex number after one iteration ?
  17. Hit the Iterate button several times. Do you think the complex number -1/2+1/2i is in the Mandelbrot set ? (hint: remember that the Mandelbrot set comprises all values of the parameter c in the map z_(n+1)=-z_n^2+c for which the iteration remains bounded.

The Julia set applet

  1. Link to the applet Julia Applet. The complex parameter c has a real part called a and an imaginary part called b. Set a to 0 and b to 0. Sketch (the black part of) the Julia set you see.
  2. Now set a=0 and b=1.0. Sketch this Julia set too. Now drag the mouse to magnify a region around coordinates (-0.5,0.5). Hit Draw Fractal after selecting the region to recompute the points in the magnified region. You may want to magnify this region once or twice more. Are there are any regions of black points inside the blue ? Sketch the magnified region.
  3. Set a=0.5 and b=0.25. Again use the magnification feature of the applet to see whether there are any regions in which the points do not iterate to infinity. Make a sketch of your magnified region.
  4. The Julia sets I showed in class are defined by a=-0.75, b=0 and a=-0.85, b=0.18. Experiment zooming in on features and redrawing them You should see that the boundary of the black region is truly a fractal object.

To get credit for this lab you need to
  1. Hand in written answers to the questions posed in the lab.
The deadline to get these things in is next Thursday.

Back to the PHY307 Homepage

This page maintained by Simon Catterall, last updated 2 November, 2000.