Friday, April 6, 2012

sumpin sumpin....

I got drunk tonight, wrote a Monte Carlo integration program in Java for shits, and now I'm watching The Marx Brothers "A Night at the Opera" which is pretty funny...

The error estimate is way off.  ...  I'm drunk, so fuck it.This is a crappy way to do integrals, but it is cheap and quick (relatively speaking).  During the Manhattan Project (back when computers where people rather than machines... and women, too, even though in today's society women hate math and prefer barbie dolls thanks for shitty advertizements and gender roles based on capitalist shit), this was how you did numerical integration.


import java.util.Arrays;
import java.util.Random;
/**
 *
 * @author discordantmind
 */
public class MonteCarloIntegration {
    public static void main(String[] args) {
        /* Create program to calculate Monte Carlo Integration
         * The integrand is a separate method called 'integrand'
         */
        // create random points for integration, and sort from highest to lowest
        int numberPoints = 20; // how many points along curve should be evaluated
        int endPoint = 2;
        double[] xposition = new double[numberPoints];
        Random xGen = new Random();
        for(int i=1 ; i < (numberPoints - 1); i++) {
            xposition[i] = endPoint * xGen.nextDouble();
         //   System.out.println(xposition[i]);
        } 
        xposition[0] = 0.;
        xposition[numberPoints - 1] = 2.;


        Arrays.sort(xposition); 
        
        // check to see if points are sort-of evenly spread out
        for (double dd : xposition){
            System.out.println(dd);
        }
        
        //Create new random number generators for x and y coordinates 
        Random xtestpoint = new Random();
        Random ytestpoint = new Random();
        
        // starting stuff for Monte Carlo shit
        double testx;
        double testy;
        double interval;
        int below;
        double testintegral;
        double area = 0; // initialize integral
        int numberRandom = 100; // number of random points for MC
        double error = 0; // initialize error counter thingy
        double rho; // density of points below curve
        /* BEGIN MONTE CARLO SHIT */
        for(int i=0; i < (xposition.length - 1); i++) {
            // Taking care of end points
            interval = xposition[i+1] - xposition[i];
            below = 0;
            for(int j=0; j<numberRandom; j++) {
                testx = xposition[i] + interval * xtestpoint.nextDouble();
                testy = 2.0 * ytestpoint.nextDouble();
                testintegral = integrand(testx);
                if(testy <= testintegral) {
                    below++;
                }
            }
            rho = below/ (double) (numberRandom);
            area += interval * 2.0 * rho;
            error += interval * 2.0 * Math.sqrt((rho - Math.pow(rho,2))/numberRandom);
        }
        System.out.println("Error estimate is " + error);
        System.out.println("Integral from 0 to "+ endPoint + " is: " + area);


    }
    public static double integrand(double x) {
        // plug in whatever function you want to integrate here as 'func'
        double func = Math.sqrt(4. - Math.pow(x,2)); 
        return func;
    }
}
I can't really drink hard liquor anymore.  I'm still taking aspirin therapy, which means I can't drink to heavily or I could hemorrhage into my brain.  But, the doctor said I can stop taking Plavix, which is nice...

Enhanced by Zemanta

Friday, March 30, 2012

Mental Lists

I maintain a few lists of things in my head, for whatever reason.  I add to them from time to time.  Here are a few.

  1. List of actors/actresses/celebrities that I hate.
  2. List of politicians that I hate.
  3. List of people who will be among the first against the wall when the Revolution comes (includes some members from list #1 or #2).
  4. Movies that I like even though they are crap.
  5. Movies that I secretly enjoy, though I won't confess it to people
  6. Movies that I should appreciate even though I don't (also kept secret).
  7. List of lists to keep in my head.... (oddly enough, this doesn't fall into a recursion)

Wednesday, March 14, 2012

Pi Day

Today is Pi Day.  March 14, is 3/14..... 3.14... Which is similar to pi.  Actually, pi keeps going past 3.14, it doesn't repeat and doesn't stop.  So, you could say that it isn't really a "Day" for Pi, since pi doesn't stop at 3.14.  You could take it out to 3.14159, take the 159/100 as a fraction of a day and say that tomorrow has a "Pi hour" from 3 to 4 in the morning.  Or a "Pi instant" at 3:49am... of course, pi keeps repeating, so there's no point is celebrating the infinitely short duration that would correspond to pi.  Just celebrate the whole day like a bunch of cretins ;)

Tuesday, March 13, 2012

Killing Afghanis

I just heard on the news that The President of the United states said the killing of 16 Afghani civilians was "outrageous and unacceptable."  Something easy to quote, and the media decided to do, as is their duty.  I imagine the President's men spent a great deal of time agonize over which two words he should express in his press conference, and  made sure to tell the White House press corps to make sure to highlight those two words.  It couldn't be "abhorrent."  No.  That might signal something about how abhorrent our troops are, and our troops are all (naturally) heroes, n'shit.  "Unacceptable" is good.  Killing those people in there homes (unarmed civilians... including children)... that's really "unacceptable."  This kid is going to get a "stern talking to."  Maybe he'll get reduced to pay-grades, for that "unacceptable" behavior.  I remember getting a B in math, once, and my mom told me something similar.  "You love algebra!  This behavior is outrageous and unacceptable!"

Yeah, that US soldier was there in support of US Special Forces who were training am paramilitary force to help reinforce US troops.... A sort of Vietnamization of the Afghan war.  What a load of BS.  I don't even know where to begin.  It's like grading a C-student's physics homework.  I'd like to help but ALL of your assumptions are wrong, to the point where I think you should just drop of out college altogether and become a firewatcher.  Yes, someone who's sole ability is to watch fires.  You don't report fires as the occur.  You don't help fight the fires.  You watch them, because that's all your fucking little brain can handle.

Killing kids is really terrible, though.  All of it is terrible, but the kids really stick with you.  How many of those kids could have grown up to be brilliant?  How many of those kids could have become mathematical geniuses like Srinivasa Ramanujan.  Or a brilliant painter or artist?  And if you think those sorts of things are rare, all human life is rare, and to be honest everyone is brilliant to some degree... And if you think its rare in Afghanistan, maybe it's because they don't have schools and a proper infrastructure to support all the geniuses clipped at the bud... And if you think that a First World country can come to Afghanistan to bring them schools and a proper infrastructure by sending in soldiers armed to the teeth, then you should really quit what you are doing right now and pursue a career as a firewatcher.
Enhanced by Zemanta

Thursday, March 8, 2012

How to feed geese.

You bring a bag of bread crumbs to the pond, and throw some crumbs near a couple of geese.  The geese come closer, eating the crumbs.  You throw them a few more.  The geese eat them and come closer.  You drop a few more bread crumbs near your feet, since the geese are already there.  They eat them before they hit the ground.  You are out of bread crumbs.  The geese attack your pant legs.  You try to walk away.  The geese are birds and can fly faster then you can walk.  You run.  They fly.  You get home.  The geese shit on your car.

Tuesday, March 6, 2012

Religion

Getting into an argument with someone over religion is like explaining a joke to a slow person.  They'll never get it, and when you finally give up, its lost its humor.

Thursday, March 1, 2012

Leap years


I hate leap years.  It isn't that every four years (with some exceptions) we get an extra day.  What I hate is that we think we have it all figured out.  We know that a year is 375.25 days.... exactly.... right?  Wrong.  It's more along the lines of 365.242199 days per year.... But, it's even more complicated than that.

And it changes periodically, depending on a number of factors. The Earth is in orbit around the sun, but it isn't really in a vacuum.  The Earth picks up matter from space, expels matter into space, collisions from asteroids of various shapes distort our orbit, slightly.

Bad Astronomy also did a blog on something similar.  It is exceptionally difficult to determine when we determine when a year is up.  It should be based on when we return to the same place in our orbit.  Ok, when is that?  How do we determine that?  Based on the fixed stars?  But, the Sun is moving through its orbit in the galaxy, so those fixed frames of reference are themselves changing.

Why do I hate leap year?  Because we think we've got the year all figured out, and that we think it is precisely 365.25 days...

Discordianism states that all the order in the Universe is an illusion.  We wish there to be order, so we impose it on all our observations.  We create rules and structures and all of science is based upon those our observations whose underlying theorem is that there is a form or order... a set of rules which we must understand....  Maybe Chaos is just plays tricks with us...