import java.awt.*; import java.applet.*; //copyright 2000 M Paez, U Antioquia, R landau, OSU public class Strsin extends Applet implements Runnable { Thread runstring; private Image offScreenImage; double mxx,bxx,myy,byy; int jj; double xi[][],xiw[],ro,ten,vel2,vel; public void start() { if(runstring==null); { runstring=new Thread(this); runstring.start(); } } public void stop() { if(runstring != null){ runstring.stop(); runstring=null; } } public void run() { while(true){ repaint(); try{ Thread.sleep(300); } catch(InterruptedException e){ } } } public void update(Graphics g) { //To avoid flicker Graphics offScreenGraphics=offScreenImage.getGraphics(); offScreenGraphics.setColor(getBackground()); offScreenGraphics.fillRect(0,0,size().width,size().height); offScreenGraphics.setColor(g.getColor()); paint(offScreenGraphics); g.drawImage(offScreenImage,0,0,this); } void coormundo(double xiz,double ysu,double xde,double yinf) { double maxx,maxy,xxfin,xxcom,yyin,yysu; maxx=400; maxy=250; xxcom=0.15*maxx; xxfin=0.75*maxx; yyin=0.8*maxy; yysu=0.2*maxy; mxx=(xxfin-xxcom)/(xde-xiz); bxx=0.5*(xxcom+xxfin-mxx*(xiz+xde)); myy=(yyin-yysu)/(yinf-ysu); byy=0.5*(yysu+yyin-myy*(yinf+ysu)); } void ejes(double xmz,double yms,double xmd,double ymi,Graphics g) { //Grafica los ejes // La entrada esta en coordenadas 0.0 a 1.0 int i,mp,xpi,xpd,yps,ypi,xdiv,ydiv,ypcen; double yincr,xincr,yte; //char nhorz[3],nver[15]; char nver; int sig=4; ydiv=1; xpi=(int)(mxx*xmz+bxx); xpd=(int)(mxx*xmd+bxx); yps=(int)(myy*yms+byy); ypi=(int)(myy*ymi+byy); ypcen=(int)byy; g.drawLine(xpi,ypcen,xpd,ypcen); } public void init() { double xx,pi; int i; xi=new double[101][3]; xiw=new double[101]; ro=0.010; setBackground(Color.black); ten=40; jj=1; offScreenImage=createImage(size().width,size().height); vel2=ten/ro; vel=Math.sqrt(vel2); } public void Strplot(Graphics g, int jj) { // solves the string partial differential equation double Cons,ten,ro,dx,xx,pi; double dt,vel2; int peo,peyo,pex,peye; int k,m,icoun,il,ip,lam,ll,i,nmax; Cons=1.0; //initial condition an eigenfunction sin(2pi x/L) pi=3.14159265358979323846; for(i=0;i<101;i++){ xx=i/100.0; xi[i][0]=0.001*Math.sin(2.0*pi*xx); xiw[i]=1000.00*xi[i][0]; } if(jj==1){ dx=1.00/100.00; dt= dx/vel; nmax=100; coormundo(0.0,2.0,100.0,-2.0); } g.setColor(Color.yellow); //the time steps begin here. This is second time step ejes(0.0,2.0,100.0,-2.0,g); for(i=1;i<100;i++){ xi[i][1]=xi[i][0]+0.5*(xi[i+1][0]+xi[i-1][0]-2.0*xi[i][0]); } icoun=0; //third time step and following time steps for(k=1;k0) xiw[m]=1000.0*xi[m][2]; } // only at every 5 time steps we want data // ip=k%5; if(k==jj) { for(i=0; i<101; i++) { if(i>0){ peo=(int)(mxx*(i-1)+bxx); peyo=(int)(myy*xiw[i-1]+byy); pex=(int)(mxx*i+bxx); peye=(int)(myy*xiw[i]+byy); g.drawLine(peo,peyo,pex,peye); } } //for i } } }//rutine public void paint(Graphics g) { Strplot(g,jj); jj=jj+10; } }//class