~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/percent/%choose.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [flag]=%choose(x)
 
2
// Utility function for use with schur
 
3
//     [U,dim]=schur(A,choose) returns orth. basis
 
4
//     for eigenspace associated to selected polynomials
 
5
//Needs two global variables : 
 
6
//     %sel = list of selected polynomials (user defined)
 
7
//     eps = threshold for polynomials selection (eps= 0.0001 as default value)
 
8
//            see below 
 
9
//     Example:
 
10
//     A=...
 
11
//     chis=poly(A,'s');  //Characteristic polynomial
 
12
//     w=factors(chis);    //Factors of chis in a list
 
13
//     %sel=list(w(2),w(3)); // two selected polynomials
 
14
//     eps=0.01;     //Threshold (see almosteq below)
 
15
//     [U,dim]=schur(A,%choose);     //Ordered Schur form
 
16
//     U1=U(:,1:dim);chi1=poly(U1'*A*U1,'s')  //Check
 
17
//     w1=factors(chi1)          // w1 = %sel ?
 
18
//
 
19
// Copyright INRIA
 
20
eps=0.0001;         //modify eps here !
 
21
// 
 
22
ls=x(1);flag=0;s=poly(0,'s');
 
23
select ls
 
24
case 1 then
 
25
  // ASSUME x(3) NOT ZERO   (for gev pb. x(3)=0 => eval @ infty)
 
26
  vp=x(2)/x(3);pol=s-vp; //disp(pol);
 
27
  for p=%sel; if almosteq(pol,p,eps) then flag=1;end;end
 
28
case 2 then
 
29
  pol=s^2-x(2)*s+x(3);  //disp(pol);
 
30
  for p=%sel; if almosteq(pol,p,eps) then flag=1;end;end   
 
31
end
 
32
 
 
33
function trfa=almosteq(pol,p,eps)
 
34
// returns %T if pol ~ p     %F if not
 
35
if degree(pol)<>degree(p) then trfa=%F;return;end
 
36
if norm((coeff(p)-coeff(pol)),1)<=eps then trfa=%T;return;end
 
37
trfa=%F;
 
38
 
 
39