source: git/kernel/eigenval.cc @ 854405

spielwiese
Last change on this file since 854405 was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id$ */
5/*
6* ABSTRACT: eigenvalues of constant square matrices
7*/
8
9#include "config.h"
10#include <kernel/mod2.h>
11
12#ifdef HAVE_EIGENVAL
13
14#include <kernel/febase.h>
15#include <kernel/structs.h>
16//#include "ipid.h"
17#include <misc/intvec.h>
18#include <coeffs/numbers.h>
19#include <kernel/polys.h>
20#include <kernel/ideals.h>
21//#include "lists.h"
22#include <polys/matpol.h>
23#include <polys/clapsing.h>
24#include <kernel/eigenval.h>
25
26
27matrix evSwap(matrix M,int i,int j)
28{
29  if(i==j)
30    return(M);
31
32  for(int k=1;k<=MATROWS(M);k++)
33  {
34    poly p=MATELEM(M,i,k);
35    MATELEM(M,i,k)=MATELEM(M,j,k);
36    MATELEM(M,j,k)=p;
37  }
38
39  for(int k=1;k<=MATCOLS(M);k++)
40  {
41    poly p=MATELEM(M,k,i);
42    MATELEM(M,k,i)=MATELEM(M,k,j);
43    MATELEM(M,k,j)=p;
44  }
45
46  return(M);
47}
48
49matrix evRowElim(matrix M,int i,int j,int k)
50{
51  if(MATELEM(M,i,k)==NULL||MATELEM(M,j,k)==NULL)
52    return(M);
53
54  poly p=pNSet(nDiv(pGetCoeff(MATELEM(M,i,k)),pGetCoeff(MATELEM(M,j,k))));
55  pNormalize(p);
56
57  for(int l=1;l<=MATCOLS(M);l++)
58  {
59    MATELEM(M,i,l)=pSub(MATELEM(M,i,l),ppMult_qq(p,MATELEM(M,j,l)));
60    pNormalize(MATELEM(M,i,l));
61  }
62  for(int l=1;l<=MATROWS(M);l++)
63  {
64    MATELEM(M,l,j)=pAdd(MATELEM(M,l,j),ppMult_qq(p,MATELEM(M,l,i)));
65    pNormalize(MATELEM(M,l,j));
66  }
67
68  pDelete(&p);
69
70  return(M);
71}
72
73matrix evColElim(matrix M,int i,int j,int k)
74{
75  if(MATELEM(M,k,i)==0||MATELEM(M,k,j)==0)
76    return(M);
77
78  poly p=pNSet(nDiv(pGetCoeff(MATELEM(M,k,i)),pGetCoeff(MATELEM(M,k,j))));
79  pNormalize(p);
80
81  for(int l=1;l<=MATROWS(M);l++)
82  {
83    MATELEM(M,l,i)=pSub(MATELEM(M,l,i),ppMult_qq(p,MATELEM(M,l,j)));
84    pNormalize(MATELEM(M,l,i));
85  }
86  for(int l=1;l<=MATCOLS(M);l++)
87  {
88    MATELEM(M,j,l)=pAdd(MATELEM(M,j,l),ppMult_qq(p,MATELEM(M,i,l)));
89    pNormalize(MATELEM(M,j,l));
90  }
91
92  pDelete(&p);
93
94  return(M);
95}
96
97matrix evHessenberg(matrix M)
98{
99  int n=MATROWS(M);
100  if(n!=MATCOLS(M))
101    return(M);
102
103  for(int k=1,j=2;k<n-1;k++,j=k+1)
104  {
105    while(j<=n&&MATELEM(M,j,k)==0)
106      j++;
107
108    if(j<=n)
109    {
110      M=evSwap(M,j,k+1);
111
112      for(int i=j+1;i<=n;i++)
113        M=evRowElim(M,i,k+1,k);
114    }
115  }
116
117  return(M);
118}
119
120#endif /* HAVE_EIGENVAL */
Note: See TracBrowser for help on using the repository browser.