Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SCHUR FORM OF A MATRIX
- //----------------------
- A=diag([-0.9,-2,2,0.9]);X=rand(A);A=inv(X)*A*X;
- [U,T]=schur(A);T
- [U,dim,T]=schur(A,'c');
- T(1:dim,1:dim) //stable cont. eigenvalues
- function t=mytest(Ev),t=abs(Ev)<0.95,endfunction
- [U,dim,T]=schur(A,mytest);
- T(1:dim,1:dim)
- // The same function in C (a Compiler is required)
- cd TMPDIR;
- C=['int mytest(double *EvR, double *EvI) {' //the C code
- 'if (*EvR * *EvR + *EvI * *EvI < 0.9025) return 1;'
- 'else return 0; }';]
- mputl(C,TMPDIR+'/mytest.c')
- //build and link
- lp=ilib_for_link('mytest','mytest.c',[],'c');
- link(lp,'mytest','c');
- //run it
- [U,dim,T]=schur(A,'mytest');
- //SCHUR FORM OF A PENCIL
- //----------------------
- F=[-1,%s, 0, 1;
- 0,-1,5-%s, 0;
- 0, 0,2+%s, 0;
- 1, 0, 0, -2+%s];
- A=coeff(F,0);E=coeff(F,1);
- [As,Es,Q,Z]=schur(A,E);
- Q'*F*Z //It is As+%s*Es
- [As,Es,Z,dim] = schur(A,E,'c')
- function t=mytest(Alpha, Beta),t=real(Alpha)<0,endfunction
- [As,Es,Z,dim] = schur(A,E,mytest)
- //the same function in Fortran (a Compiler is required)
- ftn=['integer function mytestf(ar,ai,b)' //the fortran code
- 'double precision ar,ai,b'
- 'mytestf=0'
- 'if(ar.lt.0.0d0) mytestf=1'
- 'end']
- mputl(' '+ftn,TMPDIR+'/mytestf.f')
- //build and link
- lp=ilib_for_link('mytestf','mytestf.f',[],'F');
- link(lp,'mytestf','f');
- //run it
- [As,Es,Z,dim] = schur(A,E,'mytestf')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement