- 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.
- Copy the .java files in the old directory Simple to
this new directory (cp Simple/*.java Complex).
- Change to the Complex directory and rename the file
Simple.java to Complex.java (type mv Simple.java Complex.java).
- 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.
- 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;
- 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;
}
- Similarly, delete the old method setX() and replace it with
public void setX(double c, double d){
x=c;
y=d;
return;
}
- 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.
- 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.
- Replace the line mymap.setA(2.5) with
the new one mymap.setA(-0.5,0.5).
- 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 ?
- 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.
- 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.
- Finally, create a file called Complex.html and inside
it place the line
< applet code=Complex.class width=300 height=300 > < /applet >
.
- Compile the files and change file and directory permissions as
per usual.
- Point Netscape at this new
applet. Hit the iterate button. What are the real and imaginary parts of the
complex number after one iteration ?
- 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.