Bug 3643 fixed, mtlb_eig is now obsolete
[scilab.git] / scilab / modules / m2sci / macros / sci_files / sci_eig.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2002-2004 - INRIA - Vincent COUVERT 
3 // 
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at    
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function [tree]=sci_eig(tree)
11 // M2SCI function
12 // Conversion function for Matlab eig()
13 // Input: tree = Matlab funcall tree
14 // Ouput: tree = Scilab equivalent for tree
15
16 // eig(A)
17 if rhs==1 then
18   // Because %c_spec and %b_spec are not defined
19   A = getrhs(tree)
20   A = convert2double(A)
21   tree.rhs=Rhs_tlist(A)
22
23   tree.name="spec"
24   
25   // d = eig(A)
26   if lhs==1 then
27     tree.lhs(1).dims=list(A.dims(1),1)
28     tree.lhs(1).type=Type(Double,Unknown)
29   // [V,D] = eig(A)
30   else
31     tree.lhs(1).dims=list(A.dims(1),A.dims(1))
32     tree.lhs(1).type=Type(Double,Unknown)
33     tree.lhs(2).dims=list(A.dims(1),A.dims(1))
34     tree.lhs(2).type=Type(Double,Unknown)
35   end
36 // eig(A,B) or eig(A,'nobalance')
37 elseif rhs==2 then
38   [A,B] = getrhs(tree)
39   
40   // 'nobalance'
41   if B.vtype==String then
42     no_equiv(gettext("''nobalance'' option, IGNORED."))
43     tree.rhs=Rhs_tlist(tree.rhs(1))
44     if lhs==1 then
45       tree.name="spec"
46       tree.lhs(1).dims=list(A.dims(1),1)
47       tree.lhs(1).type=Type(Double,Unknown)
48     else
49       tree.rhs(1)=Operation("+",list(tree.rhs(1),Variable("%i",Infer()),list()))
50       rhs2=Operation("+",list(Cste(1),Variable("%eps",Infer()),list()))
51       tree.rhs=Rhs_tlist(tree.rhs(1),rhs2)
52       tree.name="bdiag"
53       tree.lhs(1).dims=list(A.dims(1),A.dims(1))
54       tree.lhs(1).type=Type(Double,Unknown)
55       tree.lhs(2).dims=list(A.dims(1),A.dims(1))
56       tree.lhs(2).type=Type(Double,Unknown)
57     end
58     return
59   end
60   
61   if B.vtype<>Double then
62     set_infos(gettext("eig() with 2 inputs: consider generalized eigen. Check."),2)
63   end
64   m=A.dims(1)
65   n=A.dims(2)
66   if lhs==1 then
67     al=gettempvar(1)
68     be=gettempvar(2)
69     insert(Equal(list(al,be),Funcall("spec",1,tree.rhs,list(al,be))))
70     tree=Operation("./",list(al,be),tree.lhs)
71     
72     tree.out(1).dims=list(m,1)
73     tree.out(1).type=Type(Double,Unknown)
74   else
75     al=gettempvar(1)
76     be=gettempvar(2)
77
78     insert(Equal(list(al,be,tree.lhs(1)),Funcall("eig",1,tree.rhs,list(al,be,tree.lhs(1)))))
79
80     tree=Operation("./",list(al,be),list(tree.lhs(1)))
81     tree=Funcall("diag",1,list(tree),tree.out)
82
83     tree.lhs(1).dims=list(A.dims(1),A.dims(1))
84     tree.lhs(1).type=Type(Double,Unknown)
85     tree.lhs(2).dims=list(A.dims(1),A.dims(1))
86     tree.lhs(2).type=Type(Double,Unknown)
87   end
88 // eig(A,B,flag)
89 else
90   no_equiv(msprintf(gettext("%s, flag IGNORED."),expression2code(tree)))
91   
92   tree.rhs(3)=null()
93   
94   tree.lhs(1).dims=list(A.dims(1),A.dims(1))
95   tree.lhs(1).type=Type(Double,Unknown)
96   if lhs==2 then
97     tree.lhs(2).dims=list(A.dims(1),A.dims(1))
98     tree.lhs(2).type=Type(Double,Unknown)
99   end
100 end
101
102 endfunction