ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 02 Dec 2017 04:16:35 -0600can series make mistakes?http://ask.sagemath.org/question/39909/can-series-make-mistakes/ series seems to make errors . luckily, taylor works correctly.
start with L_F=(exp(-s)-1+s)/(s^2/2) (laplace transform of the "equilibrium" uniform density)
and switch to Pollaczek laplace transform L_F /(1- epsilon * L_F);
You can check that the moments expansions t, t1 differ
var('s');n=2
L_F=(exp(-s)-1+s)/(s^2/2) #satisfies L_F(s=0)=1
L_L=L_F/(1-L_F/3)
t = L_L.series(s,2*n+2)
t1= taylor(L_L,s,0,2*n+2)
print t1florinSat, 02 Dec 2017 04:16:35 -0600http://ask.sagemath.org/question/39909/Taylor Series With Order (Big O)http://ask.sagemath.org/question/36665/taylor-series-with-order-big-o/ I'm trying to replicate some Mathematica code, and I know very little about Mathematica and Sage.
The Mathematica code creates a Taylor series for f(x) about (x0), with degree 5. I was able to replicate that.
x, x0, dt = var('x, x0, dt')
f = function('f')
t = f(x).taylor(x, x0, 5)
Next it does a substitution.
k1 = f(x0)*dt
s = x0 + k1/2
k2 = t.subs(x=s)
The problem is it that it then removes the higher order terms using the big O notation.
k2 = Expand[g[x] \[CapitalDelta]t /. x -> s] + O[\[CapitalDelta]t]^5
It looks like this is available for series and polynomial rings (no clue what those are) in SageMath, but I haven't figured out how to apply it to the Taylor series expansion.
Is there a way to truncate certain order terms off of an expression?
Is there a way to replicate the Taylor series expression I want with `.series()` or polynomial rings?
I tried importing `sage.rings.big_oh` and using `Order()` but neither seemed applicable to the expression I had. I also made half an attempt to recreate a Taylor series with `.series()` but didn't quite get what I was hoping for.
tq = 1/factorial(n)*f(x)*x^n
tq.series(n, 5)
Thanks for the help, both my math and SageMath skills are lacking.douggardSun, 19 Feb 2017 16:56:02 -0600http://ask.sagemath.org/question/36665/Multivariable taylor series with relationship between variableshttp://ask.sagemath.org/question/23821/multivariable-taylor-series-with-relationship-between-variables/ Let's consider a function `f(x,y,z)` and the following relationship between the variables:
f(x,y,z) = x+y+z
x << y << z around 0
I would like the first order Taylor expansion of f around 0. And I would expect this result:
>> taylor(f, (x,0),(y,0),(z,0),1)
z
But I have :
>> taylor(f, (x,0),(y,0),(z,0),1)
x+y+z
How can I do it?rufus_wilsonMon, 18 Aug 2014 15:15:57 -0500http://ask.sagemath.org/question/23821/Question about sum and diffhttp://ask.sagemath.org/question/25750/question-about-sum-and-diff/Why this code :
f(x)=sum(diff(sin(x),x,n),n,1,10)
f(x)
does not work?DesruimFri, 06 Feb 2015 11:57:46 -0600http://ask.sagemath.org/question/25750/How to convert a Taylor polynomial to a power series?http://ask.sagemath.org/question/24777/how-to-convert-a-taylor-polynomial-to-a-power-series/With Maple I can write
g := 2/(1+x+sqrt((1+x)*(1-3*x)));
t := taylor(g,x=0,6);
coeffs(convert(t,polynom));
end get
1, 1, 1, 3, 6
Trying to do the same with Sage I tried
var('x')
g = 2/(1+x+sqrt((1+x)*(1-3*x)))
taylor(g, x, 0, n)
and get
NotImplementedError
Wrong arguments passed to taylor. See taylor? for more details.
I could not find the details I am missing by typing 'taylor?'. Then I tried
g = 2/(1+x+sqrt((1+x)*(1-3*x)))
def T(g, n): return taylor(g, x, 0, n)
T(g, 5)
and got
6*x^5 + 3*x^4 + x^3 + x^2 + O(0) + 1
which is almost what I want (although I fail to understand this 'workaround').
But when I tried next to convert this Taylor polynomial to a power series
g = 2/(1+x+sqrt((1+x)*(1-3*x)))
def T(g, n): return taylor(g, x, 0, n)
w = T(g, 5)
R.<x> = QQ[[]]
R(w).polynomial().padded_list(5)
I got the error
TypeError: unable to convert O(0) to a rational
The question: *How can I convert the Taylor polynomial of 2/(1+x+sqrt((1+x)(1-3x))) to a power series and then extract the coefficients?*
*Solution ??*: With the help of the answer of calc314 below (but note that I am not using 'series') the best solution so far seems to be:
var('x')
n = 5
g = 2/(1+x+sqrt((1+x)*(1-3*x)))
p = taylor(g, x, 0, n).truncate()
print p, p.parent()
x = PowerSeriesRing(QQ,'x').gen()
R.<x> = QQ[[]]
P = R(p)
print P, P.parent()
P.padded_list(n)
which gives
6*x^5 + 3*x^4 + x^3 + x^2 + 1 Symbolic Ring
1 + x^2 + x^3 + 3*x^4 + 6*x^5 Power Series Ring in x over Rational Field
[1, 0, 1, 1, 3]
Two minutes later I wanted to wrap things in a function, making 'n' and 'g' parameters.
def GF(g, n):
x = SR.var('x')
p = taylor(g, x, 0, n).truncate()
print p, p.parent()
x = PowerSeriesRing(QQ,'x').gen()
R.<x> = QQ[[]]
P = R(p)
print P, P.parent()
return P.padded_list(n)
Now what do you think
gf = 2/(1+x+sqrt((1+x)*(1-3*x)))
print GF(gf, 5)
gives?
TypeError: unable to convert O(x^20) to a rational
*Round 3, but only small progress:*
tmonteil writes in his answer below: "the lines x = SR.var('x') and x = PowerSeriesRing(QQ,'x').gen() have no effect on the rest of the computation, and could be safely removed".
This does not work for me: if I do not keep the line x = SR.var('x') I get "UnboundLocalError: local variable 'x' referenced before assignment". But the line "x = PowerSeriesRing(QQ,'x').gen()" can be skipped. So I have now
def GF(g, n):
x = SR.var('x')
p = taylor(g, x, 0, n).truncate()
print p, p.parent()
R.<x> = QQ[[]]
P = R(p)
print P, P.parent()
return P.padded_list()
n = 7
gf = 2/(1+x+sqrt((1+x)*(1-3*x)))
print GF(gf, n)
If I open a fresh Sage session, I have, like tmontile, no problem. However I cannot always
open a fresh Sage session when I want to execute GF(gf, n). Therefore consider
n = 7
gf = 2/(1+x+sqrt((1+x)*(1-3*x)))
print GF(gf, n)
p = taylor(gf, x, 0, n).truncate()
print p, p.parent()
R.<x> = QQ[[]]
P = R(p)
print P, P.parent()
P.padded_list()
print GF(gf, n)
If I open a fresh Sage session this will run OK. But when this piece of code is rerun
my old friend will reappear:
"TypeError: unable to convert O(x^20) to a rational"
Peter LuschnyTue, 04 Nov 2014 06:09:26 -0600http://ask.sagemath.org/question/24777/taylor expansion with arbritary precision numbershttp://ask.sagemath.org/question/23370/taylor-expansion-with-arbritary-precision-numbers/Hi,
if I define a function with arbritary precision numbers (e.g., f=0.123456789123456789*log(1+x)) and then compute its Taylor expansion (f.taylor(x,0,5)) it seems to me that the coefficients are given in double precision, whereas if I compute them (e.g., by derivative(f,x,5)(x=0)/factorial(5)) they are in original precision. First of all, am I right or is it only a visualisation difference? If I'm right, is it possible to compute the Taylor expansion with the original precision?
Cheers,
MarcoMarco CaliariFri, 11 Jul 2014 01:58:26 -0500http://ask.sagemath.org/question/23370/taylor(1/x^2,x,2,2) give unexpected resultshttp://ask.sagemath.org/question/10958/taylor1x2x22-give-unexpected-results/
When I calculated this by hand, the constant term is 1/4 but sage gives 3/4.
Sage:
$$\newcommand{\Bold}[1]{\mathbf{#1}}\frac{3}{16} {\left(x - 2\right)}^{2} - \frac{1}{4} x + \frac{3}{4}$$
My calculation:
$$\frac{1}{4} -\frac{1}{4}(x-2)+\frac{3}{16}(x-2)^2$$
I'm learning taylor series and sage at the same time, so its quite possible I'm misusing sage. I checked the same thing on wolframalpha, and it agrees with me.
Any ideas? I running sage Sage Version 6.0,Release Date: 2013-12-17 under Ubuntu 12.10. Thanks.
AndyHFri, 24 Jan 2014 07:41:05 -0600http://ask.sagemath.org/question/10958/multivariable taylor serieshttp://ask.sagemath.org/question/10668/multivariable-taylor-series/I know how to generate a multivairiable Taylor series and extract its coefficients. What I want to do is to extract all the terms where the exponents of the individual variables satisfy certain requirements.
So for instance, my function is
f(x,y)=(1/(1-x*y))*(1/(1-x*y^2))*(1/(1-x*y^3))*(1-x*y^4))
What I want is all terms in the Taylor series such that the exponent on x is at most 10 and the exponent on y is at most 20. Ideas?ClemFanJC07Mon, 28 Oct 2013 05:01:27 -0500http://ask.sagemath.org/question/10668/Maclaurin and taylor serieshttp://ask.sagemath.org/question/10329/maclaurin-and-taylor-series/I need to write a function that returns a list of Maclaurin coefficients for f(x) up to and including degree d. I have to use the taylor and coefficient commands in sage.kimncole1Sun, 07 Jul 2013 15:59:46 -0500http://ask.sagemath.org/question/10329/TypeError: FIXNUM.http://ask.sagemath.org/question/10058/typeerror-fixnum/Hi everyone,
I am using function taylor() in sage to find the Taylor series of a function as follows:
var ('x')
fx = e^(-(1/632936348449528153)*(x))
taylor(fx,x,1,2)
it gives me the correct answer. But when the the denominator in the exponent (i.e. the denominator of 1/632936348449528153) is increased further by one digit (say 9) I receive the following error message
TypeError: ECL says: 6329363484495281539 is not of type FIXNUM.
My actual function is like
a=e^(-(1/632936348449528153937412733512609636)*(x1))
But when I use the above function again in taylor(), I get the error as shown below.
TypeError: ECL says: 632936348449528153937412733512609636 is not of type FIXNUM.
Is there any solution to overcome this error????
Note: I am using sage in the Sage Notebook online in a browser.
assadabbasiTue, 23 Apr 2013 16:31:26 -0500http://ask.sagemath.org/question/10058/Multivariate Taylor Serieshttp://ask.sagemath.org/question/9783/multivariate-taylor-series/Hi. I know `f.taylor(x, x_0, n)` would generate an n-order Taylor approximation of f around x_0 for a function of a single variable. How can I do this for multiple variables? I know Maxima can handle it. How do I do this in sage?yktulaThu, 07 Feb 2013 11:13:48 -0600http://ask.sagemath.org/question/9783/Restrict taylor() to only find genuine Taylor serieshttp://ask.sagemath.org/question/9415/restrict-taylor-to-only-find-genuine-taylor-series/In Maple, the Taylor series command produces an error if the expression does not have a Taylor series, such as `1/x` around `x = 0`. Is it possible to achieve the same effect in Sage? I have some rather long expressions, and it's not always immediately obvious whether there are some singular terms hidden in the result of `.taylor()`.
Doubtless LeeSun, 28 Oct 2012 11:22:29 -0500http://ask.sagemath.org/question/9415/Taylor expansion twice for a general function cause problem?http://ask.sagemath.org/question/8568/taylor-expansion-twice-for-a-general-function-cause-problem/Hi,
I met a problem when expanding a general function twice:
y = var('y')
f = function('f',var('x'))
g = f(x=var('eps')*y)
h = taylor(g, eps, 0, 1)
taylor(h, eps, 0, 1)
The last expression ends up with an error: NotImplementedError: arguments must be distinct variables
Is it a bug or I got anything wrong? Thanks!
tririverFri, 16 Dec 2011 08:13:28 -0600http://ask.sagemath.org/question/8568/