Created
January 27, 2013 18:57
-
-
Save thisMagpie/4649773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class Hall{ | |
public static void main (String[] args) throws IOException { | |
if(args.length>0){ | |
BufferedReader xReader=new BufferedReader(new FileReader(IOUtil.fileName(args[0]))); | |
BufferedReader yReader=new BufferedReader(new FileReader(IOUtil.fileName(args[1]))); | |
PrintWriter xyWriter = new PrintWriter(new FileWriter(args[2])); | |
GNUPlot gnuPlot = new GNUPlot(); | |
PrintWriter residualWriter = new PrintWriter(new FileWriter(args[3])); | |
Scanner xScan = new Scanner(xReader); | |
Scanner yScan = new Scanner(yReader); | |
gnuPlot.printGradient(xScan,yScan); | |
double[] residual = gnuPlot.computeResidual(); | |
BufferedReader keyboard =new BufferedReader(new InputStreamReader(System.in)); | |
System.out.print(" Input the magnetic field in mT: "); | |
double field = IOUtil.skipToDouble(new Scanner(keyboard)); | |
System.out.print(" Input the magnetic field error in mT: "); | |
double fieldError = IOUtil.skipToDouble(new Scanner(keyboard)); | |
System.out.printf(" Gradient gnu %g", gnuPlot.getGradient()); | |
xyError(xyWriter, gnuPlot.getX(),gnuPlot.getY(),errorCurrent(gnuPlot.getX()),errorVoltage(gnuPlot.getY())); | |
xyWriter.close(); | |
xyError(residualWriter, gnuPlot.getX(), residual,errorCurrent(gnuPlot.getX()),errorVoltage(gnuPlot.getY())); | |
residualWriter.close(); | |
printNoDensity(gnuPlot.getGradient(),field,gnuPlot, fieldError); | |
} | |
} | |
private static void printNoDensity(double gradient, double field, GNUPlot gnu, double fieldError){ | |
double electron = 1.60217646 * Math.pow(10,-19); | |
double numberDensity = field / (gradient * electron); | |
System.out.printf("Number density for N-Type Germanium sample with gradient of %g = %g in a field of %g mT", gradient,numberDensity,field); | |
double errorNumberDensity= Math.sqrt(relativeError((20* Math.pow(10,-6)),Math.pow(10,-3))+relativeError(gnu.getGradientError(),gradient)+relativeError(fieldError,field)); | |
System.out.printf("Number density has a relative error of %g mT", errorNumberDensity); | |
} | |
public static void xyError(PrintWriter outFile, double[] x, double[] y, double[] xErr, double[] yErr ){ | |
for (int i=0;i<y.length;i++) { | |
outFile.printf("%g %g %g %g \n", x[i], y[i],xErr[i],yErr[i]); | |
System.out.printf("%g %g %g %g \n", x[i], y[i],xErr[i],yErr[i]); | |
} | |
} | |
public static double[] errorVoltage(double[] y){ | |
double[] error = new double[y.length]; | |
for (int i=1;i<y.length;i++) | |
error[i]= 0.015+0.2 * y[i]; | |
return error; | |
} | |
public static double[] errorCurrent(double[] x){ | |
double[] error = new double[x.length]; | |
for (int i=1;i<x.length;i++) | |
error[i] = 0.01+0.01 * x[i]; | |
return error; | |
} | |
private static double relativeError(double error, double value){ | |
return Math.pow(error/value,2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment