On Tuesday, February 7, 2017 at 12:14:49 PM UTC, [email protected] wrote: > > > > On Saturday, February 4, 2017 at 4:46:38 PM UTC-6, Dima Pasechnik wrote: >> >> >> >> On Saturday, February 4, 2017 at 8:48:22 PM UTC, [email protected] >> wrote: >>> >>> I would like to know the right way to do in SAGE what I am currently >>> doing with Mathematica in these two examples (I actually know how to do the >>> first one in SAGE, but probably not in the best way): >>> 1) Finding the intersection of a generic tangent line to f(x) with f(x): >>> f[x_]:= x^2(x^2-1) >>> L[a_,x_]:=f[a]+f'[a](x-a) >>> Solve[L[a,x]==f[x],x] >>> Here the main issue for me is how use the derivative f'(x) without >>> having to define a new function g(x)=derivative(f(x)) >>> >> >> Are your f always polynomials? Sage can do much more with polynomials >> then with "generic" symbolic functions. >> (e.g. for intersecting plane curves an exact approach would be to compute >> the resultant, etc) >> >> Regarding your last question, certainly there is no need to define a new >> named function for everything, e.g. >> sage: f(x)=x^2 >> sage: f.diff(x) >> x |--> 2*x >> sage: f.diff(x)(5) >> 10 >> >> works >> > > f is not always a polynomial, but the above surely answers my question, > thank you > >> >> >>> >>> 2) Testing if |f(z)| < f(|z|) for various choices of f: >>> Pl[f_,r_]:=Plot[Abs[f[r Exp[I t]]]/f[r],{t,0,2Pi}] >>> Here I am mostly interested in how to write a command that uses a >>> function as a variable. >>> >> >> Sage has two different types of "functions": 1) native Python functions >> 2) symbolic functions; >> certainly both of these can be passed around as parameters. >> > > I have not been able to use f as a parameter. To use a simpler example, > what is the SAGE code corresponding to this Mathematica code: > f[x_]:=1+x+x^2 > g[x_]:=1+x+x^2+x^3 > Ex[f_]:=Expand[f[x]^2] > Ex[f] > > 1 + 2 x + 3 x^2 + 2 x^3 + x^4 > > Ex[g] > > 1 + 2 x + 3 x^2 + 4 x^3 + 3 x^4 + 2 x^5 + x^6 > > etc. > > > Sure it's easy, although you might have to learn a bit of Python :-)
sage: def Ex(g): # we define a Python function here ....: return expand(g^2) ....: sage: f(x)=(x+1)^2 sage: Ex(f) x |--> x^4 + 4*x^3 + 6*x^2 + 4*x + 1 -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
