Search This Blog

Wednesday, September 21, 2011

pi.py


Sólo hay que escribir en la terminal:
python pi.py

para obtener una aproximación de $$\frac{\pi}{2}$$

Resultado


Kepler 16

Programación

La integración se realiza con el método de Riemann, es decir se construye un llenado de la región a integrar  con simplicios adecuados, es decir figuras de lados rectos. Aunque las curvas obtenidas sean fractales en ocasiones, no se comete un error al calcular el área, o volumen de mayor dimensión   que se desee.

Sin embargo existe otro método. El método de Monte Carlo consiste en poner puntos al azar en la región a integrar, y su universo. Después se cuentan las que están dentro y las que están fuera. El cociente entre las que están dentro sobre el total de puntos del universo, es una medida del área.

Presento en Python un programa para calcular el área:

 import numpy as np   #aca se importo la libreria numpy

#la idea es aproximar un circulo
 Ni=0
 No=0     #inicializamos variables
 NT=0

 for i in range(0,1000000):         #ciclo, podemos usar un numero cualquiera, pero hay que tener bien en cuenta que este representa el

 x=2*r*np.random.rand()         #numero de puntos aletorios  
 y=2*r*np.random.rand()  
 NT=NT+1

    d=np.sqrt((x-r)**2+(y-r)**2)     #definimos el rango

    if d

Obviamente este programa no está terminado, aquí hay otro:


import math
import random

 # define any function here!
 def f(x):
        return math.sqrt(1.0 - x * x)

 # define any xmin-xmax interval here! (xmin < xmax)

 xmin = -1.0
 xmax = 1.0

# find ymin-ymax
 numSteps = 1000000  # bigger the better but slower!
 ymin = f(xmin)
 ymax = ymin
 for i in range(numSteps):
           x = xmin + (xmax - xmin) * float(i) / numSteps
           y = f(x)
           if y < ymin: ymin = y
            if y > ymax: ymax = y

 # Monte Carlo
 rectArea = (xmax - xmin) * (ymax - ymin)
 numPoints = 1000000 # bigger the better but slower!
 ctr = 0
 for j in range(numPoints):
        x = xmin + (xmax - xmin) * random.random()
        y = ymin + (ymax - ymin) * random.random()
        if f(x) > 0 and y > 0 and y <= f(x):
         ctr += 1
         if f(x) < 0 and y < 0 and y >= f(x):
          ctr += 1 

fnArea = rectArea * float(ctr) / numPoints
 print "Area under the curve = " + str(fnArea)

El segundo programa tomado de ActiveState

Thursday, September 15, 2011

Parabola con Sage


Seno con NumPy y matplotlib


También en Ubuntu


Este ya lo hice con el Python de Ubuntu, usando el comando visual.

NASA Detects Planet Dancing With a Pair of Stars

An illustration of the planet, called Kepler-16b, which orbits two stars but is not thought to be habitable.
By DENNIS OVERBYE Published: September 15, 2011
Sometimes the orange sun rises first. Sometimes it is the red one, although they are never far apart in the sky and you can see them moving each other, casting double shadows across the firmament and periodically crossing right in front of each other.
Such is life, if it were possible, on the latest addition to the pantheon of weird planets now known to exist outside the bounds of our own solar system. It is the first planet, astronomers say, that has been definitely shown to be orbiting two stars at once, circling at a distance of some 65 million miles a pair of stars that are themselves circling each other much more closely. A team of astronomers using NASA’s Kepler planet-hunting spacecraft announced the discovery on Thursday in a paper published online in the journal Science and in a talk at a conference in Jackson Hole, Wyo.
The official name of the new planet is Kepler 16b, but astronomers are already referring to it informally as Tatooine, after the home planet of Luke and Anakin Skywalker in the George Lucas “Star Wars” movies, which also had two suns. Indeed, a representative from Mr. Lucas’s production company, Lucasfilm, expected to participate in a news conference at NASA’s Ames Research Laboratory in California, Kepler’s home office.
“Reality has finally caught up with science fiction,” said Alan P. Boss of the Carnegie Institution, a member of the research team.
While some double-star systems have been suspected to harbor planets, those smaller bodies have never been seen.
“This is a direct detection; it removes all doubt,” said Laurance Doyle of the SETI Institute in Mountain View, Calif., who led the discovery team. “It will help those guys make their case.”
Beyond the wow factor, astronomers said the discovery — as so many discoveries of so-called exoplanets have done — had thrown a wrench into another well-received theory of how planets can and cannot form. “In other words,” said Sara Seager, a planetary expert at the Massachusetts Institute of Technology who was not part of the discovery team, “people don’t really know how to form this planet.”
It was long thought, Dr. Seager said, that for its orbit to be stable, a planet belonging to two stars at once would have to be at least seven times as far from the stars as the stars were from each other. According to that, Kepler 16b would have to be twice as far out as it is to survive.

“This planet broke the rule,” she said.

Moreover, by timing all the eclipses and transits of planet and stars in the system, the astronomers have been able to measure the sizes and masses of the stars and the planet to unusually high precision, calibrating models of stellar and planetary properties.
“I believe this is the best-measured planet outside the solar system,” Dr. Doyle said. Technically, Tatooine is probably a ball of gas about the size of Saturn living in a system about 200 light-years away, in the constellation Cygnus.
If you go, pack to wear layers. Because those suns move back and forth all the time, temperatures on the planet can change by some 54 degrees over the course of a few Earth days from minus 100 to minus 150 Fahrenheit. So the weather is like “a nippy day in Antarctica at best,” as Dr. Doyle put it.
Kepler, launched in 2009, is on a three-year mission to determine the fraction of stars in the galaxy that have Earth-like planets. It scrutinizes a patch of some 155,000 stars in the constellations Cygnus and Lyra looking for dips in starlight when planets cross in front of their home stars.
In the case of the Kepler 16 system — home to Tatooine — there turned out to be a lot of dips. The two stars are about 20 million miles apart and produce two eclipses every 41 days as they take turns going in front of each other. One star is about two-thirds the mass of the Sun, the other about a fifth of the Sun.
In addition, there are smaller dips when the planet, which is about 65 million miles from the center of the system — about the distance of Venus from the Sun — passes in front of each of the stars in the course of its 229-day orbit.
The degree of dimming during the planetary transits — those times that a planet crosses the path of something else — usually allow Kepler astronomers to measure the size of a planet relative to the stars. As a result, uncertainties in the properties of stars propagate into uncertainties of as much as 25 percent in the mass of a planet — enough to blur the line between a rocky planet and a gaseous one.
But in the Kepler 16 system, by comparing slight variations in the timing of the transits with calculations of the positions of the stars and the gravitational nudges the bodies give one another, Dr. Doyle’s team could deduce the absolute masses and sizes of the stars and planets in the system. That is a tool, they say, that is becoming increasingly valuable for determining the masses of small planets in multiple-planet systems.
As a result, said Dr. Doyle, “it’s a laboratory for all sorts of physics and stellar evolution.”
The Tatooine laboratory will be available to a wide audience for at least a while longer. Dr. Doyle noted that amateur astronomers in northern Asia, equipped with as little as an eight-inch telescope and an off-the-shelf CCD detector (an electronic device that cameras use to capture images), would be able to record the passage of the Tatooine planet across the brighter star in its system on June 28 next year.
But enjoy it while you can. Because of variations in the planet’s orbital plane, as seen from Earth, the planet will stop crossing one of the stars as soon as 2014 and cease transiting the other, brighter one in 2018. It will be around 2042 before the show starts up again for Earthlings.
NYT

Wednesday, September 14, 2011