A simple example of coding and simulating a little problem in Java

| コメント(0) | トラックバック(0)

Here we can visually understand the convergence of Cauchy sequence by entering the value of x and N. Definition: The function f(x,N,i) of two positive integers x, i and a rational number N is defined by
          f\left(x,N,i\right)=\frac{\left[N\exp\left(0.01i-10\right){}r\left(x\right)\right]}{N\exp\left(0.01i-10\right)}.

The function g(N,i) of a positive integer i and a rational number N is defined by
          g\left(N,i\right)=\log\left\{N\exp\left(0.01i-10\right)\right\}.

[•] is Gauss' symbol and r(x) is a positive square root of x. The vertical axis shows a sequence of values on the function of (x,N,i). The horizontal axis shows a sequence of values on the function of (N,i). The function of (x,N,i) has a minimum value in the assigned (i=1) condition and a maximum value in the assigned (i=1000) condition when the domain of i is between 1 and 1000.

The domain of x is over 0 and below 10^8, and the domain of N is over 0.1^16 and below 10^16. When you enter the numerical values of x and N, please push the enter key each time you enter x or N in the text box.

If you enter the value of x and N in other domains, the program automatically sets the variables such as x=10^5 and N=10^5.

          source code: CauchySequence.java

import java.math.BigDecimal;
import java.math.BigInteger;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class CauchySequence extends Applet implements ActionListener{

private static final long serialVersionUID = -6724959421340457497L;
JTextField yx = new JTextField("100000");
JTextField yn = new JTextField("100000");
JLabel label1 = new JLabel("Convergence of Cauchy sequence", JLabel.CENTER);
JLabel label2 = new JLabel("A natural number, 0<x<10^8", JLabel.CENTER);
JLabel label3 = new JLabel("A rational number, 0.1^16<N<10^16", JLabel.CENTER);

// variable set
double x = 100000;
double n = 100000;

public void init(){
label1.setPreferredSize(new Dimension(416,24));
label1.setFont(new Font("Serif",Font.BOLD,14));
add(label1);
label2.setPreferredSize(new Dimension(170,23));
label2.setFont(new Font("Serif",Font.BOLD,11));
add(label2);
yx.setPreferredSize(new Dimension(80,23));
add(yx);
label3.setPreferredSize(new Dimension(210,23));
label3.setFont(new Font("Serif",Font.BOLD,11));
add(label3);
yn.setPreferredSize(new Dimension(120,23));
add(yn);
yx.addActionListener(this);
yn.addActionListener(this);
}

public void actionPerformed(ActionEvent e){
if(e.getSource()==yx){
x=Double.valueOf(yx.getText()).doubleValue();
if(x <= 0 || x >= Math.pow(10.0,8) || x!=(long)x){
x=100000;
}
}
if(e.getSource()==yn){
n = Double.valueOf(yn.getText()).doubleValue();
BigDecimal n0 = new BigDecimal(yn.getText());
BigDecimal n1 = new BigDecimal(Math.pow(0.1,16));
BigDecimal n2 = new BigDecimal(Math.pow(10.0,16));
int d1 = n0.compareTo(n1);
int d2 = n0.compareTo(n2);
if(d1==-1 || d1==0 || d2==0 || d2==1){
n=100000;
}
}
yx.setText(""+(long)x);
yn.setText(""+n);
repaint();
}

public void paint(Graphics g){

// variable set
int i;
double b, m, p, y, minp, maxp, minb, maxb;
BigDecimal a0, a2, b0, n0, p0, p1, x0;
BigInteger a1;
double[] pp = new double[1000];
double[] bb = new double[1000];
int[] xxx = new int[1000];
int[] yyy = new int[1000];

for(i=1;i<=1000;i++){
p = Math.exp(10-0.01*i);
m = n/p;
p0 = new BigDecimal(p);
n0 = new BigDecimal(n);
p1 = n0.divide(p0,30,BigDecimal.ROUND_HALF_EVEN);
pp[i-1] = Math.log(m);
y = Math.sqrt(x);
x0 = new BigDecimal(y);
a0 = x0.multiply(p1);
a1 = a0.toBigInteger();
a2 = new BigDecimal(a1);
b0 = a2.divide(p1,30,BigDecimal.ROUND_HALF_EVEN);
b = b0.doubleValue();
bb[i-1] = b;
}

minp = pp[0];
maxp = pp[0];
minb = bb[0];
maxb = bb[0];

for(i=0;i<=999;i++){
if(pp[i]>maxp){
maxp = pp[i];
}
}

for(i=0;i<=999;i++){
if(pp[i]<minp){
minp = pp[i];
}
}

for(i=0;i<=999;i++){
if(bb[i]>maxb){
maxb = bb[i];
}
}

for(i=0;i<=999;i++){
if(bb[i]<minb){
minb = bb[i];
}
}

for (i=0;i<=999;i++){
double xx = maxp-minp;
double yy = maxb-minb;
xxx[i] = (int)((pp[i]-minp)*(351/xx))+33;
yyy[i] = 441-(int)((bb[i]-minb)*(351/yy));
}

Graphics2D g2 = (Graphics2D)g;
GradientPaint gp1 = new GradientPaint(0, 0, new Color(154,181,228), 0,470,new Color(225,232,245), true);
g2.setPaint(gp1);
g2.fillRect(0,0,416,470);
super.paint(g);
GradientPaint gp2 = new GradientPaint(0, 33, new Color(225,232,245), 0,351,new Color(154,181,228), true);
g2.setPaint(gp2);
g2.fillRect(33,90,354,351);
g2.setColor (Color.black);
g2.setFont(new Font ("Serif",Font.PLAIN,11));
g2.drawString("f",15,95);
g2.drawString("(x,N,i)",1,108);
g2.drawString("g(N,i)",365,455);
for (i=0;i<=998;i++){
g.drawLine(xxx[i], yyy[i], xxx[i+1], yyy[i+1]);
}
}
}

I have recently begun to code the examples of numerical computation in Java and hope to make better use of the computational power and the graphical user interface.

トラックバック(0)

トラックバックURL: http://www.suzuki-labor.com/mt/mt-tb.cgi/2336

コメントする

My Photo
プロフィール!
2016・11・15 改訂
spacer01
rssspacer01foaf
spacer01
atom.xml
spacer01

この記事について

このページは、Suzuki TakashiがAugust 19, 2007 7:20 PMに書いた記事です。

ひとつ前の記事は「ようやく、パート1。」です。

次の記事は「一息つくまで、パート1。」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

August 2023

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Recent Posts

月別 アーカイブ

Workbooks

  • Basic Word List
  • Basic Word List 3rd Edition
  • Samuel C. Brownstein (著), Mitchel Weiner (著), Sharon Weiner Green (著)
  • SAT、GRE用の語彙が2000語以上収録され、2009年4月に4th Editionが出版される。又、Synonym Testが750題、Comprehensive Testが75題付記されている。2005年8月に国内向けの訳本として『最強の英語ボキャブラリー1700語』が出版され、Synonym Testが500題、Comprehensive Testが50題付記されている。
  • 1100 Words You Need to Know
  • 1100 Words You Need to Know 4th Edition
  • Murray Bromberg (著), Melvin Gordon (著)
  • SAT用の語彙が920語、熟語が184語収録され、2008年6月に5th Editionが出版される。Review, 24題で1週分の知識の確認を、Analogy Review, 15~20題で10週分の確認を、Final Review Test, 150題で46週分の確認を行うことになる。1周しただけで定着する程簡単なものではなく、繰り返しが重要なことは他のボキャビル本と同様。音声教材として Wordplay: 550+ Words You Need to Know 2nd Edition が出されており、The Rambling Panthersから始まる7つのドラマに新出語句を散りばめている。
  • Kaplan Word Power
  • Kaplan Word Power 3rd Edition
  • Kaplan (著)
  • SAT、GRE用の語彙が750語収録され、Plug Inの10~15題で1課分の知識の確認を行うことになる。収録語彙の水準は類書よりやや高めで、Plug Inでの設問の尋ね方もやや高度なものになっている。具体的には Fill in the blanks. や Match the word closest to the word that means the opposite. といった形式に苦労した。又、音声教材として Kaplan Word Power (CD) があり、CD2枚の構成になっている。
  • Word Smart
  • Word Smart for the GRE, 2nd Edition
  • Princeton Review (著)
  • GRE用の語彙が678語収録され、Quick Quizは65課あり、6~15題で1課分の知識の確認を、Final Exam Drillの570題で57課分の確認を行うことになる。類書にSAT用のWord Smart、Word Smart Ⅱ等があり、それらを含めて繰り返し訓練するとなると、結構時間が掛かるのは当然だろう。又、音声教材としてSAT用だが The Princeton Review Word Smart CD があり、All or Nothingから始まる14のドラマに228語が散りばめられている。
spacer01

Banner


Bookmark

  • Valid XHTML 1.0 Transitionalspacer01
  • Valid CSS!spacer01
OpenID 対応しています OpenIDについて