# NO WARRANTY
precision_digits=30
nop=5 # rank of matrix
MS_nop_comp=MatrixSpace(ComplexField(precision_digits),nop,nop)
tmat=MS_nop_comp(0) # zero-ize the values
ttdag=MS_nop_comp(0)
for a in range(nop):
  for b in range(nop):
    tmat[a,b]=random()+I*random()
ttdag=tmat*tmat.conjugate().transpose()
m=gp(ttdag)
ev=gp.mateigen(m).sage()
print ev[:-1]

On 30 Mar, 22:34, Ben123 <ben.is.loca...@gmail.com> wrote:
> Hello. Thank you for showing me the equivalent process in PARI/GP. I
> think this implies I need to transfer the complex Hermitian matrix
> into gp_console() to find eigenvectors, then transfer them back to
> Sage. I'll update this post when I figure out how to do that.
>
> In the mean time, if someone has a simple way of doing that please let
> me know. My updated Sage code lacks the last step.
>
> precision_digits=30
> nop=5 # rank of matrix
> MS_nop_comp=MatrixSpace(ComplexField(precision_digits),nop,nop)
> tmat=MS_nop_comp(0) # zero-ize the values
> ttdag=MS_nop_comp(0)
> for a in range(nop):
>   for b in range(nop):
>     tmat[a,b]=random()+I*random()
> ttdag=tmat*tmat.conjugate().transpose() # get a Hermitian matrix
> # Find eigenvectors of ttdag in PARI/GP, pass results back to sage
>
> Thanks for the help,
>
> On Mar 30, 2:45 pm, achrzesz <achrz...@wp.pl> wrote:
>
> > sage: gp_console()
> > ?  \p 100
> >    realprecision = 115 significant digits (100 digits displayed)
> > ? a=matrix(3,3,k,m,random(1.0))+I*matrix(3,3,k,m,random(1.0));
> > ?  m=a*conj(a)~;
> > ?  mateigen(m)
>
> > On 30 Mar, 18:20, Jason Grout <jason-s...@creativetrax.com> wrote:
>
> > > On 3/30/11 10:44 AM, Ben123 wrote:
>
> > > > Hello. I've written a sage program which produces a complex matrix. I
> > > > want to find the eigenvalues and associated eigenvectors. I also want
> > > > to use arbitrary precision. I don't care about speed. I've read old
> > > > posts to this group on this topic, but am unsure how to proceed.
> > > > Currently I'm using the following method and using sage 4.6.1
>
> > > > precision_digits=30
> > > > nop=5 # rank of matrix
> > > > MS_nop_comp=MatrixSpace(ComplexField(precision_digits),nop,nop)
> > > > tmat=MS_nop_comp(0) # zero-ize the values
> > > > ttdag=MS_nop_comp(0)
>
> > > > # I realize there are more efficient methods of getting a random
> > > > matrix, but this is explicit
> > > > for a in range(nop):
> > > >    for b in range(nop):
> > > >      tmat[a,b]=random()+I*random()
>
> > > > ttdag=tmat*tmat.conjugate().transpose() # get a Hermitian matrix
> > > > print 'ttdag is'
> > > > print ttdag
> > > > print 'eigenvalues of ttdag are '
> > > > print ttdag.eigenvalues() # eigenvalues of Hermitian matrix should be
> > > > real. Imaginary component is due to finite precision.
> > > > # I can get better precision here by increasing precision_digits
>
> > > > #print ttdag.eigenmatrix_right()
> > > > # IndexError: list index out of range
>
> > > > print ttdag.eigenvectors_right()
> > > > # this is not returning the eigenvectors, even when precision is
> > > > increased to 500
>
> > > > How can I find the eigenvectors of a complex Hermitian matrix with
> > > > arbitrary precision?
>
> > > One option: you might look at using the alglib library; at one time, the
> > > author was writing a Sage interface, but that work has stalled for
> > > several months.  Alglib appears to have a python interface, though.
>
> > > Alglib:http://www.alglib.net/
>
> > > Rob Beezer's been doing some work on the numerical linear algebra in
> > > Sage, so he also might have something to add...
>
> > > Thanks,
>
> > > Jason
>
>

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to