On Monday, December 26, 2016 at 2:55:16 AM UTC-8, Ingo Dahn wrote: > > Hi, > the following code works in SageCell if I remove the argument of the > anonymous function and uncomment line 3. > > @interact > def _(f=('$f$',x^2)): > # f(x)=x^2 > x0=1 > def tangent(g,z): > return derivative(g,x)(z)*(x-z)+g(z) > pf=plot(f,-5,5) > t=tangent(g=f,z=x0) > pt=plot(t,-5,5) > show(pf+pt) > > But in this form I get the deprecation warning > > sagemathcell.py:8: DeprecationWarning: Substitution using function-call > syntax and unnamed arguments is deprecated and will be removed from a future > release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) > See http://trac.sagemath.org/5930 for details. > t=tangent(g=f,z=x0) > > > None of my experiments after reading related posts helped. > > Any hints? > > Ingo > > The input parameter as set by f=('$f',x^2) makes f the *expression* x^2. When
t=tangent(g=f,z=x0) gets executed, you end up evaluating f(1) and derivative(f,x)(1), which trigger the warning. You could avoid this by sticking with expressions all the way and using "named" substitution instead of the deprecated evaluation syntax: def tangent(g,z): return derivative(g,x)(x=z)*(x-z)+g(x=z) Note that no generality is lost, since you're hardcoding the name with respect to which you take the derivative anyway. For your purposes, this is probably the easiest solution: just don't use "functions" and stick with "expressions". Alternatively, you can turn "f" into a properly defined one argument function: def _(f_in=('$f$',x^2)): f=f_in(x) ... and then your original works properly. The specification of your "tangent" function gets a bit funny then, though: its input parameter "g" should be a one argument function, and the argument should be "x". Writing a "tangent" function that takes as input a one argument function and returns the corresponding tangent line as a one argument function is a little more work, but can be done too: from sage.symbolic.operators import FDerivativeOperator def tangent(g,z): der_g=FDerivativeOperator(g,[0]) T=der_g(z)*(x-z)+g(z) return T.function(x) @interact def _(f_in=('$f$',x^2)): f=f_in.function(x) x0=1 pf=plot(f,-5,5) t=tangent(g=f,z=x0) pt=plot(t,-5,5,color="red") show(pf+pt) -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.