The mathematics that explains the natural world usually takes the form of equations. Examples include Newton's law of gravity, Maxwell's equations of electromagnetism, and Schrodinger's equation for describing the behavior of a quantum system. Sometimes equations do not have exact solutions so calculations are required. For example, Newton's law of gravity is only exact in the simple but artificial situation of two objects isolated in space. As soon as three or more objects are in the system, Newton's law become an approximation and the gravity between the objects must be calculated. In the nineteenth century, clever mechanical devices were invented to do calcuations reliably and fairly rapidly, at least compared to doing calculations by hand on paper. The idea of a digital computer was first presented by Alan Turing in 1936, and after the Second World War the first modern computers were built. These early computers were the size of a living room, they used a lot of power, and they used relays and vacuum tubes since transistors had not yet been invented.
Picture of Alan Turing, age 16. He was the one who came up with the idea of a digital computer that then led to the technology we have today. . Click here for original source URL.
The modern revolution in computing that led to handheld calculators and desktop computers has also transformed science. For forty years, the speed and power of computers have been growing exponentially, with an improvement by a factor of two roughly every two years. This is the only aspect of modern life where progress has been so rapid. The smartphone that most people use every day is a hundred times more powerful than the computer that got the Apollo astronauts to the Moon. A calculation that would have taken months two decades ago can now be done in mere seconds. Scientists can do calculations that would have been inconceivable before the invention of the computer. This revolution has touched every area of astronomy.
When a computer is used to simulate some aspect of the universe, the simulation is only as good as the physics that is fed into the computer. In other words, a computer cannot take the place of theory, no matter how cleverly it is programmed. However, computation can be used to model or simulate very complex physical situations and in those cases it can lead to insights. For example, in the Solar System, Newton's law of gravity cannot be applied with perfect accuracy because there are eight planets and other small bodies orbiting the Sun and each one exerts gravity on all the others. When astronomers started to simulate the long term behavior of the Solar System, they made some surprising discoveries. They found that small changes in the starting configuration accumulate and lead to large eventual differences in the orbits. This is sometimes called the "butterfly effect." They also found that the system could becme chaotic, where some objects stopped being stable and repeatable in their orbits and changed their positions or were even ejected from the system entirely. Now that we know of many planetary systems beyond the Solar System, simulations are extremely important in understanding and preducting their properties.
On the largest scales, astronomers started applying computers to understanding galaxies and the universe in the 1980s. In this kind of simulation, there is not enough computational power to input all the stars in a galaxy or all the galaxies in the universe, so a "particle"in the simulation is usually standing in for many stars or only the biggest galaxies. Here's what happens in the simulation: a three dimensional grid of space is created virtually in the computer, it is populated with galaxies, the gravity force of each galaxy on every other galaxy is calculated, all the galaxies respond to the forces by moving slightly in the virtual space, then the gravity forces are recalculated at the new positions, and this process repeats for a long as neccesary. One complication is that universe is expanding so the virtual space has to grow as time goes by to represent Hubble expansion. With many calculations and many time steps the evolution of large scale structure in the universe can be simulated.
How many calculations? A lot! If the force of every particle on every other particle must be calculated, it adds up quickly. If there are N objects exerting gravity, the number of calculations is N × (N-1), where the gravity of an object on itself doesn't need to be calculated. When N is large the number of calculations goes up as N2. For a hundred objects, that means 10,000 calculations. For a thousand ojects, it means a million calculations. for a million objects, it means a trillion calculations. The largest astrophysical simulations use supercomuters to follow tens of billions of particles, so they can simulate the behavior of a large chunk of the universe, although it might take weeks or months to simulate billions of years of cosmic evolution. This type of science is called an N-body problem.
Computers allow problems to be attacked by brute force but programmers still use clever tricks to make the simulations better or run faster. For example, since gravity weakens with the inverse square of distance, in practive it's not neccesary to calculate the force of every particle on every particle. It's a good approximation to only consider the nearest particles and estimate the net force from all the others. N-body simulations have been used to show how the universe went from an early hot and smooth state to a larger and cooler state filled with galaxies and clusters of galaxies. Simulations have also been used to show what happens when two galaxies interact or collide. So far we've only talked about Newtonian gravity, which is fine for simulating a solar system or a star cluster or a galaxy. But computers can also be "fed" the equations of general relativity so that the conditions near a black hole can be simulated. Or a simulation can have gas particles added since a diffuse gas behaves differently from compact objects like stars. The result is called a hydrodynamic simulation.
Computers are ubiquitous in astronomy and simulations are contributing to the health and advancement of the subject. Astronomy stands on a sturdy tripod of observations, theory, and simulations. Observations and data lead the subject since discoveries are being made all the time. Theory is a crucial backdrop for understanding the observations. And now simulations play a role in understanding complex situations and suggesting new observations.