Isn't this how it happened:
Man designed machines, machines became self aware, man saw them as threat and declared war on them, war went on for decades, man was losing. In a desperate attempt to win over the machines, man blocked out the sky, removing the solar driven machines power source.
The machines adapted, they transformed their creators into powerstations. But humans are a bitch, they require stimulation to keep functioning and thus the matrix was created.
Man > Machine > Sentient > Threat > War > Lost > Matrix