⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dirichletdemo.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
字号:
/* WARANTY NOTICE AND COPYRIGHTThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.Copyright (C) Michael J. Meyermatmjm@mindspring.comspyqqqdia@yahoo.com*//* * DirichletDemo.java * * Created on January 18, 2002, 5PM */ package Examples.Probability;import Statistics.*;import Processes.*;import java.lang.Math.*;import Graphics.Frame;import java.awt.event.*; /** <p>A two dimensional Brownian motion is started at the origin and the path  *  displayed until it hits the boundary of the unit circle.</p>  * * @author  Michael J. Meyer */public class DirichletDemo extends Graphics.Frame{                  // wait       public void sleep(long millis)       {             long current=System.currentTimeMillis();          while(System.currentTimeMillis()<current+millis){}                  } //end sleep                  // constructor       public DirichletDemo()       {           setDefaultCloseOperation(EXIT_ON_CLOSE);                      // repaint on mouseclick           addMouseListener(new MouseAdapter(){	                                 	     public void mouseClicked(java.awt.event.MouseEvent event) 	     {  paint(getGraphics());  }                       }); // end mouseListener                      // enable events           setEnabled(true);           requestFocus();           setBounds(150,50,800,500);           setTitle("Two dimensional Brownian motion, "+                    "click to restart, close to kill");                  } // end constructor              public void paint(final java.awt.Graphics g)       {                          int T=50000,      //time steps to horizon           dim=2;        //dimension           double dt=0.001;  //size of time step                   double[] x={0,0};  //starting point                           //allocate a two dimensional Brownian motion starting at x           final VectorBrownianMotion B=new VectorBrownianMotion(dim,T,dt,x);                           //define the unit disc as a two dimensional region           Region_nD disc=new Region_nD(){                        public boolean isMember(double[] z)                {                     double u=z[0], v=z[1];                     return (u*u+v*v<1);       }                             }; //end disc                           //allocate the hitting time for the boundary           final StoppingTime tau=new FirstExitTime_nD(B,disc);                    // clear the window           g.setColor(java.awt.Color.white);           g.fillRect(0,0,800,800); // clear drawing           g.setColor(java.awt.Color.red);                      // circle inscribed square of side 400,            // upper left corner at (200,50)           g.drawOval(200,50,400,400);            int n=B.pathSegment(tau);                          double[][] z=B.get_path();                      double f=200.0;    //scaling, radius of disc=200 pixels           int u1,u2,v1,v2;           u1=400+(int)(f*x[0]);           u2=250-(int)(f*x[1]);           g.drawOval(u1,u2,2,2);     // the starting point                          for(int t=0;t<n;t++)           {               v1=400+(int)(f*z[t+1][0]);               v2=250-(int)(f*z[t+1][1]);               // pause 1 nanosecond               sleep(20);               g.drawLine(u1,u2,v1,v2);               u1=v1;               u2=v2;           }                                sleep(500);                            }// end paint       /******************************************************************************* * *                                 MAIN * ******************************************************************************/                public static void main(String[] args)       throws java.io.FileNotFoundException, java.io.IOException       {            DirichletDemo window=new DirichletDemo();           window.setVisible(true);           String filename="Pictures/Graphs/BMinCircle.eps";                     window.saveAsEPS(filename);              }              } // end DirichletDemo                                                             

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -