If creativity and innovation is only market-driven, inventions may leave the world even more divided, says Microsoft co-founder.

Bill and Melinda Gates told graduating students at Stanford University on Sunday that innovation for profit alone will not solve the most pressing problems facing the planet.

Delivering the university's first joint commencement address, the two spoke of their admiration for Stanford and the "flexibility of mind" and "openness to change" it creates. But they urged students to take on problems like poverty and disease and not be driven by profit alone.

It was a good time to remind the university's roughly 5,000 graduating students of their potential to bring about change. Many will leave Stanford to join start-ups or form their own companies, and this is the time they are formulating plans for what they hope to achieve.

"There are so many remarkable things going on here at this campus, but if Melinda and I had to put into one word what we love most about Stanford, it's the optimism," said Bill Gates. "There's an infectious feeling here that innovation can solve almost every problem."

How Bill Gates became a philanthropist

Bill Gates was one such optimist in the mid-90s when Microsoft was donating computers to help bridge the digital divide. But while the project found a measure of success in the US, a trip to South Africa taught him a lot.

"My visit to Soweto became an early lesson in how naive I was," Bill said of his visit to a community centre there that had received computers.

"It became clear to me, very quickly, that this was not the United States. The people there lived in corrugated tin shacks with no electricity, no water, no toilets. Most people didn't wear shoes. They walked barefoot along the streets, except there were no streets, just ruts in the mud."

There was no electric power at the community centre so an extension cord ran 200 feet from a diesel generator to power the PCs.

"Looking at this setup, I knew the minute the reporters left, the generator would [be put] to a more urgent task. And the people at the community center would worry about problems that couldn't be solved by a personal computer," he said.

How Bill Gates wants to change the world

So now, despite having amassed a fortune from the PC industry, much of Bill and Melinda Gates' work involves not smartphones and software, or bringing isolated villages online, but the less glamorous work of developing vaccines for HIV, polio, and malaria and the ways people can lift themselves out of poverty.

Ask people if the world will get better in future and many reply that it will not, Bill Gates said.

"The pessimists are wrong, in my view. But they are not crazy. If innovation is purely market driven, and we don't focus on the big inequities, then we could have amazing advances in inventions that leave the world even more divided," he said.

"If our optimism doesn't address the problems that affect so many of our fellow human beings, then our optimism needs more empathy. If empathy channels our optimism, we will [address] the poverty and the disease and the poor schools."

The problems the graduates choose to focus on will determine whether the world gets better, he said.

"If your world is wide, you can create the future we all want. If your world is narrow, you may create the future the pessimists fear," Gates said.

"As I started learning in Soweto, if we are going to make our optimism matter to everyone and empower people everywhere, we need to see the lives of those most in need. If we have optimism without empathy, it doesn't matter how much we master the secrets of science. We are not really solving problems," he said. "We are just working on puzzles."