import java.awt.*; import java.awt.event.*; import java.util.Random; import java.lang.Math; public class Sprott extends java.applet.Applet implements MouseMotionListener, ActionListener { //************************************************************** // Iterations of calculation int iterate=6000; // Time step double h=0.2; // Single Parameter of system double param=0.6; // Zoom on graph double zoom=40.0; // Initial Position double x0=0.0, y0=0.0, z0=0.0; // Three dimensional diff. eq. : dx/dt=fx, dy/dt=fy, dz/dt=fz public double fx(double x, double y, double z){ return y; } public double fy(double x, double y, double z){ return z; } public double fz(double x, double y, double z){ return -(param*z)-y+absl(x)-1; } //************************************************************** TextField Zoom; int num=(iterate+1), X, Y, xa, xb, xc, ya, yb, yc; int angle, Width, Height, choice; double theta=0.0, phi=3.1415926/12, z=z0, x=x0, y=y0; double data[][]=new double[4][num]; double x2=x+1e-8, y2=y, z2=z, t=0.0; double d1, df, rs, lsum=0.0, l1=0.0; public void paint(Graphics g){ g.clearRect(0, 0, Width, Height); g.setColor(Color.black); Xform4(100, 0, 0); int A=xc+X, B=yc-Y; g.drawLine(xc, yc, A, B); Xform4(90, 5, 0); g.drawLine(A, B, xc+X, yc-Y); Xform4(90, -5, 0); g.drawLine(A, B, xc+X, yc-Y); Xform4(0, 100, 0); A=xc+X; B=yc-Y; g.drawLine(xc, yc, A, B); Xform4(5, 90, 0); g.drawLine(A, B, xc+X, yc-Y); Xform4(-5, 90, 0); g.drawLine(A, B, xc+X, yc-Y); Xform4(0, 0, 100); A=xc+X; B=yc-Y; g.drawLine(xc, yc, A, B); Xform4(5, 0, 90); g.drawLine(A, B, xc+X, yc-Y); Xform4(-5, 0, 90); g.drawLine(A, B, xc+X, yc-Y); //draw graph g.setColor(Color.blue); for (int n=1; n<(num-2); n+=1){ Xform4(zoom*data[0][n], zoom*data[1][n], zoom*data[2][n]); xa=X; ya=Y; Xform4(zoom*data[0][n+1], zoom*data[1][n+1], zoom*data[2][n+1]); xb=X; yb=Y; g.drawLine(xc+xa, yc-ya, xc+xb, yc-yb); } } public void init(){ Label ZOOM=new Label("Parameter A :"); add(ZOOM); Zoom=new TextField(String.valueOf(param), 3); add(Zoom); Zoom.addActionListener(this); Width=size().width; Height=size().height; xc=(Width/2); yc=(Height/2); addMouseMotionListener(this); setdata(); } public void setdata(){ for (int k=1; (k<(num-1)); k++){ data[0][k]=0; data[1][k]=0; data[2][k]=0; } x=x0; y=y0; z=z0; x2=x+1-8; y2=y; z2=z; t=0.0; lsum=0.0; l1=0.0; for (int k=1; (k<(num-1)); k++){ data[0][k]=x; data[1][k]=y; data[2][k]=z; rk4(); d1=((x2-x)*(x2-x))+((y2-y)*(y2-y))+((z2-z)*(z2-z)); if (d1>0){ df=d1*1e16; rs=1.0/Math.sqrt(df); x2=x+rs*(x2-x); y2=y+rs*(y2-y); z2=z+rs*(z2-z); if (k>1000){ lsum=lsum+Math.log(df); l1=0.5*lsum/k/h; } } t+=h; if ((absl(y)+absl(x)+absl(z))>500){ break; } } // if (((absl(y)+absl(x)+absl(z))<500)&&(l1>0.001)){ // cout << "Highest LE : " << l1 << endl; // } } public void rk4(){ //Runge-Kutta Method //provided by Prof. J. C. Sprott double k1x, k2x, k3x, k4x, k1y, k2y, k3y, k4y, k1z, k2z, k3z, k4z; k1x=h*fx(x, y, z); k1y=h*fy(x, y, z); k1z=h*fz(x, y, z); k2x=h*fx(x+(0.5*k1x), y+(0.5*k1y), z+(0.5*k1z)); k2y=h*fy(x+(0.5*k1x), y+(0.5*k1y), z+(0.5*k1z)); k2z=h*fz(x+(0.5*k1x), y+(0.5*k1y), z+(0.5*k1z)); k3x=h*fx(x+(0.5*k2x), y+(0.5*k2y), z+(0.5*k2z)); k3y=h*fy(x+(0.5*k2x), y+(0.5*k2y), z+(0.5*k2z)); k3z=h*fz(x+(0.5*k2x), y+(0.5*k2y), z+(0.5*k2z)); k4x=h*fx(x+k3x, y+k3y, z+k3z); k4y=h*fy(x+k3x, y+k3y, z+k3z); k4z=h*fz(x+k3x, y+k3y, z+k3z); x+=(k1x+(2.0*(k2x+k3x))+k4x)/6.0; y+=(k1y+(2.0*(k2y+k3y))+k4y)/6.0; z+=(k1z+(2.0*(k2z+k3z))+k4z)/6.0; k1x=h*fx(x2, y2, z2); k1y=h*fy(x2, y2, z2); k1z=h*fz(x2, y2, z2); k2x=h*fx(x2+(0.5*k1x), y2+(0.5*k1y), z2+(0.5*k1z)); k2y=h*fy(x2+(0.5*k1x), y2+(0.5*k1y), z2+(0.5*k1z)); k2z=h*fz(x2+(0.5*k1x), y2+(0.5*k1y), z2+(0.5*k1z)); k3x=h*fx(x2+(0.5*k2x), y2+(0.5*k2y), z2+(0.5*k2z)); k3y=h*fy(x2+(0.5*k2x), y2+(0.5*k2y), z2+(0.5*k2z)); k3z=h*fz(x2+(0.5*k2x), y2+(0.5*k2y), z2+(0.5*k2z)); k4x=h*fx(x2+k3x, y2+k3y, z2+k3z); k4y=h*fy(x2+k3x, y2+k3y, z2+k3z); k4z=h*fz(x2+k3x, y2+k3y, z2+k3z); x2+=(k1x+(2.0*(k2x+k3x))+k4x)/6.0; y2+=(k1y+(2.0*(k2y+k3y))+k4y)/6.0; z2+=(k1z+(2.0*(k2z+k3z))+k4z)/6.0; return; } public double absl(double a){ if (a>0.0){ return a; } else { return -a; } } public void Xform4(double x, double y, double z){ X = (int)(((x*(Math.cos(theta))) + (y*(Math.sin(theta))))); Y = (int)(((((x*(Math.sin(theta))) + (-y*(Math.cos(theta))))*(Math.sin(phi))) + (z*(Math.cos(phi))))); } public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){ int a=(xc-(e.getX())); int b=(yc-(e.getY())); theta=-(3.1415926/2)-((double)a/(double)yc)*(3.1415926/2); phi=(3.1415926/2)-((double)b/(double)yc)*(3.1415926/2); repaint(); } public void actionPerformed(ActionEvent e){ param=Double.valueOf(Zoom.getText()).doubleValue(); setdata(); repaint(); } }