2

I have the following code

Clear[AdomTrunctest, AdomPolyNtest, ListPolytest, y];
AdomTrunctest = 3;
ExDtest := Sum[D[y[n, t], t], {n, 0, AdomTrunctest}];
Ntest = Expand[(y'[t])^2 /. y'[t] -> ExDtest ];
ListPolytest = 
  Reverse[MonomialList[
     Ntest /. y[x_, z_] -> EPS^x*y[x, z] /. 
      Derivative[A_, B_][y][x_, z_] -> 
       EPS^x*Derivative[A, B][y][x, z], EPS]] /. EPS -> 1;
For[i = 0, i < AdomTrunctest + 1, i++, 
 AdomPolyNtest[i] = ListPolytest[[i + 1]]]
For[i = 0, i < AdomTrunctest + 1, i++, 
 Print["A", i, " = ", AdomPolyNtest[i]]]

 y[0, t_] = 1 + 2 t 

Print["A", 0, " = ", AdomPolyNtest[0]] 

My issue is with the last few lines, if you run this code you will see the third last line prints the general form of the so called polynomials I am calculating, everything is good. However once I define y[0, t_] = 1 + 2 t in the second to last line, I expect now that once I call AdomPolyNtest[0] in the last line, that the derivative of y[0,t] be evaluated, and not left general, but it is instead left general. I believe this is because I have replaced ExDtest which was SetDelayedwith Derivative within the MonomialList command, so it is no longer "evaluated afresh" each time it is called.

Decebalus
  • 115
  • 7

1 Answers1

2

After

Clear[AdomTrunctest, AdomPolyNtest, ListPolytest, y];
AdomTrunctest = 3;
ExDtest := Sum[D[y[n, t], t], {n, 0, AdomTrunctest}];
Ntest = Expand[(y'[t])^2 /. y'[t] -> ExDtest ];
ListPolytest = 
  Reverse[MonomialList[
     Ntest /. y[x_, z_] -> EPS^x*y[x, z] /. 
      Derivative[A_, B_][y][x_, z_] -> 
       EPS^x*Derivative[A, B][y][x, z], EPS]] /. EPS -> 1;
For[i = 0, i < AdomTrunctest + 1, i++, AdomPolyNtest[i] = ListPolytest[[i + 1]]]
For[i = 0, i < AdomTrunctest + 1, i++, Print["A", i, " = ", AdomPolyNtest[i]]]

instead of locking in an explicit expression for y, consider defining a substitution function such as

suby = { y :> (If[#1 === 0, 1 + 2 #2, y[#1, #2]] &) }

This will substitute the implicit function 1+2 #2 in place of y (where #2 is the second argument of y) if the first argument of y is equal to #1 === 0:

Print["A", 0, " = ", AdomPolyNtest[0] /. suby]

A0 = 4

Kagaratsch
  • 11,955
  • 4
  • 25
  • 72