Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package pennystack;
- /**
- *
- * @author Andrew
- */
- public class PennyStack {
- private static class Penny{
- public double thickness, height;//Thickness in inches; height in altitude above sea level of the bottom of the coin, measured in inches
- public double stress;//Stress at the bottom of this penny, in psi
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Penny[] thePennies = new Penny[16172452];
- thePennies[0] = new Penny();//initialize first penny
- thePennies[0].thickness = .056;
- thePennies[0].stress = 0;
- for(int i = 1; i<thePennies.length; i++)//initialize other pennies
- {
- thePennies[i] = new Penny();
- thePennies[i].thickness = .056;
- thePennies[i].height = thePennies[i-1].height + thePennies[i-1].thickness;
- thePennies[i].stress = 0;
- }
- double error = 1;//error in the height of the top of the tower
- while(error>.1){
- double lastHeight = thePennies[16172451].height + thePennies[16172451].thickness;
- System.out.println(lastHeight);
- thePennies[16172451].stress = 0;
- for(int i = thePennies.length-2; i>=0; i--)
- {
- thePennies[i].stress = thePennies[i+1].stress + getWeight(thePennies[i])/getArea(thePennies[i]);
- thePennies[i].thickness = getThickness(thePennies[i]);
- }
- for(int i = 1; i<thePennies.length; i++)
- {
- thePennies[i].height = thePennies[i-1].height + thePennies[i-1].thickness;
- }
- error = Math.abs(lastHeight - (thePennies[16172451].height + thePennies[16172451].thickness));
- }
- System.out.println(getWeight(thePennies[16172451]));
- System.out.println(getWeight(thePennies[0]));
- }
- public static double getThickness(Penny p)
- {
- return .056-.000000175*p.stress;
- }
- public static double getArea(Penny p)//a more dedicated programmer could find the dependence on area, but that is beyond the linearization of compression we started with.
- {
- double r = .374;
- return Math.PI * r * r;
- }
- public static final double m = 0.0025;//weight of a penny, in kg
- public static final double M = Double.parseDouble("5.97219E24");//Mass of the earth, in slugs
- public static final double G = Double.parseDouble("6.67398E-11");//Gravitaional constant of the universe, in m^3 kg^-1 s^-2
- public static final double Re = 6371000;//radius of the earth, in meters
- public static double getWeight(Penny p)
- {
- return (G * M * m / Math.pow(Re + (p.height*.0254), 2))* 0.224808943 ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement