As I cycled into work this very chilly morning I was very thankful for my extra gloves, coat, hat and thermals. But I only knew I was going to need them thanks to the mathematics behind the weather app on my phone that accurately predicted this sudden cold snap.

How does your app know what the weather is going to be like? Image: DorisWeasley, CC BY-SA 3.0

The weather is a result of the motion of the Earth's atmosphere and oceans, the way moisture is moved around in the atmosphere, coupled to changes in the pressure and temperature of the air. The atmosphere and the oceans are *fluids* — liquids or gases. Luckily for meteorologists, there's a set of equations that describes the behaviour of fluids, called the *Navier-Stokes equations*.

The general idea behind a weather forecast is relatively straight-forward. You start by taking measurements of factors that describe the current weather, such as temperature, air pressure and density, wind speed and the moisture content of the air. You then feed these starting values to a mathematical model that is built on the Navier-Stokes equations and which allows you to evolve the weather forward in time on a computer.

In practice, though, there are several things that make weather forecasting tricky. Firstly, you can't possibly measure temperature, pressure, moisture, and so on, at every single point on the Earth or region you're interested in. Secondly, you can't measure them with infinite accuracy. And the famous *butterfly effect* – the idea that the small air disturbance caused by a butterfly's beating wing can develop into a tornado halfway around the world – means that the inevitable inaccuracies can snowball as the computer makes the calculations, potentially producing a forecast that is way off.

A third problem is that the equations involved in a weather model are incredibly difficult to solve. The *Navier-Stokes equations* are in fact the subject of one of the biggest open problems in mathematics. Nobody knows if physically meaningful solutions even exist for the most general form of these equations. If you can prove or disprove their existence, you're set to win a million dollar prize (find out more in this article).

Weather models divide the Earth and its atmosphere into a grid. Image: NOAA.

Instead of solving the underlying equations exactly, meteorologists use computers to approximate solutions, in an approach called *numerical weather prediction* (NWP). They divide the Earth and its atmosphere into a grid, much like a TV or computer monitor divides an image up into pixels. And just as every pixel on a monitor is assigned a single colour, so every grid box is assigned just a single value for each of pressure, moisture, temperature, and so on — a value that comes from a manageable number of measurements taken in an individual grid box. To make the calculations more tractable, simplified versions of the equations involved can then run across this grid, generating the forecast for the next time step (say, in an hour) for each grid box. The butterfly effect can then be mitigated using techniques such as *ensemble forecasting* (see here to find out more).

In current state-of-the-art weather models the grid points are about 1.5km apart in the horizontal direction and 300m in the vertical direction: even fast supercomputers can't handle a higher resolution. Processes and features that occur inside grid boxes, such as clouds, aren't directly predicted (or taken as input) by weather models. Instead, they are estimated using mathematical formulae that roughly describe the physics involved. Such estimations are called *parameterisations*. (You can read about a potentially new approach the modelling of clouds here.)

The most complex weather models are called *Earth system models*, which not only tightly link models of the ocean and atmosphere to each other, but also link these to mathematical descriptions of other components such as the sea-ice, the surface of the land, and so on, to capture the interactions across the whole of the Earth's weather system.

You can read more about NWP and the maths of understanding weather and climate on *Plus*.