Ask Your Question

Problem using Taylor several times

asked 2020-04-03 12:57:45 +0200

LBLB gravatar image

updated 2020-04-03 19:08:26 +0200

FrédéricC gravatar image

I have a sage worksheet using small functions such as

def vMatrix(M):
    for i in [0..1]: 
        for j in [0..1]:
    return Matrix(2,Lmat)

At the beginning, it works perfectly (computing approximations of matrices with parameters) but after using it several times, it stops computing the Taylor expansion of the coefficients, and simply returns the matrix.

I'm getting crazy with that :(

Does someone has an idea on what's happening?

Thx Leo

edit retag flag offensive close merge delete


Please give an example of what you don't understand. If the matrix does not contain any y then nothing happens...

rburing gravatar imagerburing ( 2020-04-03 15:42:30 +0200 )edit

Why? I wish it gives a Taylor expansion in any case.

LBLB gravatar imageLBLB ( 2020-04-03 15:55:43 +0200 )edit

For example, first it gave the correct result, and now: Applying the function vMatrix to the following matrix: [ (m^3 + my - m)/(m^2 - 1) -(m^4 + m^2y - 2m^2 + 1)/(m^5 - 2m^3 + m)] [ my -(m^2y - m^2 + 1)/(m^3 - m)]

It gives: [ -m^5/(m^2 - 1) (m^6 + m^2 - 1)/(m^5 - 2*m^3 + m)] [ -m^5 - m^3 + m (m^6 + m^4 - 1)/(m^3 - m)] which is just the result of the substitution.

LBLB gravatar imageLBLB ( 2020-04-03 16:01:35 +0200 )edit

Sorry, I was wrong, it should do the expansion. When I try it with that first matrix in SageMath 9.0, it does do the expansion. What version are you using? Please add a complete example to your post.

rburing gravatar imagerburing ( 2020-04-03 16:17:34 +0200 )edit

I'm using 8.0 The problem is that the false result does not occurs directly. If I run the function, it gives me the expansion as well. But after running more cells, then it starts to mess up completely. In fact I see where the problem comes from: the matrices are defined over "Symbolic Ring" (with formal variable m and y) Then I run a function that uses matrices with some other variables (and after that it starts to mess up). At some point, my guess is that Sage doesn't know anymore that my matrices coeffs are functions of m, and so the taylor command is kind of empty for him. Any idea how to fix that?

LBLB gravatar imageLBLB ( 2020-04-03 16:34:25 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-04-06 13:04:39 +0200

rburing gravatar image

The function is fine as long as the external variables y and m are defined in the way you expect (as var('y') and var('m') respectively). To ensure that a function works consistently (equal inputs always resulting in equal outputs), it should not depend on external variables. So you can modify the function to use var('y') and var('m') directly, or change the definition to accept y and m as parameters (and making sure to always pass in the correct ones).

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


Asked: 2020-04-03 12:57:45 +0200

Seen: 97 times

Last updated: Apr 06 '20