Created
January 30, 2013 14:17
-
-
Save thisMagpie/4673547 to your computer and use it in GitHub Desktop.
class to hold main method for hall experiment
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); | |
| gnuPlot.printGradient(xScan,yScan); | |
| double[] residual = gnuPlot.computeResidual(); | |
| xyError(xyWriter, gnuPlot.getX(),gnuPlot.getY(),errorCurrent(gnuPlot.getX()),errorVoltage(gnuPlot.getY())); | |
| xyWriter.close(); | |
| xyError(residualWriter, gnuPlot.getX(), residual,errorCurrent(gnuPlot.getX()),error(gnuPlot.getY(),gnuPlot.rss())); | |
| residualWriter.close(); | |
| printHallCoefficient(printNoDensity(gnuPlot.getGradient(),field,gnuPlot, fieldError, type)); | |
| } | |
| } | |
| 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]=(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 conf){ | |
| double[] error = new double[dat.length]; | |
| for (int i=0;i<dat.length;i++) | |
| error[i] = conf * dat[i]; | |
| 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 electron = 1.6022 * Math.pow(10,-19); | |
| double numberDensity = field / ((gradient) * 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)); | |
| 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