5e8c0e1f17831edab80ed3c6fcd85a8c5cc963cb
[scilab.git] / scilab / modules / scicos_blocks / macros / NonLinear / DLRADAPT_f.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function [x,y,typ]=DLRADAPT_f(job,arg1,arg2)
23     x=[];y=[];typ=[];
24     select job
25     case "plot" then
26         standard_draw(arg1)
27     case "getinputs" then
28         [x,y,typ]=standard_inputs(arg1)
29     case "getoutputs" then
30         [x,y,typ]=standard_outputs(arg1)
31     case "getorigin" then
32         [x,y]=standard_origin(arg1)
33     case "set" then
34         x=arg1;
35         graphics=arg1.graphics;exprs=graphics.exprs
36         model=arg1.model;
37         while %t do
38             [ok,p,rn,rd,g,last_u,last_y,exprs]=scicos_getvalue("Set block parameters",..
39             ["Vector of p mesh points";
40             "Numerator roots (one line for each mesh)";
41             "Denominator roots (one line for each mesh)";
42             "Vector of gain at mesh points" ;
43             "past inputs (Num degree values)";
44             "past outputs (Den degree values)"],..
45             list("vec",-1,"mat",[-1,-1],"mat",..
46             ["size(%1,''*'')","-1"],"vec","size(%1,''*'')",..
47             "vec","size(%2,2)","vec","size(%3,2)"),exprs)
48
49
50             if ~ok then break,end
51             m=size(rn,2)
52             [npt,n]=size(rd)
53             if m>=n then
54                 message("Transfer must be strictly proper"),
55             elseif size(rn,1)<>0&size(rn,1)<>size(p,"*") then
56                 message("Numerator roots matrix row size''s is incorrect")
57             else
58                 rpar=[p(:);real(rn(:));imag(rn(:));real(rd(:));imag(rd(:));g(:)]
59                 ipar=[m;n;npt]
60                 model.dstate=[last_u(:);last_y(:)]
61                 model.rpar=rpar
62                 model.ipar=ipar
63                 graphics.exprs=exprs
64                 x.graphics=graphics;x.model=model
65                 break;
66             end
67         end
68     case "define" then
69         p=[0;1]
70         rn=[]
71         rd=[0.2+0.8*%i,0.2-0.8*%i;0.3+0.7*%i,0.3-0.7*%i]
72         g=[1;1]
73         last_u=[]
74         last_y=[0;0]
75
76         model=scicos_model()
77         model.sim="dlradp"
78         model.in=[1;1]
79         model.out=1
80         model.evtin=1
81
82         model.dstate=[last_u;last_y]
83         model.rpar=[p(:);real(rn(:));imag(rn(:));real(rd(:));imag(rd(:));g(:)]
84         model.ipar=[0;2;2]
85         model.blocktype="d"
86         model.firing=[]
87         model.dep_ut=[%t %f]
88
89         exprs=[sci2exp(p);
90         sci2exp(rn);
91         sci2exp(rd,0);
92         sci2exp(g);
93         sci2exp(last_u);
94         sci2exp(last_y)]
95         gr_i=["txt=[''N(z,p)'';''-----'';''D(z,p)''];";
96         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
97         x=standard_define([2 2],model,exprs,gr_i)
98     end
99 endfunction