I want to have a function called printRes[expr_,var_]
, which does the following:
x=1;
expr:=a*x^3;
result=printRes[expr,x];
result
(* derivative of a*x^3 relative to x is 3ax^2, and when x=1, result is 3a. *)
I am unable to put all this into a row after many tries. How do I do it?
StringTemplate["The derivative of `fun` with respect to `var` is `res` when `var` = `val`"]@<|"fun" -> ToString[f, TraditionalForm], "var" -> x, "val" -> 1, "res" -> ToString[D[f, x] /. x -> 1, TraditionalForm]|>
? $\endgroup$StringTemplate
, haven't used it before. But there is a problem,x=1
must be evaluated before evaluation ofprintRes
$\endgroup$"res"
in the association. $\endgroup$x
to be1
at the outset. $\endgroup$