Ask Your Question
1

Problem using Taylor several times

asked 2020-04-03 05:57:45 -0500

LBLB gravatar image

updated 2020-04-03 12:08:26 -0500

FrédéricC gravatar image

I have a sage worksheet using small functions such as

def vMatrix(M):
    Lmat=[]
    for i in [0..1]: 
        for j in [0..1]:
            Lmat.append(M.subs(y==1-m^2-m^4)[i,j].taylor(m,0,4))
    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

Comments

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 08:42:30 -0500 )edit

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

LBLB gravatar imageLBLB ( 2020-04-03 08:55:43 -0500 )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 09:01:35 -0500 )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 09:17:34 -0500 )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 09:34:25 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2020-04-06 06:04:39 -0500

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

Stats

Asked: 2020-04-03 05:57:45 -0500

Seen: 90 times

Last updated: Apr 06