I am writing a program which iteratively solve and make substitution from a list. As I have shown in the code substitution works when I enter the value directly (Input 100). When I extract the same value from a list and substitute (102),It does not seem to work. I have checked the FullForm for both and they are same.

x''[t] /. x -> Function[{t}, A Cos[t]]

(* -A Cos[t] *)


(* A Cos[t] *)

x''[t] /. x -> Function[{t}, xsol[[1]]]    

(* 0 *)

I am new to Mathematica. Could someone please explain the right method to do it. Thanks

  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Mar 15 '15 at 18:30
  • $\begingroup$ Please precisely specify xsol[[1]]. $\endgroup$ – bbgodfrey Mar 15 '15 at 18:34
  • 1
    $\begingroup$ Try x''[t] /. x -> Function[{t}, Evaluate@xsol[[1]]] $\endgroup$ – Nasser Mar 15 '15 at 18:34
  • $\begingroup$ @Nasser Thanks it worked. $\endgroup$ – feminkk Mar 15 '15 at 18:36
  • 1
    $\begingroup$ The reason that Evaluate is needed is that Function has attribute HoldAll $\endgroup$ – Bob Hanlon Mar 15 '15 at 20:29