# Mathematica calculus help

• Jan 25th 2011, 11:06 AM
TRex77
Mathematica calculus help
So this is my first time using mathematica and I am having a small problem. I thought I had figured out the question but then looked at my friend's answer and mine was just a little off so I switched around the problem to try to get his answer.

For some reason I keep getting outputs with "Pa" when I solve the equation

Said equation:

For[i = 1, i < 51, i = i + 1, Qa = (100000 - 200 Pa/3) (1.01)^(i - 1);
sol = Solve[{Qa == 50}, {Qa}]; quant[i] = First[Qa /. sol]]
Array[quant, 50]

I am trying to solve for Qa for years 1-50

Thanks for the help!
• Jan 25th 2011, 11:16 AM
Ackbeet
That's a very puzzling piece of code. Why are you solving for Qa when you already have Qa = (100000 - 200 Pa/3) (1.01)^(i - 1)? In order to get rid of the Pa, you're going to have to assign its value somewhere above the bit of code you've given. Here's a way to find out if Mathematica knows the value of a variable:

Type in the variable in a new cell, and hit Shift-Enter (that is, evaluate the cell). If Mathematica spits back the variable right back at you, then it hasn't been assigned a value. But if it returns something other than the variable name, then it has been assigned.

Also, I don't think this code is going to do what you want: you've assigned Qa using the = assignment operator. That's a one-shot deal. Whatever is in the for loop initiation gets assigned once. So, you're going to have

Qa=(100000 - 200 Pa/3) (1.01)^(1 - 1) = 100000 - 200 Pa/3, no matter what value of i you loop through. Try the delayed definition of :=. Then, whenever you change the variable i, Qa will change right along with you. Another way to handle it is to put the Qa assignment in the main body of the for loop, instead of in the initialization part.

Hope this helps.