Created
January 31, 2013 04:59
-
-
Save thisMagpie/4680353 to your computer and use it in GitHub Desktop.
hall offet calculations
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); | |
| String type = xScan.nextLine(); | |
| double field =IOUtil.skipToDouble(xScan); | |
| double fieldError =IOUtil.skipToDouble(xScan); | |
| double deltaField = IOUtil.skipToDouble(xScan); | |
| gnuPlot.printGradient(xScan,yScan); | |
| double[] residual = gnuPlot.computeResidual(); | |
| xyWriter.printf("Current Voltage xerr yerr \n"); | |
| xyError(xyWriter, gnuPlot.getX(),gnuPlot.getY(),errorCurrent(gnuPlot.getX()),errorVoltage(gnuPlot.getY())); | |
| xyWriter.close(); | |
| residualWriter.printf("Residuals Voltage xerr yerr \n"); | |
| xyError(residualWriter, gnuPlot.getX(), residual,errorCurrent(gnuPlot.getX()),error(gnuPlot.getY(),gnuPlot.rss())); | |
| //xyError(residualWriter, gnuPlot.getX(), residual,errorCurrent(gnuPlot.getX()),errorResistance(gnuPlot.getY())); | |
| residualWriter.close(); | |
| printHallCoefficient(printNoDensity(gnuPlot.getGradient(),field,gnuPlot, fieldError, type,deltaField)); | |
| } | |
| } | |
| 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=0;i<y.length;i++) | |
| error[i]= 0.005* y[i]; | |
| return error; | |
| } | |
| public static double[] errorResistance(double[] y){ | |
| double[] error = new double[y.length]; | |
| for (int i=0;i<y.length;i++) | |
| error[i]=1+(0.009* y[i]); | |
| return error; | |
| } | |
| public static double[] errorCurrent(double[] x){ | |
| double[] error = new double[x.length]; | |
| for (int i=0;i<x.length;i++) | |
| error[i] = 0.01+(0.01 * x[i]); | |
| return error; | |
| } | |
| public static double[] error(double[] dat, double perc){ | |
| double[] error = new double[dat.length]; | |
| for (int i=0;i<dat.length;i++) | |
| error[i] = perc; | |
| return error; | |
| } | |
| private static double relativeError(double error, double value){ | |
| return Math.pow(error/value,2); | |
| } | |
| private static double printNoDensity(double gradient, double field, GNUPlot gnu, double fieldError, String type, double deltaB){ | |
| double numberDensity=0.0; | |
| double electron = 1.6022 * Math.pow(10,-19); | |
| if(type.equals("P-Type")) { | |
| numberDensity = field / ((gradient-0.156972) * electron); | |
| } | |
| else if(type.equals("N-Type")) { | |
| numberDensity = field / ((gradient+0.156972) * electron); | |
| } | |
| System.out.printf(" %s Germanium with a magnetic flux density of of $%gmT$\n",type, field); | |
| System.out.printf(" Flux density has an error of $%gmT$", fieldError); | |
| System.out.printf(" The number density of the sample is $%g m^3/C$\n Gradient is %g \n", numberDensity, gradient); | |
| double errorNumberDensity= Math.sqrt(relativeError(gnu.getGradientError(),gradient)+relativeError(fieldError,field)+relativeError(deltaB,field)); | |
| System.out.printf(" Number density has a relative error of %g m^3/C", errorNumberDensity); | |
| return numberDensity; | |
| } | |
| private static void printHallCoefficient(double numberDensity){ | |
| double electron = 1.6022 * Math.pow(10,-19); | |
| double hallCoefficient = 1/(electron * numberDensity); | |
| System.out.printf("\n Hall Coefficient is %g", hallCoefficient); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment