Image copyright Getty Images

It has long been known that happiness depends on many different life circumstances.

Now scientists have developed a mathematical equation that can predict momentary delight.

They found that participants were happiest when they performed better than expected during a risk-reward task.

Brain scans also revealed that happiness scores correlated with areas known to be important for well-being.

The team says the equation, published in PNAS Journal, could be used to look at mood disorders and happiness on a mass scale. It could also help the UK government analyse statistics on well-being, which they have collected since 2010.

Image copyright ucl Image caption The equation looks at expectations, rewards and past outcomes

"We can look at past decisions and outcomes and predict exactly how happy you will say you are at any point in time," said lead author Dr Robb Rutledge from University College London.

"The brain is trying to figure out what you should be doing in the world to get rewards, so all the decisions, expectations and the outcomes are information it's using to make sure you make good decisions in the future. All of the recent expectations and rewards combine to determine your current state of happiness," he told BBC News.

Think of going to a restaurant for example, having low expectations may improve your dining experience if the food is better than expected. But having positive expectations may improve your happiness before the meal even starts because of your anticipation of the event.

Image copyright AFP/getty images Image caption "This is the best moment of my life" said Mo Farah when he won the men's 5,000m final in London 2012

To build the mathematical model, the team analysed the results of 26 people doing a task in which, over repeated trials, they chose between definite and risky monetary rewards. Every few trials they were asked to report their level of happiness.

Participants' brains were also scanned using fMRI (functional magnetic resonance imaging).

Activity in two areas of the brain correlated positively with happiness scores; these were the ventral striatum - a main source of dopamine neurons - and the insula, an area of the brain known to be important for several emotions including happiness.

The striatum was associated with changes in happiness and the insula with overall levels of happiness.

The equation was then applied to over 18,000 people who played a smartphone risk-reward game in The Great Brain Experiment app, which was recently shown to be a reliable way of studying cognitive behaviour.

We are all creatures of comparisons and are thus prisoners of implicit expectations Prof Andrew Oswald, Behavioural economist, University of Warwick

While the experiment was far more simplistic than real world events, Dr Rutledge said that like in real life, the subjects took risks in order to gain rewards.

"We were pleased to see that our equation did a good job of explaining happiness. Even over this wide range of participants, there is a surprisingly consistent relationship between rewards, expectations, and happiness.

"I'm hopeful this mathematical equation lets us get a better understanding of things we all care about, like how happy we are in general," he added.

Commenting on the work, Tom Stafford a cognitive scientist at the University of Sheffield, said it was impressive that the equation could predict happiness with such accuracy, "especially given how unpredictable humans are".

"The importance of this study is the way it knits together brain activity, a computational account of reward and large-scale crowd sourcing of data on how people feel," added Dr Stafford.

But he said that it was not clear that the equation could give insight into some of the "big questions" of happiness in real life, like which partner to choose.

Image copyright Thinkstock

Another independent researcher, Prof Andrew Oswald, a behavioural economist at the University of Warwick, said it was striking that brain patterns matched people's answers in happiness surveys.

"The study also finds that your immediate sense of happiness depends on the size of the gap between what you achieve and what you expect. That makes good intuitive sense. It also fits with a great deal of statistical work by economists showing that happiness and job satisfaction is influenced by a person's relative pay," Prof Oswald told BBC News.

"If you want to know how happy I am, don't ask me my salary. Ask me how my salary compares to other professors or to my own salary in the past. It is the gap - whether positive or negative - that really matters. We are all creatures of comparisons and are thus prisoners of implicit expectations."

Those without a maths degree may find it difficult to read the equation but anybody can take part in the mobile risk-reward game, which will in turn contribute more data to the project.

Follow Melissa on twitter