I need to define a function fun
, and then re-define this function iteratively. The code is given at the end.
First, a function fun[x_, y_, d_]
is defined, which is a polynomial in $x$ and $y$, and $d$ is the degree of this polynomial.
My goal is to modify fun
according to some of its coefficients, see the definition fun2[x_, y_, d_]
for example.
The problem is that, these coefficients are $0$ if $d$ is not substituted by a "real" number, like $d = 1$. See the code between the definitions of fun
and fun2
.
Just after the definition of fun2
, I compute fun2[x, y, d]
and it is the same as fun1[x, y, d]
. The reason is that $d$ is not assigned a value. But fun2[x, y, 1]
gives the desired answer, which is different from fun[x, y, 1]
.
The problem is that I want to repeat this process many times, say
fun3 = fun2 + Coefficient[fun2, x^2]
fun4 = fun3 + Coefficient[fun3, x^3]
....
fun"d" = fun2 + Coefficient[fun"d-1", x^(d-1)]
(This is just an example, the real process I need is far more complicated and can not be deined in one go. In this example, one can just use Sum[Coefficient...]
.)
Of course I don't want introduce so many functions. I want to define fun
and modify it in a for loop. But the code below shows that Coefficient[fun[x, y, d], ...]
is always $0$, since $d$ is not assigned a value.
I can't use a variable like temp
in this for loop, because
For [i =...
....
temp = fun[x, y, d]
temp = temp + Coefficient[temp, x^i]
...
will just give fun[x, y, d]
, as Coefficient[temp, x^i]
is always $0$ as mentioned above.
I need a suggestion on how to do such work more elegantly.
Sum
, you can "Convert To > InputForm" from the "Cell" menus before copying, if that's a problem. $\endgroup$