Question: Writing Procedures inside of For Loops

I'm trying to write a for loop that will generate several procedures, which doesn't quite seem to work as expected.


Here is the sample code:

for j from 1 to 2 do
f[j]:=proc(x,y)
x+y^(j)
end proc;
od;

Then if you run the following, you get:

f[1](x,y) = x+y^3

f[2](x,y) = x+y^3

 

Whereas, I'd like to have:

f[1](x,y) = x + y^1

f[2](x,y) = x + y^2

Any suggestions on why the j value goes to 3 or on how to fix this? Thanks in advance.

Please Wait...