Referring to the various canon sources, we can see a number of reasons why the machines chose to create a Matrix for the humans, rather than simply using cows or pigs.
The Animatrix Canon
At the end of the sequence "Second Renaissance - Part II", we see the machine negotiator at the UN receiving (and accepting) the human negotiator's "Instrument of Surrender". He states his sole precondition, that the humans will "Hand over your flesh".
Although the machines are shown to be creatively vicious, there is no indication whatsoever that they intend to renege on the agreement and kill all the remaining humans.
Comic Canon
Regarding the reason why the machines don't simply use cows, in the story "Goliath", written by Neil Gaiman, we learn that the humans are being used not only for their electrical energy but also that the machines are using humans as memory storage and processing units.
What's going on?" I asked. "Do you know?" "Enemy missile took out a
central processing unit," he said. "Two hundred thousand people,
hooked up in parallel, blown to dead meat. We've got a mirror going of
course, and we'll have it all up and running again in no time flat.
You're just free-floating here for a couple of nanoseconds, while we
get London processing again."
Additionally, the machines then use a human pilot (in an attempt to
avert an invasion by aliens) because he is a more capable pilot than the machines themselves are able to provide.
"Why me?"
"Well," he said, "the short answer is that you were designed to do
this. We've improved a little on the basic human design in your case.
You're bigger. You're much faster. You have faster processing speeds
and reaction times."
Film Canon
In the final sequence of The Matrix Revolutions, we see the Architect pouring scorn on the idea that he might renege on the deal made with the Zion humans.
Oracle : I have your word?
Architect : What do you think I am, human?
This ties in very nicely with The Animatrix canon. The machines accepted the instrument of surrender and have been trying ever since, to keep the humans in a state of quiescence rather than attempting (as they could very easily) to kill them.