Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Newton's identities in Sage

asked 12 years ago

jtaa gravatar image

updated 12 years ago

EDIT
I actually need: sk=[c1sk1+...+ck1s1kck] ? could somebody help me to change tobias welch's answer so that it computes sk instead of ck?
END EDIT

I'm combining netwon's identities with le verrier's algorithm

I need some help coding the following on python.

ck=1k(sk+c1sk1+c2sk2++ck1s1)
where sk=Tr(Ak), for some square matrix A, k=1,2,3,,n

So, i'd like to type in c(k) and python spits out the value for ck as defined above.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

twch gravatar image

An recursive algorithm would be quite inefficient for this problem as yout would have to recalculate all c_k coefficients in each step.

The following few lines should work for your problem (if I hopefully didn't make any mistakes with the formulas):

def c(k,A):
    c_arr=[-A.trace()]
    for j in range(k-1):
        c_arr=c_incr(c_arr,A)
        print c_arr
    return c_arr[k-1]

def c_incr(c_arr, A):
    k=len(c_arr)+1
    c_new=(A^k).trace()
    for c_k in c_arr:
        k-=1
        c_new+=c_k*(A^k).trace()
    c_new=-1/(len(c_arr)+1)*c_new
    c_arr.append(c_new)
    return c_arr
Preview: (hide)
link

Comments

it worked thanks!

jtaa gravatar imagejtaa ( 12 years ago )

what if i wanted a new formula for s_k=[c_1s_{k-1}+...+c_{k-1}s_1-kc_k] ?

jtaa gravatar imagejtaa ( 12 years ago )
2

You should consider learning some programming. It will save you a lot of time.

ppurka gravatar imageppurka ( 12 years ago )

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: 12 years ago

Seen: 719 times

Last updated: Mar 17 '13