bug 2938 fixed (xend call removed) + slight improvements
Serge Steer [Mon, 7 Jul 2008 09:02:18 +0000 (09:02 +0000)]
scilab/modules/cacsd/demos/lqg/lqg.dem
scilab/modules/cacsd/demos/lqg/scheme.dem

index e6890a1..d1a3030 100644 (file)
@@ -6,19 +6,26 @@
 //
 
 mode(-1);
-
+oldln=lines();lines(0)
 //display the diagram
 x=[5,10,20,40,50,70,80,90];xmin=-10;xmax=100;
 y=[22,28,30,32];ymin=12;ymax=40;
 
-xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
-yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
-    
-xset("window",0);xbasc();xselect();
-plot2d(xx,yy,ones(1,16),'022');
+xx=[x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
+yy=[y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
+
+scf(0);clf();xselect();
+a=gca();a.data_bounds=[xmin ymin;xmax ymax];a.box='on';
+xpolys(xx,yy)
 xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
 xtitle('PLANT   and   CONTROLLER')
 
+
+// xset("window",0);xbasc();xselect();
+// plot2d(xx,yy,ones(1,16),'022');
+// xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
+// xtitle('PLANT   and   CONTROLLER')
+
 path=get_absolute_file_path('lqg.dem');
 s=poly(0,'s');z=poly(0,'z');
 x_message(['Simple example of SISO LQG Design';
@@ -28,26 +35,26 @@ x_message(['Simple example of SISO LQG Design';
 n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
 
 select n
-       case 0
-               return
-       case 1
-               mode(1)
-               s=poly(0,'s');
-               str='(s-1)/(s^2-5*s+1)';
-               rep=x_dialog('Nominal plant?',str)
-               if rep==[] then return,end
-               Plant=evstr(rep);
-               Plant=syslin('c',Plant);
-               mode(-1)
-       case 2
-               mode(1)
-               z=poly(0,'z');
-               str='(z+1)/(z^2-5*z+2)'
-               rep=x_dialog('Nominal plant?',str)
-               if rep==[] then return,end
-               Plant=evstr(rep);
-               Plant=syslin('d',Plant);
-               mode(-1)
+case 0
+  return
+case 1
+  mode(1)
+  s=poly(0,'s');
+  str='(s-1)/(s^2-5*s+1)';
+  rep=x_dialog('Nominal plant?',str)
+  if rep==[] then return,end
+  Plant=evstr(rep);
+  Plant=syslin('c',Plant);
+  mode(-1)
+case 2
+  mode(1)
+  z=poly(0,'z');
+  str='(z+1)/(z^2-5*z+2)'
+  rep=x_dialog('Nominal plant?',str)
+  if rep==[] then return,end
+  Plant=evstr(rep);
+  Plant=syslin('d',Plant);
+  mode(-1)
 end
 
 mode(1)
@@ -86,62 +93,62 @@ x_message('Closed-loop response');
 
 resp=['Frequency response';'Time response'];
 while %t do
-       n=x_choose(resp,'Select response(s)');
-       select n
-               case 0
-                       disp("LQG demo stops!");break;
-               case 1 then
-                       mode(1)
-                       xbasc(0);xset("window",0);xselect();bode(Tlqg);xend()
-                       mode(-1)
-               case 2
-                       if Plant(4)=='c' then
-                       mode(1)
-                       defv=['0.1','20'];
-                       title='Enter Sampling period and Tmax';
-                       rep=x_mdialog(title,['Sampling period?';'Tmax?'],defv)
-                       if rep==[] then break,end
-                       dttmax=evstr(rep)
-                       dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
-                       t=0:dt/5:tmax;
-                       n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-                       select n1
-                               case 1 then
-                                       scf(1);clf();xselect();
-                                       plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')]);
-                               case 2 then
-                                       scf(1);clf();xselect();
-                                       plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t']);
-                       end
-                       mode(-1)
-               elseif Plant(4)=='d' then
-                       mode(1)
-                       defv=['30'];
-                       title='Tmax?';
-                       rep=x_mdialog(title,['Tmax='],defv)
-                       if rep==[] then break,end
-                       Tmax=evstr(rep);
-                       mode(-1)
-                       n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
-                       select n2
-                               case 0 then
-                                       break;
-                               case 1 then
-                                       mode(1)
-                                       u=ones(1,Tmax);u(1)=0;
-                                       scf(1);clf();xselect();
-                                       plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
-                                       mode(-1)
-                               case 2 then
-                                       mode(1)
-                                       u=zeros(1,Tmax);u(1)=1;
-                                       scf(1);clf();xselect();
-                                       plot2d((1:Tmax)',(dsimul(Tlqg,u))')
-                                       mode(-1)
-                       end
-               end
-       end
+  n=x_choose(resp,'Select response(s)');
+  select n
+  case 0
+    disp("LQG demo stops!");break;
+  case 1 then
+    mode(1)
+    scf(0);clf();xselect();bode(Tlqg);
+    mode(-1)
+  case 2
+    if Plant(4)=='c' then
+      mode(1)
+      defv=['0.1','20'];
+      title='Enter Sampling period and Tmax';
+      rep=x_mdialog(title,['Sampling period?';'Tmax?'],defv)
+      if rep==[] then break,end
+      dttmax=evstr(rep)
+      dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
+      t=0:dt/5:tmax;
+      n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+      select n1
+      case 1 then
+       scf(1);clf();xselect();
+       plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')]);
+      case 2 then
+       scf(1);clf();xselect();
+       plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t']);
+      end
+      mode(-1)
+    elseif Plant(4)=='d' then
+      mode(1)
+      defv=['30'];
+      title='Tmax?';
+      rep=x_mdialog(title,['Tmax='],defv)
+      if rep==[] then break,end
+      Tmax=evstr(rep);
+      mode(-1)
+      n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
+      select n2
+      case 0 then
+       break;
+      case 1 then
+       mode(1)
+       u=ones(1,Tmax);u(1)=0;
+       scf(1);clf();xselect();
+       plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
+       mode(-1)
+      case 2 then
+       mode(1)
+       u=zeros(1,Tmax);u(1)=1;
+       scf(1);clf();xselect();
+       plot2d((1:Tmax)',(dsimul(Tlqg,u))')
+       mode(-1)
+      end
+    end
+  end
 end
-
+lines(oldln(2))
 clear s z n str rep Plant P22 ny nu nx Qx Qu bigQ Rx Ry bigR  Plqg r 
-clear Klqg Slqg Rlqg Tlqg resp title dttmax dt t n1 defv Tmax n2 u 
+clear Klqg Slqg Rlqg Tlqg resp title dttmax dt t n1 defv Tmax n2 u oldln
index 3140091..e8fbb06 100644 (file)
@@ -12,8 +12,8 @@ y=[22,28,30,32];ymin=12;ymax=40;
 xx=[xmin,xmin,x([1 2 2 7 4 6 3 4 5 6 3 3 5 5]);xmax,xmax,x([3,2,7,7,5,8,3,4,5,6,4,4,6,6])];
 yy=[ymin,ymax,y([3,1,1,1,3,3,2,2,2,2,2,4,2,4]);ymin,ymax,y([3,3,1,3,3,3,4,4,4,4,2,4,2,4])];
     
-xset("window",0);xbasc();xselect();
-plot2d(xx,yy,ones(1,16),'022');
+scf(0);clf();xselect();
+a=gca();a.data_bounds=[xmin ymin;xmax ymax];
+xpolys(xx,yy)
 xstring(28,30,'K');xstring(56,30,'Plant');xstring(12,28.80,'-');
 xtitle('PLANT   and   CONTROLLER')
-xend()