What is the purpose of Prayer? We are having a lovely discussion in chat about the purpose and efficacy of prayer.

I am of the opinion that God has a plan and the future is completely set. However I also believe that you should pray for what you need and that God will answer your prayer. 

What scripture forms the basis for our prayers and how do we rationalize praying when the outcome is set?
This is an awfully big question, but here are what I think are the key points from scripture:


Prayer is more than just asking for things.  Tom Duckering's answer does a good job outlining this, but to gloss it again, prayer is communication with God which involves both talking to God and listening to him.  As our primary form of communication with God, it reinforces in us our relationship with him in all its forms.
Prayer does include asking for specific outcomes.  There are far too many examples to ignore: Abraham conversing with God over Sodom and Gomorrah, David pleading for Bathsheba's son, Hannah praying for a child, even Jesus praying that the cup be taken from him.  God wants us to ask for things, even though he doesn't always give us what we ask for.
(Here's where it gets a bit controversial) God can and does "change his mind"†.  My favorite example of this is Exodus 32, the story of the Golden Calf. Briefly, God tells Moses he is going to destroy the Israelites, but relents when Moses pleads with him not to. This is the classic definition of intercession: Moses stands between Israel and God and intervenes on their behalf.

This seems counter-intuitive, but God makes it quite clear that he wants people to intercede with him.  See Ezekiel 22:30:


  I looked for someone among them who would build up the wall and stand before me in the gap on behalf of the land so I would not have to destroy it, but I found no one. (Ezekiel 22:30 NIV)


This verse makes explicit what lots of stories in the Old Testament imply: God actively seeks people who will intercede with him.  So in the story of Golden Calf, it seems quite likely that God went to Moses hoping that Moses would react the way that he did.  Why?  Because as long as Moses was faithful there was still hope for Israel, and the rest of the story bears this out as Moses goes down to the camp and restores order.

The important point here is that God does not change, we do.  If Moses responds with apathy, then Israel is lost and the best that God can do is show his righteous wrath by destroying them.  But because Moses responds with prayer, God can take the better path of using Moses to lead them back to him.

What about times when we intercede but we have no actual control over the situation, like praying for healing?  Our prayers affect what God does because our involvement changes the picture from God's perspective.  If we are indifferent and don't bother praying, then what he does will not have any great effect on us.  But if we are deeply involved in prayer, then our hearts are on the line.  If God comes through, we will be affected and we will give the glory to God.  Our prayers, then, factor into God's decision of what he will do, and maybe, just maybe, our involvement will be enough to tip the balance.


If none of this made any sense, here's at least a great C. S. Lewis quote on the topic:


  "Praying for particular things," said I, "always seems to me like
  advising God how to run the world. Wouldn't it be wiser to assume
  that He knows best?" 
  
  "On the same principle", said he, "I suppose you
  never ask a man next to you to pass the salt, because God knows best
  whether you ought to have salt or not. And I suppose you never take an
  umbrella, because God knows whether you ought to be wet or dry."
  
  "That's quite different," I protested.
  
  "I don't see why," said he. "The odd thing is that He should let us influence the course of events
  at all. But since he lets us do it in one way I don't see why He
  shouldn't let us do it in the other." 
  
  (C. S. Lewis, God in the Dock)


† God "changes his mind" perhaps only from our perspective inside of time.  God actually seems to exist outside of time entirely, and so perceives all points in time simultaneously.  It's hard to understand this without time words, but before (a time word!) the creation of the world God sees everything that will happen, and writes his entire plan around what he knows that we will do.