Ask Your Question
0

Taylor expansion does not work

asked 2025-12-05 10:56:58 +0200

Itzui gravatar image

updated 2026-04-09 01:19:46 +0200

dan_fulea gravatar image

I started with Sagemath and wanted to use it in order to get the Taylor Series of a function. However, a quick check shows that the coefficients are not correct. If I use series() instead of taylor(), then the output looks okay.

Did I make something wrong? Does Sagemath have some problems as the function contains several variables?

Here is a minimal example which reproduce the problem:

reset()
var('exx eyy x kx')

p1 = kz_s = sqrt(eyy - kx^2)
p2 = sqrt(1 - kx^2)

rs = (p1 - p2) / (p1 + p2)
rs = rs(eyy = exx + x)
rs = rs.subs(eyy = exx + x) 

ser = rs.taylor(x, 0, 1)

p1 = plot(rs(exx = 4, x = 0.0) , (x, 0, .2), color='red' ) 
p2 = plot(ser(exx = 4, x = 0.0) , (x, 0, .2) )
show(p1 + p2)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2026-04-09 01:17:52 +0200

dan_fulea gravatar image

Consider the first plot line,

p1 = plot(rs(exx = 4, x = 0.0) , (x, 0, .2), color='red' )

And let us see what we are plotting here:

sage: rs(exx = 4, x = 0.0)
(sqrt(-kx^2 + 4) - sqrt(-kx^2 + 1))/(sqrt(-kx^2 + 4) + sqrt(-kx^2 + 1))

Above, kx is a variable, there is no meaning for plotting the above expression for $x$ (which no longer appears, it was silenced to zero, but) running from $0$ to $0.2$.

We have even less chances to plot something for the same $x$-interval for the ser-plot:

sage: ser(exx = 4, x = 0.0)
-(-I*sqrt(kx^2 - 4) + sqrt(-kx^2 + 1))/(I*sqrt(kx^2 - 4) + sqrt(-kx^2 + 1))

Here we can push the $I=\sqrt{-1}$ inside the radicals and compare, getting the same expression from an algebraic point of view.

But why do we plot these expressions?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-12-05 10:56:58 +0200

Seen: 270 times

Last updated: Apr 09