/* * Started May 17, 1996 */ import java.applet.*; import java.net.*; import java.io.*; import java.awt.*; import java.util.*; import java.lang.*; class Matrix { int m,n; // rows and columns double[][] A; public Matrix() { this.m = 0; this.n = 0; } public Matrix(int row, int col) { int i,j; this.m = row; this.n = col; this.A = new double[m][n]; for (i=0; i= M.m() || j >= M.n()) { System.err.println("minor out of range"); System.exit(1); } else { int k,l; this.m = M.m() - 1; this.n = M.n() - 1; this.A = new double[this.m][this.n]; for (k=0; k=j)) { this.A[k][l] = M.A(k,l+1); } else if((k>=i) && (l=i) && (l>=j)) { this.A[k][l] = M.A(k+1,l+1); } } } } public int m() {return this.m;} public int n() {return this.n;} public double A(int i,int j) { return this.A[i][j]; } public void setA(int i,int j,double val) {this.A[i][j] = val;} public Matrix transpose() { int i,j; Matrix res = new Matrix(this.n,this.m); for (i=0; i 1) { double tmp = 0; for (i=0; i mu.A(i,0)) ReMin = mu.A(i,0); if (ReMax < mu.A(i,0)) ReMax = mu.A(i,0); for (j=0; j 9 || ((int)number.charAt(digit)-ZERO) < 0){ System.err.println("integer number reading error: "+number); System.exit(1); } else{ result = result*10 + (int)number.charAt(digit) - ZERO; } digit ++; } if (negative) result *= -1; return result; } // convert a string into a double double getDouble(String number) { double result = 0; int length = number.length(); int digit = 0; int decimalDigit = 0; boolean before = true; boolean negative = false; if (number.charAt(digit) == NEGATIVE_SIGN){ negative = true; digit ++; } while (digit < length){ if (number.charAt(digit) == DECIMAL_POINT){ decimalDigit = 0; before = false; } else if (((int)number.charAt(digit)-ZERO) > 9 || ((int)number.charAt(digit)-ZERO) < 0){ System.err.println("real number reading error "+number+" "+number.charAt(digit)); System.exit(1); } else if (before){ result = result*10 + (double)number.charAt(digit) - (double)ZERO; } else{ decimalDigit ++; int ddIndex = 0; double dd = (double)number.charAt(digit)-(double)ZERO; for (ddIndex=0; ddIndex 0) c.insets = new Insets(top, left, bottom, right); ((GridBagLayout)container.getLayout()).setConstraints(component, c); container.add(component); } public void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height) { constrain(container, component, grid_x, grid_y, grid_width, grid_height, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, 0, 0, 0, 0); } public void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int top, int left, int bottom, int right) { constrain(container, component, grid_x, grid_y, grid_width, grid_height, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, top, left, bottom, right); } public void paintCoord(Graphics g) { String xLable = "sigma"; String yLable = "E[r_e]"; int xTicks = 5; int yTicks = 5; if (xTicks<2 || yTicks<2){ System.err.println("xTicks or yTicks has to be at least 2"); System.exit(1); } double xMin = 0; double xMax = (int)(SigmaMax/(xTicks-1)+1)*(xTicks-1); double yMin = (int)(ReMin/(yTicks-1)-1)*(yTicks-1); double yMax = (int)(ReMax/(yTicks-1)+1)*(yTicks-1); int i = 0; // draw coordinate axes g.drawLine(left,bottom,right,bottom); // x axis g.drawLine(left,bottom,left,top); // y axis // dra2w coordinate lables g.drawString(xLable,(int)(right+right_margin*0.5),bottom); g.drawString(yLable,left,(int)(top-top_margin*0.5)); // draw coordinate ticks for (i=0; i mu_p.A(i,0)) r_e_min = mu_p.A(i,0); if (r_e_max < mu_p.A(i,0)) r_e_max = mu_p.A(i,0); } // System.out.println("re_min: "+r_e_min+" re_max: "+r_e_max); for (i=0; i<=numPoints; i++){ r_e[i] = r_e_min + (r_e_max-r_e_min)*i/((double)numPoints); double lambda_1 = (r_e[i]*d-b)/(a*d-b*c); double lambda_2 = (a-r_e[i]*c)/(a*d-b*c); Matrix w_p = V_p_inv.times(mu_p).times(lambda_1).plus (V_p_inv.times(one).times(lambda_2)); sigma[i] = w_p.transpose().times(V_p.times(w_p)).A(0,0); sigma[i] = Math.sqrt(sigma[i]); /* rescaling, convert to annually percent */ r_e[i] *= 1200; sigma[i] *= (Math.sqrt(12)*100); // System.out.println(r_e[i]+"\t"+sigma[i]+"\t"); } double sigma_min = sigma[0]; double sigma_max = sigma[0]; for (i=1; i<=numPoints; i++){ if (sigma_min > sigma[i]) sigma_min = sigma[i]; if (sigma_max < sigma[i]) sigma_max = sigma[i]; } /* scailing and flipping up-side-down */ int[] x = new int[numPoints+1]; int[] y = new int[numPoints+1]; for (i=0; i<=numPoints; i++){ x[i] = (int)(left+(right-left)*(sigma[i]-SigmaMin)/(SigmaMax-SigmaMin)); y[i] = (int)(bottom-(bottom-top)*(r_e[i]-ReMin)/(ReMax-ReMin)); } this.paintCoord(g); for (i=0; i