Advertisement
heider

Scilab[ordered] Schur decomposition of matrix and pencils

Nov 17th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.37 KB | None | 0 0
  1. //SCHUR FORM OF A MATRIX
  2. //----------------------
  3. A=diag([-0.9,-2,2,0.9]);X=rand(A);A=inv(X)*A*X;
  4. [U,T]=schur(A);T
  5.  
  6. [U,dim,T]=schur(A,'c');
  7. T(1:dim,1:dim)      //stable cont. eigenvalues
  8.  
  9. function t=mytest(Ev),t=abs(Ev)<0.95,endfunction
  10. [U,dim,T]=schur(A,mytest);
  11. T(1:dim,1:dim)  
  12.  
  13. // The same function in C (a Compiler is required)
  14. cd TMPDIR;
  15. C=['int mytest(double *EvR, double *EvI) {' //the C code
  16.    'if (*EvR * *EvR + *EvI * *EvI < 0.9025) return 1;'
  17.    'else return 0; }';]
  18. mputl(C,TMPDIR+'/mytest.c')
  19.  
  20. //build and link
  21. lp=ilib_for_link('mytest','mytest.c',[],'c');
  22. link(lp,'mytest','c');
  23.  
  24. //run it
  25. [U,dim,T]=schur(A,'mytest');
  26. //SCHUR FORM OF A PENCIL
  27. //----------------------
  28. F=[-1,%s, 0,   1;
  29.     0,-1,5-%s, 0;
  30.     0, 0,2+%s, 0;
  31.     1, 0, 0, -2+%s];
  32. A=coeff(F,0);E=coeff(F,1);
  33. [As,Es,Q,Z]=schur(A,E);
  34. Q'*F*Z //It is As+%s*Es
  35.  
  36. [As,Es,Z,dim] = schur(A,E,'c')
  37. function t=mytest(Alpha, Beta),t=real(Alpha)<0,endfunction
  38. [As,Es,Z,dim] = schur(A,E,mytest)
  39.  
  40. //the same function in Fortran (a Compiler is required)
  41. ftn=['integer function mytestf(ar,ai,b)' //the fortran code
  42.      'double precision ar,ai,b'
  43.      'mytestf=0'
  44.      'if(ar.lt.0.0d0) mytestf=1'
  45.      'end']
  46. mputl('      '+ftn,TMPDIR+'/mytestf.f')
  47.  
  48. //build and link
  49. lp=ilib_for_link('mytestf','mytestf.f',[],'F');
  50. link(lp,'mytestf','f');
  51.  
  52. //run it
  53.  
  54. [As,Es,Z,dim] = schur(A,E,'mytestf')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement