I no longer have Mathematica 7 installed, and your code runs (although with no printed output...) on Mathematica 10. Based on the error message, it sounds like you need to Clear[f]
before trying to reassign it.
For[i = 1, i < 5, i++,
Clear[f];
f = x^2 + y^2 - 10;
x = i;
eqn = (f == 0);
soln = Solve[eqn, y];
Print[soln]
]
However, you're still really mixing things up. Consider what happens with your code as the loop executes. First it starts with i=1 and says:
Clear[f]
-- or don't, this isn't the only issuef = x^2 + y^2 - 10
-- This gives me an expression with symbolsx
andy
x=i
-- This setsx=1
sincei=1
already
At this point, the expression for f
has become y^2 - 9`. Next time it comes around, it will repeat:
f = x^2 + y^2 - 10
-- Butx
is no longer a symbol!! So now it still treatsx=1
...
This becomes a nightmare. I could try to hack your code into working with the fewest changes (e.g. make it Clear[f,x]
or something), but that's not really the best advice I can give.
A better overall construction would be something like:
Eqn[x_,y_]=(x^2+y^2-10==0);
For[i=1,i<5,i++,
Print[Solve[Eqn[i,y],y]];
];
Your function f
is a function, so you should make it a function like f[x_,y_]=something
. Better yet, just make the entire equation into a function as above. That way, you never actually modify the values of x
or y
and don't get caught with issues in your loop.
And before you use this new code I've given you, clear everything or just quit the Kernel.