ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 18 Mar 2013 15:21:42 -0500Newton's identities in Sagehttp://ask.sagemath.org/question/9847/newtons-identities-in-sage/**EDIT**
I actually need:
$s_k=[c_1s_{k-1}+...+c_{k-1}s_1-kc_k]$ ? could somebody help me to change tobias welch's answer so that it computes $s_k$ instead of $c_k$?
**END EDIT**
I'm combining netwon's identities with le verrier's algorithm
I need some help coding the following on python.
$c_k=\frac{-1}{k}(s_k+c_1s_{k-1}+c_2s_{k-2}+\dots+c_{k-1}s_1)$
where $s_k=Tr(A^k)$, for some square matrix A, $\forall k=1,2,3,\dots,n$
So, i'd like to type in $c(k)$ and python spits out the value for $c_k$ as defined above.
Mon, 25 Feb 2013 03:08:03 -0600http://ask.sagemath.org/question/9847/newtons-identities-in-sage/Answer by twch for <p><strong>EDIT</strong> <br/>
I actually need:
$s_k=[c_1s_{k-1}+...+c_{k-1}s_1-kc_k]$ ? could somebody help me to change tobias welch's answer so that it computes $s_k$ instead of $c_k$? <br/>
<strong>END EDIT</strong> </p>
<p>I'm combining netwon's identities with le verrier's algorithm </p>
<p>I need some help coding the following on python.</p>
<p>$c_k=\frac{-1}{k}(s_k+c_1s_{k-1}+c_2s_{k-2}+\dots+c_{k-1}s_1)$ <br/>
where $s_k=Tr(A^k)$, for some square matrix A, $\forall k=1,2,3,\dots,n$ </p>
<p>So, i'd like to type in $c(k)$ and python spits out the value for $c_k$ as defined above. </p>
http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?answer=14599#post-id-14599An 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
Mon, 25 Feb 2013 21:06:44 -0600http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?answer=14599#post-id-14599Comment by ppurka for <p>An recursive algorithm would be quite inefficient for this problem as yout would have to recalculate all c_k coefficients in each step.</p>
<p>The following few lines should work for your problem (if I hopefully didn't make any mistakes with the formulas):</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18049#post-id-18049You should consider learning some programming. It will save you a lot of time.Mon, 18 Mar 2013 15:21:42 -0500http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18049#post-id-18049Comment by jtaa for <p>An recursive algorithm would be quite inefficient for this problem as yout would have to recalculate all c_k coefficients in each step.</p>
<p>The following few lines should work for your problem (if I hopefully didn't make any mistakes with the formulas):</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18157#post-id-18157it worked thanks!Mon, 25 Feb 2013 22:51:33 -0600http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18157#post-id-18157Comment by jtaa for <p>An recursive algorithm would be quite inefficient for this problem as yout would have to recalculate all c_k coefficients in each step.</p>
<p>The following few lines should work for your problem (if I hopefully didn't make any mistakes with the formulas):</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18054#post-id-18054what if i wanted a new formula for s_k=[c_1s_{k-1}+...+c_{k-1}s_1-kc_k] ?Sun, 17 Mar 2013 15:54:19 -0500http://ask.sagemath.org/question/9847/newtons-identities-in-sage/?comment=18054#post-id-18054