error messages standardized + code improvments
Serge Steer [Fri, 11 Jul 2008 15:16:09 +0000 (15:16 +0000)]
83 files changed:
scilab/modules/cacsd/macros/abcd.sci
scilab/modules/cacsd/macros/abinv.sci
scilab/modules/cacsd/macros/arhnk.sci
scilab/modules/cacsd/macros/arma2p.sci
scilab/modules/cacsd/macros/armac.sci
scilab/modules/cacsd/macros/armax.sci
scilab/modules/cacsd/macros/armax1.sci
scilab/modules/cacsd/macros/arsimul.sci
scilab/modules/cacsd/macros/augment.sci
scilab/modules/cacsd/macros/balreal.sci
scilab/modules/cacsd/macros/black.sci
scilab/modules/cacsd/macros/bloc2exp.sci
scilab/modules/cacsd/macros/bloc2ss.sci
scilab/modules/cacsd/macros/bode.sci
scilab/modules/cacsd/macros/cainv.sci
scilab/modules/cacsd/macros/calfrq.sci
scilab/modules/cacsd/macros/chart.sci
scilab/modules/cacsd/macros/cls2dls.sci
scilab/modules/cacsd/macros/cont_mat.sci
scilab/modules/cacsd/macros/contrss.sci
scilab/modules/cacsd/macros/copfac.sci
scilab/modules/cacsd/macros/csim.sci
scilab/modules/cacsd/macros/ctr_gram.sci
scilab/modules/cacsd/macros/ddp.sci
scilab/modules/cacsd/macros/des2tf.sci
scilab/modules/cacsd/macros/dscr.sci
scilab/modules/cacsd/macros/dtsi.sci
scilab/modules/cacsd/macros/evans.sci
scilab/modules/cacsd/macros/findABCD.sci
scilab/modules/cacsd/macros/findAC.sci
scilab/modules/cacsd/macros/findx0BD.sci
scilab/modules/cacsd/macros/flts.sci
scilab/modules/cacsd/macros/frep2tf.sci
scilab/modules/cacsd/macros/g_margin.sci
scilab/modules/cacsd/macros/gainplot.sci
scilab/modules/cacsd/macros/gtild.sci
scilab/modules/cacsd/macros/h2norm.sci
scilab/modules/cacsd/macros/h_inf.sci
scilab/modules/cacsd/macros/h_norm.sci
scilab/modules/cacsd/macros/hankelsv.sci
scilab/modules/cacsd/macros/imrep2ss.sci
scilab/modules/cacsd/macros/inistate.sci
scilab/modules/cacsd/macros/invrs.sci
scilab/modules/cacsd/macros/invsyslin.sci
scilab/modules/cacsd/macros/kpure.sci
scilab/modules/cacsd/macros/krac2.sci
scilab/modules/cacsd/macros/lcf.sci
scilab/modules/cacsd/macros/leqe.sci
scilab/modules/cacsd/macros/leqr.sci
scilab/modules/cacsd/macros/lft.sci
scilab/modules/cacsd/macros/linf.sci
scilab/modules/cacsd/macros/lqg.sci
scilab/modules/cacsd/macros/lqg2stan.sci
scilab/modules/cacsd/macros/lqr.sci
scilab/modules/cacsd/macros/minreal.sci
scilab/modules/cacsd/macros/narsimul.sci
scilab/modules/cacsd/macros/nehari.sci
scilab/modules/cacsd/macros/nyquist.sci
scilab/modules/cacsd/macros/obs_gram.sci
scilab/modules/cacsd/macros/observer.sci
scilab/modules/cacsd/macros/obsv_mat.sci
scilab/modules/cacsd/macros/obsvss.sci
scilab/modules/cacsd/macros/p_margin.sci
scilab/modules/cacsd/macros/pfss.sci
scilab/modules/cacsd/macros/plzr.sci
scilab/modules/cacsd/macros/reglin.sci
scilab/modules/cacsd/macros/repfreq.sci
scilab/modules/cacsd/macros/riccati.sci
scilab/modules/cacsd/macros/routh_t.sci
scilab/modules/cacsd/macros/sgrid.sci
scilab/modules/cacsd/macros/show_margins.sci
scilab/modules/cacsd/macros/sm2ss.sci
scilab/modules/cacsd/macros/ss2tf.sci
scilab/modules/cacsd/macros/ssrand.sci
scilab/modules/cacsd/macros/st_ility.sci
scilab/modules/cacsd/macros/statgain.sci
scilab/modules/cacsd/macros/svplot.sci
scilab/modules/cacsd/macros/sylv.sci
scilab/modules/cacsd/macros/syslin.sci
scilab/modules/cacsd/macros/time_id.sci
scilab/modules/cacsd/macros/trfmod.sci
scilab/modules/cacsd/macros/trzeros.sci
scilab/modules/cacsd/macros/ui_observer.sci

index d35eba7..89af5c2 100644 (file)
 function [A,B,C,D]=abcd(sl)
 // Retrieves [A,B,C,D] matrices from linear system sl
 
-if type(sl)<>16 then
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: Typed list expected.\n"),"abcd",1))
-  return;
-end
-typis=sl(1);
-if typis(1)=='lss' then
-  [A,B,C,D]=sl(2:5)
-  return;
-end
-if typis(1)=='r' then
-  w=tf2ss(sl);
-  [A,B,C,D]=w(2:5)
-end
+  select typeof(sl)
+  case 'state-space' then
+    [A,B,C,D]=sl(2:5)
+    return;
+  case 'rational' then
+    w=tf2ss(sl);
+    [A,B,C,D]=w(2:5)
+  else
+    error(msprintf(_("%s: Wrong type for input argument: syslin structure expected.\n"),"abcd"))
+  end
 endfunction
index dc3825e..6720799 100644 (file)
@@ -46,119 +46,124 @@ function [X,dims,F,U,k,Z]=abinv(Sl,Alfa,Beta,flag)
 //     Then C*[(sI-A-B*F)^(-1)+D]*(Q+B*R) =0   (<=>G*(Q+B*R)=0)
 //F.D.
 //function [X,dims,F,U,k,Z]=abinv(Sl,Alfa,Beta,flag)
-[LHS,RHS]=argn(0);
-if RHS==1 then Alfa=-1;Beta=-1;flag='ge';end
-if RHS==2 then Beta=Alfa;flag='ge';end
-if RHS==3 then flag='ge';end
-if RHS==4 then 
-if type(flag)~=10 then error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"abinv",4));end
-end
-timedomain=Sl.dt;
-if timedomain==[] then    warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"abinv"));timedomain='c';end
-[A,B,C,D]=abcd(Sl);
-[nx,nu]=size(B);
-Vi=eye(A);
-[X,dimV]=im_inv([A;C],[Vi,B;zeros(C*Vi),D]);
-Vi1=X(:,1:dimV);
-while %t,
-[X,n1]=im_inv([A;C],[Vi1,B;zeros(C*Vi1),D]);
-if dimV==n1 then break;end
-dimV=n1;Vi1=X(:,1:n1);
-end
+  [LHS,RHS]=argn(0);
+  if RHS==1 then Alfa=-1;Beta=-1;flag='ge';end
+  if RHS==2 then Beta=Alfa;flag='ge';end
+  if RHS==3 then flag='ge';end
+  if RHS==4 then 
+    if type(flag)~=10 then 
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"abinv",4));
+    end
+  end
+  timedomain=Sl.dt;
+  if timedomain==[] then    
+    warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"abinv"));
+    timedomain='c';
+  end
+  [A,B,C,D]=abcd(Sl);
+  [nx,nu]=size(B);
+  Vi=eye(A);
+  [X,dimV]=im_inv([A;C],[Vi,B;zeros(C*Vi),D]);
+  Vi1=X(:,1:dimV);
+  while %t,
+    [X,n1]=im_inv([A;C],[Vi1,B;zeros(C*Vi1),D]);
+    if dimV==n1 then break;end
+    dimV=n1;Vi1=X(:,1:n1);
+  end
 
-//V=X(:,1:dimV);    // V subspace
-// Fast return if V=[];
-if dimV==0 then 
-       dimR=0;dimVg=0;
-       [U,k]=colcomp([B;D]);
-       [ns,nc,X]=st_ility(Sl);
-       F=stabil(Sl('A'),Sl('B'),Beta);
-       if flag=='ge' then dims=[0,0,0,nc,ns];end
-       if flag=='st' then dims=[0,0,nc,ns];end
-       if flag=='pp' then dims=[0,nc,ns];end
-       Z=syslin(timedomain,A+B*F,B*U,F,U);
-        return;
-end
-Anew=X'*A*X;Bnew=X'*B;Cnew=C*X;
-//   Determining dimR and dimVg
-B1V=Bnew(1:dimV,:);B2V=Bnew(dimV+1:nx,:);
-[U,k]=colcomp([B2V;D]);   //U is nu x nu
-Uker=U(:,1:nu-k);Urange=U(:,nu-k+1:nu);
-slV=syslin(timedomain,Anew(1:dimV,1:dimV),B1V*Uker,[]);
-[dimVg,dimR,Ur]=st_ility(slV);
-X(:,1:dimV)=X(:,1:dimV)*Ur;
-Anew=X'*A*X;Bnew=X'*B;Cnew=C*X;
-//Bnew=Bnew*U;
-//   Cut appropriate subspace  
-dim=dimVg;   //dim=dimVg   //dim=dimR
-select flag
-case 'ge'
-       dim=dimV
-case 'st'
-       dim=dimVg
-case 'pp'
-       dim=dimR
-end
-A11=Anew(1:dim,1:dim);
-B1=Bnew(1:dim,:);B2=Bnew(dim+1:nx,:);
-[U,k]=colcomp([B2;D]);   //U is nu x nu
-Uker=U(:,1:nu-k);Urange=U(:,nu-k+1:nu);
-B1t=B1*Uker;B1bar=B1*Urange;
-sl1=syslin(timedomain,A11,B1t,[]);    //
-[dimVg1,dimR1,Ur]=st_ility(sl1);
-A21=Anew(dim+1:nx,1:dim);
-A22=Anew(dim+1:$,dim+1:$);
-C1=Cnew(:,1:dim);
-B2bar=B2*Urange;Dbar=D*Urange; 
-// B2bar,Dbar have k columns , B1t has nu-k columns and dim rows
-Z=[A21,B2bar;C1,Dbar]; //Z is (nx-dim)+ny x dim+k 
-[W,nn]=colcomp(Z);    // ? (dim+k-nn)=dim  <=> k=nn ? if not-->problem
-W1=W(:,1:dim)*inv(W(1:dim,1:dim));
-F1bar=W1(dim+1:dim+k,:);  
-//[A21,B2bar;C1,Dbar]*[eye(dim,dim);F1bar]=zeros(nx-dim+ny,dim)
-//
-A11=A11+B1bar*F1bar;  //add B1bar*F1bar is not necessary.
-if B1t ~= [] then
-       voidB1t=%f;
-       if RHS==1 then
-         warning(msprintf(gettext("%s: Needs %s => Use default value %s=%d.\n"),"abinv","Alfa","Alfa",-1))
-         Alfa=-1;
-       end
-       F1t_tmp=0*sl1('B')'; //nu-k rows, dimV columns
-else
-       voidB1t=%t;F1t_tmp=[];dimR=0;
-end
-     
-if ~voidB1t then
-if norm(B1t,1)<1.d-10 then
-   F1t_tmp=zeros(nu-k,dim);dimR=0;
-end       
-end     
+  //V=X(:,1:dimV);    // V subspace
+  // Fast return if V=[];
+  if dimV==0 then 
+    dimR=0;dimVg=0;
+    [U,k]=colcomp([B;D]);
+    [ns,nc,X]=st_ility(Sl);
+    F=stabil(Sl('A'),Sl('B'),Beta);
+    if flag=='ge' then dims=[0,0,0,nc,ns];end
+    if flag=='st' then dims=[0,0,nc,ns];end
+    if flag=='pp' then dims=[0,nc,ns];end
+    Z=syslin(timedomain,A+B*F,B*U,F,U);
+    return;
+  end
+  Anew=X'*A*X;Bnew=X'*B;Cnew=C*X;
+  //   Determining dimR and dimVg
+  B1V=Bnew(1:dimV,:);B2V=Bnew(dimV+1:nx,:);
+  [U,k]=colcomp([B2V;D]);   //U is nu x nu
+  Uker=U(:,1:nu-k);Urange=U(:,nu-k+1:nu);
+  slV=syslin(timedomain,Anew(1:dimV,1:dimV),B1V*Uker,[]);
+  [dimVg,dimR,Ur]=st_ility(slV);
+  X(:,1:dimV)=X(:,1:dimV)*Ur;
+  Anew=X'*A*X;Bnew=X'*B;Cnew=C*X;
+  //Bnew=Bnew*U;
+  //   Cut appropriate subspace  
+  dim=dimVg;   //dim=dimVg   //dim=dimR
+  select flag
+  case 'ge'
+    dim=dimV
+  case 'st'
+    dim=dimVg
+  case 'pp'
+    dim=dimR
+  end
+  A11=Anew(1:dim,1:dim);
+  B1=Bnew(1:dim,:);B2=Bnew(dim+1:nx,:);
+  [U,k]=colcomp([B2;D]);   //U is nu x nu
+  Uker=U(:,1:nu-k);Urange=U(:,nu-k+1:nu);
+  B1t=B1*Uker;B1bar=B1*Urange;
+  sl1=syslin(timedomain,A11,B1t,[]);    //
+  [dimVg1,dimR1,Ur]=st_ility(sl1);
+  A21=Anew(dim+1:nx,1:dim);
+  A22=Anew(dim+1:$,dim+1:$);
+  C1=Cnew(:,1:dim);
+  B2bar=B2*Urange;Dbar=D*Urange; 
+  // B2bar,Dbar have k columns , B1t has nu-k columns and dim rows
+  Z=[A21,B2bar;C1,Dbar]; //Z is (nx-dim)+ny x dim+k 
+  [W,nn]=colcomp(Z);    // ? (dim+k-nn)=dim  <=> k=nn ? if not-->problem
+  W1=W(:,1:dim)*inv(W(1:dim,1:dim));
+  F1bar=W1(dim+1:dim+k,:);  
+  //[A21,B2bar;C1,Dbar]*[eye(dim,dim);F1bar]=zeros(nx-dim+ny,dim)
+  //
+  A11=A11+B1bar*F1bar;  //add B1bar*F1bar is not necessary.
+  if B1t ~= [] then
+    voidB1t=%f;
+    if RHS==1 then
+      warning(msprintf(gettext("%s: Needs %s => Use default value %s=%d.\n"),"abinv","Alfa","Alfa",-1))
+      Alfa=-1;
+    end
+    F1t_tmp=0*sl1('B')'; //nu-k rows, dimV columns
+  else
+    voidB1t=%t;F1t_tmp=[];dimR=0;
+  end
+  
+  if ~voidB1t then
+    if norm(B1t,1)<1.d-10 then
+      F1t_tmp=zeros(nu-k,dim);dimR=0;
+    end       
+  end     
 
-sl2=syslin(timedomain,A22,B2*Urange,0*(B2*Urange)');
-[ns2,nc2,U2,sl3]=st_ility(sl2);
-if (nc2~=0)&(RHS==1|RHS==2) then
-  warning(msprintf(gettext("%s: Needs %s => Use default value %s=%d.\n"),"abinv","Beta","Beta",-1));
-end
-F2=Urange*stabil(sl2('A'),sl2('B'),Beta);
+  sl2=syslin(timedomain,A22,B2*Urange,0*(B2*Urange)');
+  [ns2,nc2,U2,sl3]=st_ility(sl2);
+  if (nc2~=0)&(RHS==1|RHS==2) then
+    warning(msprintf(gettext("%s: Needs %s => Use default value %s=%d.\n"),"abinv","Beta","Beta",-1));
+  end
+  F2=Urange*stabil(sl2('A'),sl2('B'),Beta);
 
-//final patch
-Ftmp=[U*[F1t_tmp;F1bar],F2]*X';
-An=X'*(A+B*Ftmp)*X;Bn=X'*B*U;
-[m,n]=size(F1t_tmp);
-A11=An(1:n,1:n);B11=Bn(1:n,1:m);
-F1t=stabil(A11,B11,Alfa);
+  //final patch
+  Ftmp=[U*[F1t_tmp;F1bar],F2]*X';
+  An=X'*(A+B*Ftmp)*X;Bn=X'*B*U;
+  [m,n]=size(F1t_tmp);
+  A11=An(1:n,1:n);B11=Bn(1:n,1:m);
+  F1t=stabil(A11,B11,Alfa);
 
-F=[U*[F1t;F1bar],F2]*X';
-X=X*sysdiag(eye(Ur),U2);
-select flag
-case 'ge'
-       dims=[dimR,dimVg,dimV,dimV+nc2,dimV+ns2];
-case 'st'
-       dims=[dimR,dimVg,dimVg+nc2,dimVg+ns2];
-case 'pp'
-       dims=[dimR,dimR+nc2,dimR+ns2];
-end
+  F=[U*[F1t;F1bar],F2]*X';
+  X=X*sysdiag(eye(Ur),U2);
+  select flag
+  case 'ge'
+    dims=[dimR,dimVg,dimV,dimV+nc2,dimV+ns2];
+  case 'st'
+    dims=[dimR,dimVg,dimVg+nc2,dimVg+ns2];
+  case 'pp'
+    dims=[dimR,dimR+nc2,dimR+ns2];
+  end
 
-Z=syslin(timedomain,A+B*F,B*U,F,U);
+  Z=syslin(timedomain,A+B*F,B*U,F,U);
 endfunction
index f094755..ca30d9a 100644 (file)
@@ -9,62 +9,62 @@
 
 function [slm]=arhnk(a,ordre,tol)
 
-[lhs,rhs]=argn(0),
-   if lhs<>1 then error(41),end
-   typeofa=a(1)
-   if typeofa(1)<>'lss' then error(91,1),end;
-   if a(7)=='d' then error(93,1),end
-   select rhs
-     case 2 then istol=0;
-     case 3 then istol=1;
-   end;
-   [a,b,c,d,x0,dom]=a(2:7);
-if(maxi(real(spec(a)))) > 0 then
-  error('unstable system!');return;end
-domaine='c'
-wc=lyap(a',-b*b',domaine)
-wo=lyap(a,-c'*c,domaine)
-if istol==0 then [t,nn]=equil1(wc,wo);
-           else [t,nn]=equil1(wc,wo,tol);
-end;
-n1=nn(1);
-ti=inv(t);a=t*a*ti;b=t*b;c=c*ti
-wc=t*wc*t';wo=ti'*wo*ti;
-if ordre>n1 then
-//    error('order too big : '+string(n1)),//
-  ordre=n1
-end;
-if ordre==n1 then
-  a=a(1:n1,1:n1);b=b(1:n1,:);c=c(:,1:n1);
-  if lhs==1 then a=syslin('c',a,b,c,d,0*ones(n1,1)),end
-  return,
-end;
-sigma=wc(ordre+1,ordre+1)
-r=maxi(n1-ordre-1,1)
-n=n1
-sel=[1:ordre ordre+r+1:n];seleq=ordre+1:ordre+r
-b2=b(seleq,:);c2=c(:,seleq);
-u=-c(:,seleq)*pinv(b(seleq,:)')
-a=a(sel,sel);b=b(sel,:);c=c(:,sel);
-wo=wo(sel,sel);wc=wc(sel,sel);
-Gamma=wc*wo-sigma*sigma*eye()
-a=Gamma\(sigma*sigma*a'+wo*a*wc-sigma*c'*u*b')
-b1=Gamma\(wo*b+sigma*c'*u)
-c=c*wc+sigma*u*b';b=b1;
-d=-sigma*u+d
-//
-[n,n]=size(a)
-[u,m]=schur(a,'c')
-a=u'*a*u;b=u'*b;c=c*u;
-if m<n then
-  t=sylv(a(1:m,1:m),-a(m+1:n,m+1:n),-a(1:m,m+1:n),'c')
-  a=a(1:m,1:m)
-  b=b(1:m,:)-t*b(m+1:n,:)
-  c=c(:,1:m)
-end;
-//
-slm=syslin('c',a,b,c,d,0*ones(m,1));
+  [lhs,rhs]=argn(0),
+  if lhs<>1 then error(41),end
+  if typeof(a)<>'state-space' then error(91,1),end;
+  if a.dt<>'c' then error(93,1),end
+  select rhs
+  case 2 then istol=0;
+  case 3 then istol=1;
+  end;
+  
+  [a,b,c,d,x0,dom]=a(2:7);
+  if(maxi(real(spec(a)))) > 0 then
+    error(_("%s: Invalid input argument #%d: system must be stable\n","arhnk",1));
+  end
+  domaine='c'
+  wc=lyap(a',-b*b',domaine)
+  wo=lyap(a,-c'*c,domaine)
+  if istol==0 then [t,nn]=equil1(wc,wo);
+  else [t,nn]=equil1(wc,wo,tol);
+  end;
+  n1=nn(1);
+  ti=inv(t);a=t*a*ti;b=t*b;c=c*ti
+  wc=t*wc*t';wo=ti'*wo*ti;
+  if ordre>n1 then
+    ordre=n1
+  end;
+  if ordre==n1 then
+    a=a(1:n1,1:n1);b=b(1:n1,:);c=c(:,1:n1);
+    if lhs==1 then a=syslin('c',a,b,c,d,0*ones(n1,1)),end
+    return,
+  end;
+  sigma=wc(ordre+1,ordre+1)
+  
+  r=maxi(n1-ordre-1,1)
+  
+  n=n1
+  sel=[1:ordre ordre+r+1:n];seleq=ordre+1:ordre+r
+  b2=b(seleq,:);c2=c(:,seleq);
+  u=-c(:,seleq)*pinv(b(seleq,:)')
+  a=a(sel,sel);b=b(sel,:);c=c(:,sel);
+  wo=wo(sel,sel);wc=wc(sel,sel);
+  
+  Gamma=wc*wo-sigma*sigma*eye()
+  a=Gamma\(sigma*sigma*a'+wo*a*wc-sigma*c'*u*b')
+  b1=Gamma\(wo*b+sigma*c'*u)
+  c=c*wc+sigma*u*b';b=b1;
+  d=-sigma*u+d
+  //
+  [n,n]=size(a)
+  [u,m]=schur(a,'c')
+  a=u'*a*u;b=u'*b;c=c*u;
+  if m<n then
+    t=sylv(a(1:m,1:m),-a(m+1:n,m+1:n),-a(1:m,m+1:n),'c')
+    a=a(1:m,1:m)
+    b=b(1:m,:)-t*b(m+1:n,:)
+    c=c(:,1:m)
+  end;
+  //
+  slm=syslin('c',a,b,c,d,0*ones(m,1));
 endfunction
index d78547e..070b3b5 100644 (file)
 function [A,B,D]=arma2p(ar) 
 // Build three polynomial matrices 
 // from an ar representation 
-if ar(1)<>'ar' then error(msprintf(gettext("%s: This is not an ARMAX.\n"),"arma2p"));return;end;
+if ar(1)<>'ar' then 
+  error(msprintf(gettext("%s: Wrong type for input argument #%d: %s data structure expected.\n"),..
+                "arma2p",1,"armax"));
+end;
 A=inv_coeff(ar(2));
 if ar(3)<>[] then 
        [mb,nb]=size(ar(3));
index 27da4d7..7ca297b 100644 (file)
@@ -22,21 +22,25 @@ function [ar]=armac(a,b,d,ny,nu,sig)
 
 [na,la]=size(a);
 if na<>ny then 
-  error(msprintf(gettext("%s: Wrong size for input argument #%d: %s must be of dimension %s.\n"),"armac",1,"a(:,1)", string(ny)));
+  error(msprintf(gettext("%s: Wrong size for input argument #%d: row dimension must be equal to %d.\n"),..
+                "armac",1, ny));
 
 end
 [nb,lb]=size(b);
 if nb<>0 & nb<>ny then 
-  error(msprintf(gettext("%s: Wrong size for input argument #%d: %s must be of dimension %s.\n"),"armac",2,"b(:,1)", string(ny)));
+  error(msprintf(gettext("%s: Wrong size for input argument #%d: row dimension must be equal to %d.\n"),..
+                "armac",2, ny));
 end;
 if lb<>0 & nu<>0 then 
  if modulo(lb,nu)<>0 then 
-   error(msprintf(gettext("%s: Wrong size of input argument #%d: Number of columns are incompatible with %s.\n"),"armac",2,"nu"));
+   error(msprintf(gettext("%s: Wrong size of input argument #%d: Number of columns are incompatible with %s.\n"),..
+                 "armac",2,"nu"));
   end;
 end      
 [nd,ld]=size(d);
 if nd<>ny then 
-  error(msprintf(gettext("%s: Wrong size for input argument #%d: %s must be of dimension %s.\n"),"armac",3,"d(:,1)", string(ny)));
+  error(msprintf(gettext("%s: Wrong size for input argument #%d: row dimension must be equal to %d.\n"),..
+                "armac",3, ny));
 
 end
 ar=tlist(['ar','a','b','d','ny','nu','sig'],a,b,d,ny,nu,sig);
index 9bb369b..53bf6c5 100644 (file)
@@ -79,7 +79,7 @@ if rhs<=4,b0f=0;end
  [nzl,nzc]=size(zz);
  k=rank(zz);
 if k<>nzl then
-  warning(msprintf(gettext("%s: %s is numerically singular.\n"),"armax","z.z''"));
+  warning(msprintf(gettext("%s: %s is numerically singular.\n"),"armax","z*z''"));
 end;
  pv=pinv(zz);
  coef=(pv*zy)';
index ebaeca4..3e31882 100644 (file)
@@ -44,7 +44,8 @@ function [arc,resid]=armax1(r,s,q,y,u,b0f)
   u=matrix(u,1,-1);y=matrix(y,1,-1); //make u and y row vectors
   [n1,n2]=size(y)
   if size(y,'*')<>size(u,'*') then
-    error(msprintf(gettext("%s: Wrong type for input arguments: %s and %s must have same size.\n"),"armax1","u","y"));
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same numbers of elements expected.\n"),..
+                  "armax1",4,5));
   end 
   //
   t0=maxi(maxi(r,s+1),1)+1;
index e01c6ae..9945e64 100644 (file)
 function z=arsimul(x1,x2,x3,x4,x5,x6,x7,x8)
 // function z=arsimul(a,b,d,sig,u,up,yp,ep)
 
-[lhs,rhs]=argn(0)
-// switch to ar representation 
-if type(x1)<>15&type(x1)<>16 then 
-   if rhs < 5, error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"arsimul",5));
-       return;end;
-   ar=armac(x1,x2,x3,size(x1,'r'),size(x5,'r'),x4);
-   if rhs==5,z=arsimul(ar,x5);return;end
-   if rhs==6,z=arsimul(ar,x5,x6);return;end
-   if rhs==7,z=arsimul(ar,x5,x6,x7);return;end;
-   if rhs==8,z=arsimul(ar,x5,x6,x7,x8);return;end;
-end
-// Here the call is always arsimul(ar,....)
-a=x1('a');b=x1('b');d=x1('d');sig=x1('sig');
-u=x2;
-[bl,bc]=size(b);[al,ac]=size(a);[dl,dc]=size(d);
-[mmu,Nu]=size(u);
-if mmu<>x1('nu') then 
-  error(msprintf(gettext("%s: Number of rows of %s are incompatible with %s object.\n"),"arsimul","u",'arma"));
-  return;
-end;
-// X = [y_{n-1},y_{n-2},...y_{n-ka},u_{n-1},....,u_{n-kb},e_{n-1},....,e_{n-kd}
-a1=a(:,al+1:$);al1=size(a1,'c');
-b1=b(:,mmu+1:$);bl1=size(b1,'c');
-d1=d(:,al+1:$);dl1=size(d1,'c');
-A=[-a1,b1,d1];
-// y_{n} = A*X + b(:,1:mmu)*u_{n}+d(:,1:al)*e_{n} 
-// in the system fff x=[y_n;X];
-if A==[] then 
-  deff('[xkp1]=fff(k,x)',...
-       ['ukp1=u(:,k+1);dkp1=br(:,k+1);';
-        'xkp1= b(:,1:mmu)*ukp1+d(:,1:al)*dkp1']);
-else 
-  deff('[xkp1]=fff(k,x)',...
-       ['x=x(al+1:$);ukp1=u(:,k+1);dkp1=br(:,k+1);';
-        'ykp1= A*x + b(:,1:mmu)*ukp1+d(:,1:al)*dkp1';
-        'xkp1=[];'
-        'if al1>0; xkp1=[ykp1;x(1:al1-al)];end;';
-        'if bl1>0; xkp1=[xkp1;ukp1;x(al1+1:al1+bl1-mmu)];end;';
-        'if dl1>0; xkp1=[xkp1;dkp1;x(al1+bl1+1:al1+bl1+dl1-al)];end;';
-        'xkp1=[ykp1;xkp1];'    ]);
-end
-// Noise simulation.
-br=sig*rand(al,Nu,'normal');
-//br=[-2,1,0.5]
-// Initial condition 
-// the first call to fff will be fff(0,x) 
-// x must be set to 
-// [ y_{0},...y{-ak},u_{0},...u_{-bk},d_{0},...d_{-dk}
-// where ak= al1/al -1; bk= bl1/mmu -1 ; dk = dl1/al-1
-// past conditions for up 
-//--------------------------
-if rhs <=2,
-   up=0*ones(bl1,1);
-else
-   up=x3;
-   if bl1==0 then 
-      if up<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: [] expected.\n"),"arsimul",3))
-               return ;
+  [lhs,rhs]=argn(0)
+  // switch to ar representation 
+  if type(x1)<>15&type(x1)<>16 then 
+    if rhs < 5, 
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"arsimul",5,8));
+    end;
+    ar=armac(x1,x2,x3,size(x1,'r'),size(x5,'r'),x4);
+    if rhs==5,z=arsimul(ar,x5);return;end
+    if rhs==6,z=arsimul(ar,x5,x6);return;end
+    if rhs==7,z=arsimul(ar,x5,x6,x7);return;end;
+    if rhs==8,z=arsimul(ar,x5,x6,x7,x8);return;end;
+  end
+  // Here the call is always arsimul(ar,....)
+  a=x1('a');b=x1('b');d=x1('d');sig=x1('sig');
+  u=x2;
+  [bl,bc]=size(b);[al,ac]=size(a);[dl,dc]=size(d);
+  [mmu,Nu]=size(u);
+  if mmu<>x1('nu') then 
+    error(msprintf(gettext("%s: Number of rows of %s are incompatible with %s object.\n"),"arsimul","u",'arma"));
+    return;
+  end;
+  // X = [y_{n-1},y_{n-2},...y_{n-ka},u_{n-1},....,u_{n-kb},e_{n-1},....,e_{n-kd}
+  a1=a(:,al+1:$);al1=size(a1,'c');
+  b1=b(:,mmu+1:$);bl1=size(b1,'c');
+  d1=d(:,al+1:$);dl1=size(d1,'c');
+  A=[-a1,b1,d1];
+  // y_{n} = A*X + b(:,1:mmu)*u_{n}+d(:,1:al)*e_{n} 
+  // in the system fff x=[y_n;X];
+  if A==[] then 
+    deff('[xkp1]=fff(k,x)',...
+        ['ukp1=u(:,k+1);dkp1=br(:,k+1);';
+         'xkp1= b(:,1:mmu)*ukp1+d(:,1:al)*dkp1']);
+  else 
+    deff('[xkp1]=fff(k,x)',...
+        ['x=x(al+1:$);ukp1=u(:,k+1);dkp1=br(:,k+1);';
+         'ykp1= A*x + b(:,1:mmu)*ukp1+d(:,1:al)*dkp1';
+         'xkp1=[];'
+         'if al1>0; xkp1=[ykp1;x(1:al1-al)];end;';
+         'if bl1>0; xkp1=[xkp1;ukp1;x(al1+1:al1+bl1-mmu)];end;';
+         'if dl1>0; xkp1=[xkp1;dkp1;x(al1+bl1+1:al1+bl1+dl1-al)];end;';
+         'xkp1=[ykp1;xkp1];'   ]);
+  end
+  // Noise simulation.
+  br=sig*rand(al,Nu,'normal');
+  //br=[-2,1,0.5]
+  // Initial condition 
+  // the first call to fff will be fff(0,x) 
+  // x must be set to 
+  // [ y_{0},...y{-ak},u_{0},...u_{-bk},d_{0},...d_{-dk}
+  // where ak= al1/al -1; bk= bl1/mmu -1 ; dk = dl1/al-1
+  // past conditions for up 
+  //--------------------------
+  if rhs <=2,
+    up=0*ones(bl1,1);
+  else
+    up=x3;
+    if bl1==0 then 
+      if up<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: An empty matrix expected.\n"),"arsimul",3))
+       return ;
       end;
-   else 
+    else 
       up_s=size(up)
       if up_s(1)<>mmu|up_s(2)<>(bl1/mmu) then
        error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n'),"arsimul","up=[u(0),u(-1),..,]",string(mmu),string(bl1/mmu)));
         return 
       end
       up=matrix(up,bl1,1);
-   end
-end
-// past conditions for yp
-//--------------------------
-if rhs <=3,
-   yp=0*ones(al1,1)
-else
-   yp=x4;
-   if al1==0 then 
-      if yp<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: [] expected.\n"),"arsimul",4))
-               return ;
+    end
+  end
+  // past conditions for yp
+  //--------------------------
+  if rhs <=3,
+    yp=0*ones(al1,1)
+  else
+    yp=x4;
+    if al1==0 then 
+      if yp<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: An empty matrix expected.\n"),"arsimul",4))
+       return ;
       end;
-   else 
-     yp_s=size(yp);
-     if yp_s(1)<>al|yp_s(2)<>(al1/al) then 
-      error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"), "arsimul","yp=[y(0),y(-1),..,]",string(al), string(al1/al)));
-      return;
-     end
-     yp=matrix(yp,al1,1);
-   end
-end
-// past conditions for ep
-//--------------------------
-if rhs <=4,
-  ep=0*ones(dl1,1);
-else
-   ep=x5
-   if dl1==0 then 
-      if ep<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: [] expected.\n"),"arsimul",5))
-               return ;
+    else 
+      yp_s=size(yp);
+      if yp_s(1)<>al|yp_s(2)<>(al1/al) then 
+       error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"), "arsimul","yp=[y(0),y(-1),..,]",string(al), string(al1/al)));
+       return;
+      end
+      yp=matrix(yp,al1,1);
+    end
+  end
+  // past conditions for ep
+  //--------------------------
+  if rhs <=4,
+    ep=0*ones(dl1,1);
+  else
+    ep=x5
+    if dl1==0 then 
+      if ep<>[] then error(msprintf(gettext("%s: Wrong size for input argument #%d: An empty matrix expected.\n"),"arsimul",5))
+       return ;
       end;
-   else 
+    else 
       ep_s=size(ep);
       if ep_s(1)<>al|ep_s(2)<>(dl1/al) then
-                      error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"), "arsimul","ep=[e(0),e(-1),..,]",string(al), string(dl1/al)));
-         return;
+       error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"), "arsimul","ep=[e(0),e(-1),..,]",string(al), string(dl1/al)));
+       return;
       end
       ep=matrix(ep,dl1,1);
-   end;
-end;
-xi=[yp;up;ep];
-// If A=[] it is a degenerate case which also work 
-// but xi must be set to a scalar value to provide proper 
-// result dimensions.
-// 
-xi=[0*ones(al,1);xi];
-z=ode('discret',xi,0,1:Nu,fff);
-// Now z contains y_{1},.....y_{Nu};
-z=z(1:al,:)
+    end;
+  end;
+  xi=[yp;up;ep];
+  // If A=[] it is a degenerate case which also work 
+  // but xi must be set to a scalar value to provide proper 
+  // result dimensions.
+  // 
+  xi=[0*ones(al,1);xi];
+  z=ode('discret',xi,0,1:Nu,fff);
+  // Now z contains y_{1},.....y_{Nu};
+  z=z(1:al,:)
 endfunction
index 7b67523..fb8ee70 100644 (file)
@@ -44,8 +44,8 @@ case 'o'
   select long
   case 3 then
     // 'SRT'
-    if SRT<>"SRT" then error(msprintf(gettext("%s: Wrong value for input argument: ''%s'' expected.\n"), 'augment','SRT'),9999);
-      return
+    if SRT<>"SRT" then 
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' expected.\n"), 'augment',2,'SRT'),9999);
     end
     if ssSRT==0 then
       W1=[Iy,Oyu,Oyy;
@@ -116,7 +116,8 @@ case 'o'
       end
       return  
     end 
-    error(msprintf(gettext("%s: Wrong value for input argument: ''%s'', ''%s'' or ''%s'' expected.\n"),'augment','SR','ST','RT'),9999);
+    error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+                  'augment',2, '''SR'',''ST'',''RT'''),9999);
   case 1 then
     if SRT=='S' then
       if ssSRT==0 then
@@ -177,8 +178,8 @@ case 'i'
   select long
   case 3 then
     // 'SRT'
-    if SRT<>"SRT" then error(msprintf(gettext("%s: Wrong value for input argument: ''%s'' expected.\n"),'augment','SRT'),9999);
-      return;
+    if SRT<>"SRT" then 
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' expected.\n"), 'augment',2,'SRT'),9999);
     end;
     if ssSRT==0 then
       W1=[Iu,-Iu;
@@ -245,7 +246,10 @@ case 'i'
       end
       return  
     end 
-    error(msprintf(gettext("%s: Wrong value for input argument: ''%s'', ''%s'' or ''%s'' expected.\n"),'augment','SR','ST','RT'),9999);
+    
+    error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+                  'augment',2, '''SR'',''ST'',''RT'''),9999);
+
   case 1 then
     if SRT=='S' then
       if ssSRT==0 then
index d573cfd..ba433d1 100644 (file)
 
 function [slb,u]=balreal(a)
 
-[lhs,rhs]=argn(0)
+  [lhs,rhs]=argn(0)
 
-if type(a)<>16 then error(91,1),end
-ttp=a(1);
-if ttp(1)<>'lss' then error(91,1),end
-[a,b,c,d,x0,dom]=a(2:7);
-if dom==[] then error(96,1),end
-domain='c';
-if dom<>'c' then domain='d',end
-if lhs>2  then error(msprintf(gettext("%s: Wrong number of output arguments: %d or %d expected.\n'),"balreal",1,2)),end
-wc=lyap(a',-b*b',domain)
-wo=lyap(a,-c'*c,domain)
-r=chol(wo);x=r*wc*r';[u,s,v]=svd(x);s=diag(s);
-ns=size(s,'*');
-lli=sqrt(sqrt(s));ll=ones(ns,1)./lli
-ri=inv(r)*v;r=v'*r;
-a=r*a*ri;b=r*b;c=c*ri
-a=diag(ll)*a*diag(lli)
-b=diag(ll)*b
-c=c*diag(lli)
-slb=syslin(dom,a,b,c,d,diag(ll)*r*x0),
-if lhs==2 then u=ri*diag(lli),end
+  if typeof(a)<>'state-space' then error(91,1),end
+  [a,b,c,d,x0,dom]=a(2:7);
+  if dom==[] then error(96,1),end
+  domain='c';
+  if dom<>'c' then domain='d',end
+  wc=lyap(a',-b*b',domain)
+  wo=lyap(a,-c'*c,domain)
+  r=chol(wo);x=r*wc*r';[u,s,v]=svd(x);s=diag(s);
+  ns=size(s,'*');
+  lli=sqrt(sqrt(s));ll=ones(ns,1)./lli
+  ri=inv(r)*v;r=v'*r;
+  a=r*a*ri;b=r*b;c=c*ri
+  a=diag(ll)*a*diag(lli)
+  b=diag(ll)*b
+  c=c*diag(lli)
+  slb=syslin(dom,a,b,c,d,diag(ll)*r*x0),
+  if lhs==2 then u=ri*diag(lli),end
 endfunction
index 771b615..19a336c 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) INRIA  Serge Steer
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
@@ -49,54 +49,57 @@ function black(varargin)
   else
     comments=[];
   end
+  fname="black";//for error messages
   fmax=[]
   if or(typeof(varargin(1))==['state-space' 'rational']) then 
     //sys,fmin,fmax [,pas] or sys,frq
+    refdim=1 //for error message
     if rhs==1 then
       [frq,repf]=repfreq(varargin(1),1d-3,1d3)
     elseif rhs==2 then //sys,frq
       if size(varargin(2),2)<2 then
-       error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "black",1,1))
+       error(msprintf(_("%s: Wrong size for input argument #%d: A 1-by-n array expected with n>%d.\n"),..
+                      fname,1,1))
       end
       [frq,repf]=repfreq(varargin(1:rhs))
     elseif or(rhs==(3:4)) then //sys,fmin,fmax [,pas]
       [frq,repf]=repfreq(varargin(1:rhs))
     else
-      error(msprintf(_("%s : Invalid call: sys,fmin,fmax [,pas] [,com]'),"black"))
+      error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,1,5))
     end
     [phi,d]=phasemag(repf)
     if rhs>=3 then fmax=varargin(3),end
   elseif  type(varargin(1))==1 then 
     //frq,db,phi [,comments] or frq, repf [,comments]
+    refdim=2
     select rhs
     case 2 then //frq,repf
       frq=varargin(1);
       if size(frq,2)<2 then
        error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "black",1,1))
+                      fname,1,1))
       end
       if size(frq,2)<>size(varargin(2),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "black",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
       [phi,d]=phasemag(varargin(2))
     case 3 then  //frq,db,phi
       [frq,d,phi]=varargin(1:rhs)
       if size(frq,2)<>size(d,2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "black",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
       if size(frq,2)<>size(phi,2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "black",1,3))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,3))
       end
     else 
-      error(msprintf(_("%s : Invalid call: frq, db,phi [,com] or frq,repf [,com]'),"black"))
+       error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
     end
   else
-    error(msprintf(_("%s : Invalid argument #%d. It must be a linear"+..
-                    " dynamical system (syslin) or a real array"),"black",1))
+     error(msprintf(_("%s: Wrong type for input argument #%d:  Linear state space, transfer function "+.. 
+                    " or row vector of floats expected.\n"),fname,1))
   end;
   
   if size(frq,1)==1 then
@@ -107,7 +110,8 @@ function black(varargin)
  
   [mn,n]=size(phi);
   if and(size(comments,'*')<>[0 mn]) then
-    error(msprintf(_("%s : Invalid dimension for argument #%d"),"black",rhs+1))
+     error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),...
+                    fname,refdim,rhs+1))
   end
 
   //
@@ -172,7 +176,7 @@ function black(varargin)
     kf=kf+ilf
   end
  
-  xtitle('h(2i.pi.f) ','phase','magnitude (Db)');
+  xtitle(" ",_("Frequency (°)"),_("Magnitude (Db)"));
   //  2.3 db curve
   mbf=2.3;
   lmda=exp(log(10)/20*mbf);
index 7486317..03b4383 100644 (file)
@@ -131,8 +131,12 @@ for k=2:nsyst
   end;
   end,end
 end;
-if mini(lsorties)==0 then error(msprintf(gettext("%s: Internal error: Undefined output.\n"),"bloc2exp")),end
-if mini(lentrees)==0 then error(msprintf(gettext("%s: Internal error: Undefined input.\n"),"bloc2exp")),end
+if mini(lsorties)==0 then 
+  error(msprintf(gettext("%s: Internal error: Undefined output.\n"),"bloc2exp")),
+end
+if mini(lentrees)==0 then 
+  error(msprintf(gettext("%s: Internal error: Undefined input.\n"),"bloc2exp")),
+end
 
 endfunction
 function [where_x]=%connect(bloc,lliens,syst)
index b1785b4..21d7afb 100644 (file)
@@ -226,8 +226,16 @@ for k=2:nsyst
   end;
   end,end
 end;
-if lsorties==[] then error(msprintf(gettext("%s: Internal error: Wrong number of output arguments.\n"),"bloc2ss")),end
-if lentrees==[] then error(msprintf(gettext("%s: Internal error: Wrong number of input arguments.\n"),"bloc2ss")),end
-if mini(lsorties)==0 then error(msprintf(gettext("%s: Internal error: Undefined output.\n"),"bloc2ss")),end
-if mini(lentrees)==0 then error(msprintf(gettext("%s: Internal error: Undefined input.\n"),"bloc2ss")),end
+if lsorties==[] then 
+  error(msprintf(gettext("%s: Internal error: Wrong number of output arguments.\n"),"bloc2ss")),
+end
+if lentrees==[] 
+then error(msprintf(gettext("%s: Internal error: Wrong number of input arguments.\n"),"bloc2ss")),
+end
+if mini(lsorties)==0 then 
+  error(msprintf(gettext("%s: Internal error: Undefined output.\n"),"bloc2ss")),
+end
+if mini(lentrees)==0 then 
+  error(msprintf(gettext("%s: Internal error: Undefined input.\n"),"bloc2ss")),
+end
 endfunction
index 7387cb8..d2b3838 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) INRIA Serge Steer
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
@@ -13,54 +13,57 @@ function []=bode(varargin)
   else
     comments=[];
   end
+  fname="bode";//for error messages
   fmax=[]
   if or(typeof(varargin(1))==['state-space' 'rational']) then 
     //sys,fmin,fmax [,pas] or sys,frq
-    if rhs==1 then
+    refdim=1 //for error message
+    if rhs==1 then //sys
       [frq,repf]=repfreq(varargin(1),1d-3,1d3)
     elseif rhs==2 then //sys,frq
       if size(varargin(2),2)<2 then
-       error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "bode",1,1))
+       error(msprintf(_("%s: Wrong size for input argument #%d: A 1-by-n array expected with n>%d.\n"),..
+                      fname,1,1))
       end
       [frq,repf]=repfreq(varargin(1:rhs))
     elseif or(rhs==(3:4)) then //sys,fmin,fmax [,pas]
       [frq,repf]=repfreq(varargin(1:rhs))
     else
-      error(msprintf(_("%s : Invalid call: sys,fmin,fmax [,pas] [,com]'),"bode"))
+      error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,1,5))
     end
     [phi,d]=phasemag(repf)
     if rhs>=3 then fmax=varargin(3),end
   elseif  type(varargin(1))==1 then 
     //frq,db,phi [,comments] or frq, repf [,comments]
+    refdim=2
     select rhs
     case 2 then //frq,repf
       frq=varargin(1);
       if size(frq,2)<2 then
        error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "bode",1,1))
+                      fname,1,1))
       end
       if size(frq,2)<>size(varargin(2),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "bode",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
       [phi,d]=phasemag(varargin(2))
     case 3 then  //frq,db,phi
       [frq,d,phi]=varargin(1:rhs)
       if size(frq,2)<>size(d,2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "bode",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
       if size(frq,2)<>size(phi,2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "bode",1,3))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,3))
       end
     else 
-      error(msprintf(_("%s : Invalid call: frq, db,phi [,com] or frq,repf [,com]'),"bode"))
+       error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
     end
   else
-    error(msprintf(_("%s : Invalid argument #%d. It must be a linear"+..
-                    " dynamical system (syslin) or a real array"),"bode",1))
+    error(msprintf(_("%s: Wrong type for input argument #%d:  Linear state space, transfer function "+.. 
+                    " or row vector of floats expected.\n"),fname,1))
   end;
    frq=frq';d=d',phi=phi'
   [n,mn]=size(d)
@@ -69,7 +72,8 @@ function []=bode(varargin)
     hx=0.48
   else
     if size(comments,'*')<>mn then
-      error(msprintf(_("%s : Invalid dimension for argument #%d"),"bode",rhs+1))
+      error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),...
+                    fname,refdim,rhs+1))
     end
     hx=0.43
   end;
@@ -95,7 +99,7 @@ function []=bode(varargin)
       xpoly(max(frq)*[1;1],axes.y_ticks.locations([1 $]));e=gce();
       e.foreground=5;
   end
-  xtitle('Magnitude ',' Hz','db');
+  xtitle("",_("Frequency (Hz)"),_("Magnitude (Db)"));
 
   //phase
   axes=newaxes();
@@ -113,6 +117,7 @@ function []=bode(varargin)
       xpoly(max(frq)*[1;1],axes.y_ticks.locations([1 $]));e=gce();
       e.foreground=5;
   end
+  xtitle("",_("Frequency (Hz)"),_("Phase (°)"));
   // create legend
   if comments<>[] then
     axes=newaxes()
index e821869..6a9bd7f 100644 (file)
@@ -51,48 +51,53 @@ function [X,dims,J,Y,k,Z]=cainv(Sl,Alfa,Beta,flag)
 // [Xp(1:dimSg,:);C]*W = [0 | *] one has
 // H*W = [0 | *]  (with at least as many columns as above).
 
-[LHS,RHS]=argn(0);
-if RHS==1 then Alfa=-1;Beta=-1;flag='ge';end
-if RHS==2 then Beta=Alfa;flag='ge';end
-if RHS==3 then flag='ge';end
-if RHS==4 then 
-if type(flag)~=10 then error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"cainv",4));end
-end
-[X,ddims,F,U,k,Z]=abinv(Sl',Beta,Alfa,flag);
-[nx,nx]=size(X);
-select flag
-case 'ge'
-nr=ddims(1);nvg=ddims(2);nv=ddims(3);noc=ddims(4);nos=ddims(5);
-nd1=nx-nos;nu1=nx-noc;dimS=nx-nv;dimSg=nx-nvg;dimN=nx-nr;
-n6=1+ddims(5):nx;
-n5=1+ddims(4):ddims(5);
-n4=1+ddims(3):ddims(4);
-n3=1+ddims(2):ddims(3);
-n2=1+ddims(1):ddims(2);
-n1=1:ddims(1);
-//nr=1:nr;nzs=nr+1:nr+nvg;nzi=nvg+1:nv;
-X=[X(:,n6),X(:,n5),X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
-J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
-dims=[nd1,nu1,dimS,dimSg,dimN];
-return;
-case 'st'
-dims=nx-ddims;dims=dims($:-1:1);
-n5=1+ddims(4):nx;
-n4=1+ddims(3):ddims(4);
-n3=1+ddims(2):ddims(3);
-n2=1+ddims(1):ddims(2);
-n1=1:ddims(1);
-X=[X(:,n5),X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
-J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
-return;
-case 'pp'
-dims=nx-ddims;dims=dims($:-1:1);
-n4=1+ddims(3):nx;
-n3=1+ddims(2):ddims(3);
-n2=1+ddims(1):ddims(2);
-n1=1:ddims(1);
-X=[X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
-J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
-return;
-end
+  [LHS,RHS]=argn(0);
+  if RHS==1 then Alfa=-1;Beta=-1;flag='ge';end
+  if RHS==2 then Beta=Alfa;flag='ge';end
+  if RHS==3 then flag='ge';end
+  if RHS==4 then 
+    if type(flag)~=10 then 
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"cainv",4));
+    end
+    if size(flag,'*')<>1 then
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"cainv",4));
+    end
+  end
+  [X,ddims,F,U,k,Z]=abinv(Sl',Beta,Alfa,flag);
+  [nx,nx]=size(X);
+  select flag
+  case 'ge'
+    nr=ddims(1);nvg=ddims(2);nv=ddims(3);noc=ddims(4);nos=ddims(5);
+    nd1=nx-nos;nu1=nx-noc;dimS=nx-nv;dimSg=nx-nvg;dimN=nx-nr;
+    n6=1+ddims(5):nx;
+    n5=1+ddims(4):ddims(5);
+    n4=1+ddims(3):ddims(4);
+    n3=1+ddims(2):ddims(3);
+    n2=1+ddims(1):ddims(2);
+    n1=1:ddims(1);
+    //nr=1:nr;nzs=nr+1:nr+nvg;nzi=nvg+1:nv;
+    X=[X(:,n6),X(:,n5),X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
+    J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
+    dims=[nd1,nu1,dimS,dimSg,dimN];
+    return;
+  case 'st'
+    dims=nx-ddims;dims=dims($:-1:1);
+    n5=1+ddims(4):nx;
+    n4=1+ddims(3):ddims(4);
+    n3=1+ddims(2):ddims(3);
+    n2=1+ddims(1):ddims(2);
+    n1=1:ddims(1);
+    X=[X(:,n5),X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
+    J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
+    return;
+  case 'pp'
+    dims=nx-ddims;dims=dims($:-1:1);
+    n4=1+ddims(3):nx;
+    n3=1+ddims(2):ddims(3);
+    n2=1+ddims(1):ddims(2);
+    n1=1:ddims(1);
+    X=[X(:,n4),X(:,n3),X(:,n2),X(:,n1)];
+    J=F';Z=Z';Y=U';Y=[Y(k+1:$,:);Y(1:k,:)];
+    return;
+  end
 endfunction
index 5864d1c..7d6ada4 100644 (file)
 function [frq,bnds,splitf]=calfrq(h,fmin,fmax)
 //!
 
-eps=1.d-14   //minimum absolute lower frequency
-k=0.001;     // Minimum relative prediction error in the nyquist plan 
-epss=0.002   // minimum frequency distance with a singularity
-nptmax=5000 //maximum number of discretisation points
-tol=0.01     // Tolerance for testing pure imaginary numbers 
+  eps=1.d-14   //minimum absolute lower frequency
+  k=0.001;     // Minimum relative prediction error in the nyquist plan 
+  epss=0.002   // minimum frequency distance with a singularity
+  nptmax=5000 //maximum number of discretisation points
+  tol=0.01     // Tolerance for testing pure imaginary numbers 
 
-// Check inputs
-// ------------
-if type(h)<>15&type(h)<>16 then 
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: A syslin list expected.\n"),"calfrq",1));
+  // Check inputs
+  // ------------
+  if and(typeof(h)<>['state-space' 'rational'])
+   error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"calfrq",1))
   end
-flag=h(1);
-if flag(1)<>'lss'&h(1)<>'r' then 
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: A syslin list expected.\n"),"calfrq",1));
-end
-if flag(1)=='lss' then
-  h=ss2tf(h)
-end
-[m,n]=size(h('num'))
-if  n<>1 then  
-  error('SIMO system only!')
-end
-dom=h('dt')
-select dom
-case 'd' then 
-  dom=1
-case [] then 
-  error(96,1)
-case 0 then
-  error(96,1)
-end;
-
-if type(dom)==1 then 
-  nyq_frq=1/2/dom;
-  if fmax>nyq_frq then 
-    warning(msprintf(gettext("%s: Frequencies beyond Nyquist frequency are ignored.\n"),"calfrq"));
-    fmax=min(fmax,nyq_frq)
+  flag=h(1);
+  if flag(1)=='lss' then
+    h=ss2tf(h)
   end
-  if fmin<-nyq_frq then 
-    warning(msprintf(gettext("%s: Negative frequencies below Nyquist frequency are ignored.\n"),"calfrq"));
-    fmin=max(fmin,-nyq_frq)
+  [m,n]=size(h.num)
+  if  n<>1 then  
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input system expected.\n"),"calfrq",1))
   end
-end
-// Use symmetry to reduce the range
-// --------------------------------
-if fmin<0&fmax>=0 then
-  [frq,bnds,splitf]=calfrq(h,eps,-fmin)
-  ns1=size(splitf,'*')-1;
-  nsp=size(frq,'*');
-  bnds=[bnds(1),bnds(2),-bnds(4),-bnds(3)];
+  dom=h('dt')
+  select dom
+  case 'd' then 
+    dom=1
+  case [] then 
+    error(96,1)
+  case 0 then
+    error(96,1)
+  end;
 
-  if fmax>eps then
-    if fmax==-fmin then
-      splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2),nsp*ones(ns1)+splitf(2:$)];
-      bnds=[bnds(1),bnds(2),min(bnds(3),-bnds(3)),max(bnds(4),-bnds(4))];
-      frq=[-frq($:-1:1),frq]
-    else
-      [frq2,bnds2,splitf2]=calfrq(h,eps,fmax);
-      ns2=size(splitf2,'*')-1
-      splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2),nsp*ones(ns2)+splitf2(2:$)];
-      bnds=[min(bnds(1),bnds2(1)),max(bnds(2),bnds2(2)),...
+  if type(dom)==1 then 
+    nyq_frq=1/2/dom;
+    if fmax>nyq_frq then 
+      warning(msprintf(gettext("%s: Frequencies beyond Nyquist frequency are ignored.\n"),"calfrq"));
+      fmax=min(fmax,nyq_frq)
+    end
+    if fmin<-nyq_frq then 
+      warning(msprintf(gettext("%s: Negative frequencies below Nyquist frequency are ignored.\n"),"calfrq"));
+      fmin=max(fmin,-nyq_frq)
+    end
+  end
+  // Use symmetry to reduce the range
+  // --------------------------------
+  if fmin<0&fmax>=0 then
+    [frq,bnds,splitf]=calfrq(h,eps,-fmin)
+    ns1=size(splitf,'*')-1;
+    nsp=size(frq,'*');
+    bnds=[bnds(1),bnds(2),-bnds(4),-bnds(3)];
+
+    if fmax>eps then
+      if fmax==-fmin then
+       splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2),nsp*ones(ns1)+splitf(2:$)];
+       bnds=[bnds(1),bnds(2),min(bnds(3),-bnds(3)),max(bnds(4),-bnds(4))];
+       frq=[-frq($:-1:1),frq]
+      else
+       [frq2,bnds2,splitf2]=calfrq(h,eps,fmax);
+       ns2=size(splitf2,'*')-1
+       splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2),nsp*ones(ns2)+splitf2(2:$)];
+       bnds=[min(bnds(1),bnds2(1)),max(bnds(2),bnds2(2)),...
               min(bnds(3),bnds2(3)),max(bnds(4),bnds2(4))];
-      frq=[-frq($:-1:1),frq2]
+       frq=[-frq($:-1:1),frq2]
+      end
+      return
+    else
+      frq=-frq($:-1:1);
+      nsp=size(frq,'*');
+      
+      splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2)]
+      bnds=bnds;
+      return;
     end
-    return
-  else
+  elseif fmin<0&fmax<=0 then
+    [frq,bnds,splitf]=calfrq(h,-fmax,-fmin)
+    ns1=size(splitf,'*')-1;
     frq=-frq($:-1:1);
     nsp=size(frq,'*');
-    
     splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2)]
-    bnds=bnds;
+    bnds=[bnds(1),bnds(2),-bnds(4),-bnds(3)];
     return;
+  elseif fmin >= fmax then
+    error(msprintf(gettext("%s: Wrong value for input arguments #%d and #%d: %s < %s expected.\n"),..
+                  "calfrq",2,3,"fmin","fmax"));
   end
-elseif fmin<0&fmax<=0 then
-  [frq,bnds,splitf]=calfrq(h,-fmax,-fmin)
-  ns1=size(splitf,'*')-1;
-  frq=-frq($:-1:1);
-  nsp=size(frq,'*');
-  splitf=[1, (nsp+2)*ones(1,ns1)-splitf($:-1:2)]
-  bnds=[bnds(1),bnds(2),-bnds(4),-bnds(3)];
-  return;
-elseif fmin >= fmax then
-  error(msprintf(gettext("%s: Wrong value for input argument: %s < %s expected.\n"),..
-                "calfrq","fmin","fmax"));
-end
 
-// Compute dicretisation over a given range
-// ----------------------------------------
+  // Compute dicretisation over a given range
+  // ----------------------------------------
 
 
-splitf=[]
-if fmin==0 then fmin=min(1d-14,fmax/10);end
-//
-denh=h('den');numh=h('num')
-l10=log(10)
+  splitf=[]
+  if fmin==0 then fmin=min(1d-14,fmax/10);end
+  //
+  denh=h('den');numh=h('num')
+  l10=log(10)
 
-// Locate singularities to avoid them
-// ----------------------------------
-if dom=='c' then
-  c=2*%pi;
-  //selection function for singularities in the frequency range
-  deff('f=%sel(r,fmin,fmax,tol)',['f=[],';
-  'if prod(size(r))==0 then return,end';
-  'f=imag(r(find((abs(real(r))<=tol*abs(r))&(imag(r)>=0))))';
-  'if f<>[] then  f=f(find((f>fmin-tol)&(f<fmax+tol)));end']);
-else
-  c=2*%pi*dom
-  //selection function for singularities in the frequency range
-  deff('[f]=%sel(r,fmin,fmax,dom,tol)',['f=[],';
-  'if prod(size(r))==0 then return,end';
-  'f=r(find( ((abs(abs(r)-ones(r)))<=tol)&(imag(r)>=0)))';
-  'if f<>[] then ';
-  '  f=atan(imag(f),real(f));nf=prod(size(f))';
-  '  for k=1:nf ,';
-  '    kk=int((fmax-f(k))/(2*%pi))+1;';
-  '    f=[f;f(1:nf)+2*%pi*kk*ones(nf,1)];';
-  '  end;'
-  '  f=f(find((f>fmin-tol)&(f<fmax+tol)))';
-  'end']);
-end
-
-sing=[];zers=[];
-fmin=c*fmin,fmax=c*fmax;
+  // Locate singularities to avoid them
+  // ----------------------------------
+  if dom=='c' then
+    c=2*%pi;
+    //selection function for singularities in the frequency range
+    deff('f=%sel(r,fmin,fmax,tol)',['f=[],';
+                   'if prod(size(r))==0 then return,end';
+                   'f=imag(r(find((abs(real(r))<=tol*abs(r))&(imag(r)>=0))))';
+                   'if f<>[] then  f=f(find((f>fmin-tol)&(f<fmax+tol)));end']);
+  else
+    c=2*%pi*dom
+    //selection function for singularities in the frequency range
+    deff('[f]=%sel(r,fmin,fmax,dom,tol)',['f=[],';
+                   'if prod(size(r))==0 then return,end';
+                   'f=r(find( ((abs(abs(r)-ones(r)))<=tol)&(imag(r)>=0)))';
+                   'if f<>[] then ';
+                   '  f=atan(imag(f),real(f));nf=prod(size(f))';
+                   '  for k=1:nf ,';
+                   '    kk=int((fmax-f(k))/(2*%pi))+1;';
+                   '    f=[f;f(1:nf)+2*%pi*kk*ones(nf,1)];';
+                   '  end;'
+                   '  f=f(find((f>fmin-tol)&(f<fmax+tol)))';
+                   'end']);
+  end
 
-for i=1:m
-  sing=[sing;%sel(roots(denh(i)),fmin,fmax,tol)];
-end
+  sing=[];zers=[];
+  fmin=c*fmin,fmax=c*fmax;
 
-pp=sort(sing');npp=size(pp,'*');//'
+  for i=1:m
+    sing=[sing;%sel(roots(denh(i)),fmin,fmax,tol)];
+  end
 
-// singularities just on the left of the range
-kinf=find(pp<fmin)
-if kinf<>[] then
-  fmin=fmin+tol
-  pp(kinf)=[]
-end
+  pp=sort(sing');npp=size(pp,'*');//'
 
-// singularities just on the right of the range
-ksup=find(pp>=fmax)
-if ksup<>[] then
-  fmax=fmax-tol
-  pp(ksup)=[]
-end
+  // singularities just on the left of the range
+  kinf=find(pp<fmin)
+  if kinf<>[] then
+    fmin=fmin+tol
+    pp(kinf)=[]
+  end
 
-//check for nearly multiple singularities
-if pp<>[] then
-  dpp=pp(2:$)-pp(1:$-1)
-  keq=find(abs(dpp)<2*epss)
-  if keq<>[] then pp(keq)=[],end
-end
+  // singularities just on the right of the range
+  ksup=find(pp>=fmax)
+  if ksup<>[] then
+    fmax=fmax-tol
+    pp(ksup)=[]
+  end
 
-if pp<>[] then
-  frqs=[fmin real(matrix([(1-epss)*pp;(1+epss)*pp],2*size(pp,'*'),1)') fmax]
-  //'
-else
-  frqs=[fmin fmax]
-end
-nfrq=size(frqs,'*');
+  //check for nearly multiple singularities
+  if pp<>[] then
+    dpp=pp(2:$)-pp(1:$-1)
+    keq=find(abs(dpp)<2*epss)
+    if keq<>[] then pp(keq)=[],end
+  end
 
-// Evaluate bounds of nyquist plot
-//-------------------------------
+  if pp<>[] then
+    frqs=[fmin real(matrix([(1-epss)*pp;(1+epss)*pp],2*size(pp,'*'),1)') fmax]
+    //'
+  else
+    frqs=[fmin fmax]
+  end
+  nfrq=size(frqs,'*');
 
-xt=[];Pas=[]
-for i=1:2:nfrq-1
-  w=logspace(log(frqs(i))/log(10),log(frqs(i+1))/log(10),100);
-  xt=[xt,w]
-  Pas=[Pas w(2)-w(1)]
-end
-if dom=='c' then 
-  rf=freq(h('num'),h('den'),%i*xt);
-else
-  rf=freq(h('num'),h('den'),exp(%i*xt));
-end
-//
-xmin=mini(real(rf));xmax=maxi(real(rf));
-ymin=mini(imag(rf));ymax=maxi(imag(rf));
-bnds=[xmin xmax ymin ymax];
-dx=max([xmax-xmin,1]);dy=max([ymax-ymin,1]);
+  // Evaluate bounds of nyquist plot
+  //-------------------------------
 
-// Compute discretization with a step adaptation method
-// ----------------------------------------------------
-frq=[];
-i=1;
-nptr=nptmax; // number of unused discretization points
-l10last=log10(frqs($));
-while i<nfrq
-  f0=frqs(i);fmax=frqs(i+1);
-  while f0==fmax do
-    i=i+2;
-    f=frqs(i);fmax=frqs(i+1);
+  xt=[];Pas=[]
+  for i=1:2:nfrq-1
+    w=logspace(log(frqs(i))/log(10),log(frqs(i+1))/log(10),100);
+    xt=[xt,w]
+    Pas=[Pas w(2)-w(1)]
+  end
+  if dom=='c' then 
+    rf=freq(h('num'),h('den'),%i*xt);
+  else
+    rf=freq(h('num'),h('den'),exp(%i*xt));
   end
-  frq=[frq,f0];
-  pas=Pas(floor(i/2)+1)
-  splitf=[splitf size(frq,'*')];
+  //
+  xmin=mini(real(rf));xmax=maxi(real(rf));
+  ymin=mini(imag(rf));ymax=maxi(imag(rf));
+  bnds=[xmin xmax ymin ymax];
+  dx=max([xmax-xmin,1]);dy=max([ymax-ymin,1]);
 
-  f=mini(f0+pas,fmax);
+  // Compute discretization with a step adaptation method
+  // ----------------------------------------------------
+  frq=[];
+  i=1;
+  nptr=nptmax; // number of unused discretization points
+  l10last=log10(frqs($));
+  while i<nfrq
+    f0=frqs(i);fmax=frqs(i+1);
+    while f0==fmax do
+      i=i+2;
+      f=frqs(i);fmax=frqs(i+1);
+    end
+    frq=[frq,f0];
+    pas=Pas(floor(i/2)+1)
+    splitf=[splitf size(frq,'*')];
 
-  if dom=='c' then //cas continu
-    while f0<fmax
-      rf0=freq(h('num'),h('den'),(%i*f0));
-      rfc=freq(h('num'),h('den'),%i*f);
-      // compute prediction error
-      epsd=pas/100;//epsd=1.d-8
-      
-      rfd=(freq(h('num'),h('den'),%i*(f0+epsd))-rf0)/(epsd);
-      rfp=rf0+pas*rfd;
+    f=mini(f0+pas,fmax);
+
+    if dom=='c' then //cas continu
+      while f0<fmax
+       rf0=freq(h('num'),h('den'),(%i*f0));
+       rfc=freq(h('num'),h('den'),%i*f);
+       // compute prediction error
+       epsd=pas/100;//epsd=1.d-8
+       
+       rfd=(freq(h('num'),h('den'),%i*(f0+epsd))-rf0)/(epsd);
+       rfp=rf0+pas*rfd;
 
-      e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
-      if (e>k) then rf0=freq(h('num'),h('den'),(%i*f0));
-      rfc=freq(h('num'),h('den'),%i*f);
-      // compute prediction error
-      epsd=pas/100;//epsd=1.d-8
+       e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
+       if (e>k) then rf0=freq(h('num'),h('den'),(%i*f0));
+         rfc=freq(h('num'),h('den'),%i*f);
+         // compute prediction error
+         epsd=pas/100;//epsd=1.d-8
 
-      rfd=(freq(h('num'),h('den'),%i*(f0+epsd))-rf0)/(epsd);
-      rfp=rf0+pas*rfd;
+         rfd=(freq(h('num'),h('den'),%i*(f0+epsd))-rf0)/(epsd);
+         rfp=rf0+pas*rfd;
 
-      e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
-       // compute minimum frequency logarithmic step to ensure a maximum 
-       //of nptmax points to discretize
-       pasmin=f0*(10^((l10last-log10(f0))/(nptr+1))-1)
-       pas=pas/2
-       if pas<pasmin then
-         pas=pasmin
+         e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
+         // compute minimum frequency logarithmic step to ensure a maximum 
+         //of nptmax points to discretize
+         pasmin=f0*(10^((l10last-log10(f0))/(nptr+1))-1)
+         pas=pas/2
+         if pas<pasmin then
+           pas=pasmin
+           frq=[frq,f];nptr=max([1,nptr-1])
+           f0=f;f=mini(f0+pas,fmax)
+         else
+           f=mini(f0+pas,fmax)
+         end
+       elseif e<k/2 then
+         pas=2*pas
          frq=[frq,f];nptr=max([1,nptr-1])
-         f0=f;f=mini(f0+pas,fmax)
+         f0=f;f=mini(f0+pas,fmax),
        else
-         f=mini(f0+pas,fmax)
+         frq=[frq,f];nptr=max([1,nptr-1])
+         f0=f;f=mini(f0+pas,fmax),
        end
-      elseif e<k/2 then
-       pas=2*pas
-       frq=[frq,f];nptr=max([1,nptr-1])
-       f0=f;f=mini(f0+pas,fmax),
-      else
-       frq=[frq,f];nptr=max([1,nptr-1])
-       f0=f;f=mini(f0+pas,fmax),
       end
-    end
-  else  //cas discret
-    pas=pas/dom
-    while f0<fmax
-      rf0=freq(h('num'),h('den'),exp(%i*f0))
-      rfd=dom*(freq(h('num'),h('den'),exp(%i*(f0+pas/100)))-rf0)/(pas/100);
-      rfp=rf0+pas*rfd
-      rfc=freq(h('num'),h('den'),exp(%i*f));
-      e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
-      if (e>k) then
-       pasmin=f0*(10^((l10last-log10(f0))/(nptr+1))-1)
-       pas=pas/2
-       if pas<pasmin then
-         pas=pasmin
+    else  //cas discret
+      pas=pas/dom
+      while f0<fmax
+       rf0=freq(h('num'),h('den'),exp(%i*f0))
+       rfd=dom*(freq(h('num'),h('den'),exp(%i*(f0+pas/100)))-rf0)/(pas/100);
+       rfp=rf0+pas*rfd
+       rfc=freq(h('num'),h('den'),exp(%i*f));
+       e=maxi([abs(imag(rfp-rfc))/dy;abs(real(rfp-rfc))/dx])
+       if (e>k) then
+         pasmin=f0*(10^((l10last-log10(f0))/(nptr+1))-1)
+         pas=pas/2
+         if pas<pasmin then
+           pas=pasmin
+           frq=[frq,f];nptr=max([1,nptr-1])
+           f0=f;f=mini(f0+pas,fmax)
+         else
+           f=mini(f0+pas,fmax)
+         end
+       elseif e<k/2 then
+         pas=2*pas
          frq=[frq,f];nptr=max([1,nptr-1])
-         f0=f;f=mini(f0+pas,fmax)
+         f0=f;f=mini(f0+pas,fmax),
        else
-         f=mini(f0+pas,fmax)
+         frq=[frq,f];nptr=max([1,nptr-1])
+         f0=f;f=mini(f0+pas,fmax),
        end
-      elseif e<k/2 then
-       pas=2*pas
-       frq=[frq,f];nptr=max([1,nptr-1])
-       f0=f;f=mini(f0+pas,fmax),
-      else
-       frq=[frq,f];nptr=max([1,nptr-1])
-       f0=f;f=mini(f0+pas,fmax),
       end
     end
+    i=i+2
   end
-  i=i+2
-end
-frq( size(frq,'*') )=fmax
-frq=frq/c;
+  frq( size(frq,'*') )=fmax
+  frq=frq/c;
 endfunction
index a660d0d..a479f31 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) INRIA Serge Steer
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
@@ -8,7 +8,7 @@
 
 function chart(attenu,angl,flags)
   
-  titre='amplitude and phase contours of y/(1+y)'
+  titre=_("Amplitude and phase contours of y/(1+y)")
   l10=log(10);
   ratio=%pi/180;
   //
@@ -75,7 +75,7 @@ function chart(attenu,angl,flags)
   k2=ceil(phi_max/180)
   //
   drawlater()
-  if flags(2) then xtitle(titre,'phase(y) - degree','magnitude(y) - db'),end
+  if flags(2) then xtitle(titre,_("phase(y) (°)"),_("magnitude(y) (Db)")),end
   llrect=xstringl(0,0,'1')
   
   //isogain curves
@@ -83,49 +83,51 @@ function chart(attenu,angl,flags)
   rayon=lambda./(lambda.*lambda-ones(lambda))
   centre=-lambda.*rayon
    //
-  for i = 1:prod(size(attenu)),
-    att=attenu(i);
-    if att<0 then 
-      w=%eps:0.03:%pi;
-    else 
-      w=-%pi:0.03:0;
-    end;
-    n=prod(size(w))
-    rf=centre(i)*ones(w)+rayon(i)*exp(%i*w);
-    phi=atan(imag(rf),real(rf))/ratio; //phi is in [-180 0]
-    module=20*log(abs(rf))/l10;
-    
-    //use symetry and period to extend the curve on [k1*180 k2*180]
-    p=[];m=[];
-    S=[]
-    for k=k1:k2-1
-      if pmodulo(k,2)==0 then
-       p=[p %nan k*180-phi($:-1:1)]
-       m=[m %nan module($:-1:1)]
-       if att>0 then 
-         xstring(p($),m($),string(att),0,0),
-         e=gce();e.clip_state='off';
-         S=[e S]
-       end
-      else
-       p=[p %nan ((k+1)*180)+phi]
-       m=[m %nan module]
-       if att<0 then 
-         xstring(p($),m($),string(att),0,0),
-         e=gce();e.clip_state='off';
-         S=[e S]
-       end
-      end
-      
-    end
-    xpoly(p,m)
-    e=gce();e.foreground=flags(3);//e.line_style=3,
-    if size(S,'*')>1 then S=glue(S),end
-    S=glue([S,e]);S.user_data=att;
-  end;
-  glue(ax.children(size(attenu,'*'):-1:1))
-
+   if attenu<>[]
+     for i = 1:prod(size(attenu)),
+       att=attenu(i);
+       if att<0 then 
+        w=%eps:0.03:%pi;
+       else 
+        w=-%pi:0.03:0;
+       end;
+       n=prod(size(w))
+       rf=centre(i)*ones(w)+rayon(i)*exp(%i*w);
+       phi=atan(imag(rf),real(rf))/ratio; //phi is in [-180 0]
+       module=20*log(abs(rf))/l10;
+       
+       //use symetry and period to extend the curve on [k1*180 k2*180]
+       p=[];m=[];
+       S=[]
+       for k=k1:k2-1
+        if pmodulo(k,2)==0 then
+          p=[p %nan k*180-phi($:-1:1)]
+          m=[m %nan module($:-1:1)]
+          if att>0 then 
+            xstring(p($),m($),string(att),0,0),
+            e=gce();e.clip_state='off';
+            S=[e S]
+          end
+        else
+          p=[p %nan ((k+1)*180)+phi]
+          m=[m %nan module]
+          if att<0 then 
+            xstring(p($),m($),string(att),0,0),
+            e=gce();e.clip_state='off';
+            S=[e S]
+          end
+        end
+        
+       end
+       xpoly(p,m)
+       e=gce();e.foreground=flags(3);//e.line_style=3,
+       if size(S,'*')>1 then S=glue(S),end
+       S=glue([S,e]);S.user_data=att;
+     end;
+     glue(ax.children(size(attenu,'*'):-1:1))
+   end
   //isophase curves
+  if angl<>[] then
   eps=100*%eps;
   for teta=angl,
     if teta < -%pi/2 then
@@ -152,5 +154,6 @@ function chart(attenu,angl,flags)
     e.user_data=teta
   end;
   glue(ax.children(size(angl,'*'):-1:1))
+  end
   drawnow() ;
 endfunction
index 4ba0f61..1e06229 100644 (file)
@@ -19,21 +19,23 @@ function [s1]=cls2dls(s,t,fp)
 // fp prevarping frequency in hertz
 //!
 
-[lhs,rhs]=argn(0)
-
-if type(s)<>16 then error(91,1),end
-flag=s(1); 
-if flag(1)<>'lss' then error(91,1),end
-if s(7)==[] then warning(msprintf(gettext("%s: s is assumed continuous time.\n"),"cls2dls"));s(7)='c';end
-if s(7)<>'c'|s(7)=='d' then
-  warning(msprintf(gettext("%s: Needs a continuous system as input.\n"),"cls2dls"))
-end
-fs=1/t 
-if rhs==3 then fp=2*%pi*fp;fs=fp/tan(fp/fs/2)/2,end //prewarping
-a=2*fs*eye()-s(2)
-ad=a\(2*fs*eye()+s(2))
-b=(ad+eye())/a*s(3);
-d=s(5)+s(4)/a*s(3)
-s1=syslin('d',ad,b,s(4),d,s(6))
+  [lhs,rhs]=argn(0)
+  if typeof(s)<>'state-space'
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"cls2dls",1))
+  end
+  if s.dt==[] then 
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"cls2dls",1));
+    s.dt='c';
+  end
+  if s.dt<>'c' then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Continuous time system expected.\n"),"cls2dls",1))
+  end
+  fs=1/t 
+  if rhs==3 then fp=2*%pi*fp;fs=fp/tan(fp/fs/2)/2,end //prewarping
+  
+  a=2*fs*eye()-s(2)
+  ad=a\(2*fs*eye()+s(2))
+  b=(ad+eye())/a*s(3);
+  d=s(5)+s(4)/a*s(3)
+  s1=syslin('d',ad,b,s(4),d,s(6))
 endfunction
index deebaaa..bb9c7e2 100644 (file)
@@ -13,19 +13,30 @@ function c=cont_mat(a,b)
 //                 2       n
 //i.e. c=[b, ab, ab,...; ab ]  
 //!
-[lhs,rhs]=argn(0)
-select type(a)
- case 1  then
-    if rhs==1 then error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"cont_mat",2)),end
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'constant'  then
+    if rhs==1 then 
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"cont_mat",2)),
+    end
     [m,n]=size(a)
     if m<>n then error(20,1),end
-    [mb,nb]=size(b);if mb<>n then error(60),end
+    [mb,nb]=size(b);
+    if mb<>n then error(60),end
 
- case 16 then
-    if a(1)<>'lss' then error(91,1),end
+  case 'state-space' then
+    if rhs==2 then 
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"cont_mat",1)),
+    end
     [a,b]=a([2,3])
     [n,n]=size(a)  
- else error(msprintf(gettext("%s: Wrong type of input arguments: %s,%s pair or syslin list.\n"),"cont_mat","a","b"))
-end;
-c=b;for k=1:n-1, c=[b,a*c],end
+  else 
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"cont_mat",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"cont_mat",1))
+    end
+
+  end;
+  c=b;for k=1:n-1, c=[b,a*c],end
 endfunction
index 554bb0c..420aae3 100644 (file)
@@ -9,19 +9,21 @@
 
 function slc=contrss(a,tol)
 
-[lhs,rhs]=argn(0)
-//
-flag=a(1);
- if flag(1)<>'lss' then
-     error(91,1),
- end;
-if rhs==1 then tol=sqrt(%eps);end
-if rhs>2 then error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"contrss",1,2))
- end;
- [a,b,c,d,x0,dom]=a(2:7)
-//
-[nc,u]=contr(a,b,tol*norm([a,b],1))
-u=u(:,1:nc)
-a=u'*a*u;b=u'*b;c=c*u
-slc=syslin(dom,a,b,c,d,u'*x0)
+  [lhs,rhs]=argn(0)
+  //
+  flag=a(1);
+  if flag(1)<>'lss' then
+    error(91,1),
+  end;
+  if rhs==1 then tol=sqrt(%eps);end
+  if rhs>2 then 
+    error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"contrss",1,2))
+  end;
+
+  [a,b,c,d,x0,dom]=a(2:7)
+  //
+  [nc,u]=contr(a,b,tol*norm([a,b],1))
+  u=u(:,1:nc)
+  a=u'*a*u;b=u'*b;c=c*u
+  slc=syslin(dom,a,b,c,d,u'*x0)
 endfunction
index fce5357..51a665c 100644 (file)
@@ -29,7 +29,7 @@ function [n,m,xt,yt]=copfac(g,polf,polc,tol)
     g=tf2ss(g)
   case "state-space" then
   else
-    error(msprintf(gettext("%s: Wrong type for argument #%d: Linear dynamic system expected.\n"),"copfac",1))
+    error(msprintf(_("%s: Wrong type for input argument #%d: %s data structure expected.\n"),"copfac",1,"syslin"));
   end
   [r,p,t]=size(g);
   [a,b,c,d]=g(2:5),
@@ -46,7 +46,7 @@ function [n,m,xt,yt]=copfac(g,polf,polc,tol)
     w1=u1(:,n1+1:t),a1=w1'*a*w1,
     no=norm(a1),
     if maxi(real(spec(a1)))>no*tol then
-      error(msprintf(gettext("%s: System is not stabilizable.\n"),"copfac")),
+      error(msprintf(gettext("%s: Wrong values for input argument #%d: Stabilizable system expected.\n"),"copfac",1)),
     end,
   end,
   //------------------
@@ -54,7 +54,7 @@ function [n,m,xt,yt]=copfac(g,polf,polc,tol)
     w2=u2(:,n2+1:t),a2=w2'*a*w2,
     no=norm(a2),
     if maxi(real(spec(a2)))>no*tol then
-      error(msprintf(gettext("%s: System is not detectable.\n'),"copfac")),
+      error(msprintf(gettext("%s: Wrong values for input argument #%d: Detectable system expected.\n"),"copfac",1)),
     end,
   end,
   //-----------------------------
index e1dd094..08e0c57 100644 (file)
@@ -43,18 +43,20 @@ function [y,x]=csim(u,dt,sl,x0,tol)
   [lhs,rhs]=argn(0)
   //
   if rhs<3 then error(39),end
-
-  if type(sl)<>16 then error(56,1),end
-  flag=sl(1)
-  select flag(1)
-  case 'lss' then ,
-  case  'r'  then sl=tf2ss(sl)
-  else  error(97,1),
-  end;
-  if sl(7)<>'c' then warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"csim")),end
+  sltyp=typeof(sl)
+  if and(sltyp<>['state-space' 'rational']) then 
+    error(msprintf(_("%s: Wrong type for input argument #%d: %s data structure.\n"),"csim",3,"syslin"))
+  end
+  if sltyp=='rational' then sl=tf2ss(sl),end
+  if sl.dt<>'c' then 
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"csim",1));
+  end
   //
   [a,b,c,d]=sl(2:5);
-  if type(d)==2&degree(d)>0 then d=coeff(d,0);warning(msprintf(gettext("csim: %s set to constant.\n"),"csim","D"));end
+  if type(d)==2&degree(d)>0 then 
+    d=coeff(d,0);
+    warning(msprintf(gettext("%s: Direct feedthrough set to its zero degree coefficient.\n"),"csim"));
+  end
   [ma,mb]=size(b);
   //
   imp=0;text='if t==0 then y=0, else y=1,end'
@@ -66,13 +68,13 @@ function [y,x]=csim(u,dt,sl,x0,tol)
       //impuse response
       imp=1;
       if norm(d,1)<>0 then
-       warning(msprintf(gettext("%s: Direct feedthrough %s <> %d;set to zero.\n"),"csim","(d)",0));
+       warning(msprintf(gettext("%s: Direct feedthrough set to zero.\n"),"csim"));
        d=0*d;
       end;
     elseif part(u,1)=='s' then
       //step response
     else
-      error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"csim",1,"step","impuls"))
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"csim",1,"""step"",""impuls"""))
     end;
     deff('[y]=u(t)',text);
   case 11 then //input given by a function of time
@@ -80,7 +82,9 @@ function [y,x]=csim(u,dt,sl,x0,tol)
   case 13 then //input given by a function of time
   case 1 then //input given by a vector of data
     [mbu,ntu]=size(u);
-    if mbu<>mb | ntu<>size(dt,'*') then error(msprintf(gettext("%s: Wrong size for input argument #%d.\n"),"csim",1)), end
+    if mbu<>mb | ntu<>size(dt,'*') then 
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),"csim",1,2))
+    end
   case 15 then  //input given by a list: function of time with parameters
     uu=u(1),
     if type(uu)==11 then 
index 6b37fa9..610c1ed 100644 (file)
 function [gc]=ctr_gram(a,b,domaine)
 //!
 
-[lhs,rhs]=argn(0)
-select type(a)
-case 1  then
-  if rhs<2 then error(39); end;
-  if rhs==2 then domaine='c'; end;
-  if part(domaine,1)<>'c' then domaine='d',end
-  [m,n]=size(a)
-  if m<>n then error(20,1),end
-  [mb,nb]=size(b);if mb<>n then error(60),end
-case 16 then
-  flag=a(1);
-  if flag(1)=='r' then a=tf2ss(a);end
-  if flag(1)<>'lss' then error(91,1),end
-  [a,b,domaine]=a([2,3,7])
-  if domaine==[] then
-    write(%io(2),msprintf(gettext("%s: By default time-domain is continuous.\n"),"ctr_gram"))
-    domaine='c';
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'constant' then
+    if rhs<2 then error(39); end;
+    if rhs==2 then 
+      domaine='c'; 
+    else
+      if and(domaine<>['d','c']) then
+       error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "ctr_gram",3,"''d'', ''c''"));
+      end
+    end;
+    [m,n]=size(a)
+    if m<>n then error(20,1),end
+    [mb,nb]=size(b);if mb<>n then error(60),end
+  case 'state-space' then
+    if rhs>1 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"ctr_gram",1)),
+    end
+    [a,b,domaine]=a([2,3,7])
+    if domaine==[] then
+      warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"ctr_gram",1));
+      domaine='c';
+    elseif type(domaine)==1 then 
+      domaine='d',
+    end
+    [n,n]=size(a) 
+  case 'rational' then
+    if rhs>1 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"ctr_gram",1)),
+    end
+    a=tf2ss(a)
+    [a,b,domaine]=a([2,3,7])
+    if domaine==[] then
+      warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"ctr_gram",1));
+      domaine='c';
+    elseif type(domaine)==1 then 
+      domaine='d',
+    end
+    [n,n]=size(a) 
+  else 
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"ctr_gram",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"ctr_gram",1))
+    end
   end
-  [n,n]=size(a)    
-else 
-  error(msprintf(gettext("%s: (a,b) pair or syslin state-space.\n"),"ctr_gram"))
-end
-s=spec(a)
-if part(domaine,1)=='c' then
-  if maxi(real(s))>=0 then error(msprintf(gettext("%s: Unstable system.\n"),"ctr_gram")),end
-else
-  if maxi(abs(s))>=1 then error(msprintf(gettext("%s: Unstable system.\n"),"ctr_gram")),end
-end
-gc=lyap(a',-b*b',domaine)
+  s=spec(a)
+  if (domaine=='c'&maxi(real(s))>=0)|(domaine=='d'&maxi(abs(s))>=1) then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Stable system expected.\n"),"ctr_gram",1));
+  end
+  gc=lyap(a',-b*b',domaine)
 endfunction
index 3cc0464..d1af812 100644 (file)
@@ -47,45 +47,50 @@ function [Closed,F,G]=ddp(Sys,zeroed,B1,D1,flag,Alfa,Beta)
 // Stability (resp. pole placement) requires stabilizability 
 // (resp. controllability) of (A,B2).
 //
-[LHS,RHS]=argn(0);
-if RHS==5 then Beta=-1;end
-if RHS==4 then Beta=-1;Alfa=-1;end
-if RHS==3 then Beta=-1;Alfa=-1;flag='st';end
-if RHS==2 then Beta=-1;Alfa=-1;flag='st';D1=zeros(size(Sys('C'),1),size(B1,2));
-end
-if size(B1,1) ~= size(Sys('A'),1) then error(msprintf(gettext("%s: Wrong size for input arguments: %s and %s are not compatible.\n"),"ddp","B1","A"));end
-if size(D1,2) ~= size(B1,2) then error(msprintf(gettext("%s: Wrong size for input arguments: %s and %s are not compatible.\n"),"ddp","D1","B1"));end
-Sys1=Sys(zeroed,:);
-not_zeroed=1:size(Sys,1);not_zeroed(zeroed)=[];
-[X,dims,F,U,k,Z]=abinv(Sys1,Alfa,Beta,flag);nv=dims(3);
-Sys_new=ss2ss(Sys,X);Fnew=F*X;
-B1new=X'*B1;B2new=Sys_new('B');
-D11=D1(zeroed,:);D12=Sys1('D');
-B21=B1new(nv+1:$,:);B22=B2new(nv+1:$,:);
-// G s.t. B21+B22*G=0        D11+D12*G=0
-G=lowlev();
+  [LHS,RHS]=argn(0);
+  if RHS==5 then Beta=-1;end
+  if RHS==4 then Beta=-1;Alfa=-1;end
+  if RHS==3 then Beta=-1;Alfa=-1;flag='st';end
+  if RHS==2 then Beta=-1;Alfa=-1;flag='st';D1=zeros(size(Sys('C'),1),size(B1,2));
+  end
+  if size(B1,1) ~= size(Sys('A'),1) then
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same row dimensions expected.\n"),"ddp",1,3))
+  end
+  if size(D1,2) ~= size(B1,2) then 
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same row dimensions expected.\n"),"ddp",3,4))
+  end
+  Sys1=Sys(zeroed,:);
+  not_zeroed=1:size(Sys,1);not_zeroed(zeroed)=[];
+  [X,dims,F,U,k,Z]=abinv(Sys1,Alfa,Beta,flag);nv=dims(3);
+  Sys_new=ss2ss(Sys,X);Fnew=F*X;
+  B1new=X'*B1;B2new=Sys_new('B');
+  D11=D1(zeroed,:);D12=Sys1('D');
+  B21=B1new(nv+1:$,:);B22=B2new(nv+1:$,:);
+  // G s.t. B21+B22*G=0        D11+D12*G=0
+  G=lowlev();
 
-[Anew,Bnew,Cnew,Dnew]=abcd(Sys_new);
-Anew=Anew+B2new*Fnew;Cnew=Cnew+Dnew*Fnew;
-B1new=B1new+B2new*G;
-A11=Anew(1:nv,1:nv);C21=Cnew(not_zeroed,1:nv);
-B11=B1new(1:nv,:);D21=D1(not_zeroed,:);
-D22=Sys('D');D22=D22(not_zeroed,:);D21=D21+D22*G;
-Closed=syslin(Sys('dt'),A11,B11,C21,D21);
+  [Anew,Bnew,Cnew,Dnew]=abcd(Sys_new);
+  Anew=Anew+B2new*Fnew;Cnew=Cnew+Dnew*Fnew;
+  B1new=B1new+B2new*G;
+  A11=Anew(1:nv,1:nv);C21=Cnew(not_zeroed,1:nv);
+  B11=B1new(1:nv,:);D21=D1(not_zeroed,:);
+  D22=Sys('D');D22=D22(not_zeroed,:);D21=D21+D22*G;
+  Closed=syslin(Sys('dt'),A11,B11,C21,D21);
 
 
 endfunction
+
 function G=lowlev()
-ww=[B21 B22;D11 D12];
-[xx,dd]=colcomp(ww);
-K=kernel(ww);
-rowG=size(B22,2);colG=size(B1,2);
-if size(K,2) > colG then K=K(:,1:colG);end
-Kup=K(1:size(K,2),:);
-if rcond(Kup) <= 1.d-10 then 
-       warning(msprintf(gettext("%s: Bad conditioning.\n"),"ddp"));
-       K1=K*pinv(Kup);G=K1(size(K,2)+1:$,:);return
-end
-K1=K*inv(Kup);   //test conditioning here!
-G=K1(size(K,2)+1:$,:);
+  ww=[B21 B22;D11 D12];
+  [xx,dd]=colcomp(ww);
+  K=kernel(ww);
+  rowG=size(B22,2);colG=size(B1,2);
+  if size(K,2) > colG then K=K(:,1:colG);end
+  Kup=K(1:size(K,2),:);
+  if rcond(Kup) <= 1.d-10 then 
+    warning(msprintf(gettext("%s: Bad conditioning.\n"),"ddp"));
+    K1=K*pinv(Kup);G=K1(size(K,2)+1:$,:);return
+  end
+  K1=K*inv(Kup);   //test conditioning here!
+  G=K1(size(K,2)+1:$,:);
 endfunction
index 5e4e998..ea5ba51 100644 (file)
 function [Bfs,Bis,tf]=des2tf(des)
 //des admits a D matrix.
 
-[LHS,RHS]=argn(0);
-if LHS<>1 & LHS<> 3 then error(msprintf(gettext("%s: Wrong number of output arguments: %d or %d expected.\n"), "des2tf",1,3)); end
-[A,B,C,D,E]=des(2:6);
-[Bfs,Bis,chis]=glever(E,A);
-if LHS==3 then Bfs=C*Bfs*B; Bis=C*Bis*B+D;tf=chis;return;end
-if LHS==1 then ww=C*Bfs*B;Bfs=ww/chis-C*Bis*B+D;return;end
+  [LHS,RHS]=argn(0);
+  if LHS<>1 & LHS<> 3 then 
+    error(msprintf(gettext("%s: Wrong number of output arguments: %d or %d expected.\n"), "des2tf",1,3)); 
+  end
+  [A,B,C,D,E]=des(2:6);
+  [Bfs,Bis,chis]=glever(E,A);
+  if LHS==3 then Bfs=C*Bfs*B; Bis=C*Bis*B+D;tf=chis;return;end
+  if LHS==1 then ww=C*Bfs*B;Bfs=ww/chis-C*Bis*B+D;return;end
 endfunction
index 4e01fea..cddbfc1 100644 (file)
 
 function [f,r]=dscr(a,dt,m)
 
-[lhs,rhs]=argn(0);lst=0
-if type(dt)<>1 then
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: A positive real expected.\n"),"dscr",2))
-end
-if size(dt,'*')<>1|~isreal(dt)|dt<=0 then
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: A positive real expected.\n"),"dscr",2))
-end
+  [lhs,rhs]=argn(0);
+  if type(dt)<>1 then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"),"dscr",2))
+  end
+  if size(dt,'*')<>1 then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: A scalar expected.\n"),"dscr",2))
+  end
+  if ~isreal(dt) then
+    error(msprintf(gettext("%s: Input argument #%d must be real.\n"),"dscr",2))
+  end
 
-flag=a(1);
-select flag(1)
-case 'r' then
-  a=tf2ss(a);
-  [a,b,c,d,x0,dom]=a(2:7);
-case 'lss' then
-  [a,b,c,d,x0,dom]=a(2:7)
-else 
-  error(97,1),
-end;
-if dom<>'c' then 
-  warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"dscr")),
-end
-[n1,m1]=size(b),
-s=expm([a,b;0*ones(m1,n1+m1)]*dt),
-f=s(1:n1,1:n1);g=s(1:n1,n1+1:n1+m1);
-if rhs==3 then
-  s=expm([-a,m;0*a a']*dt),
-  r=f*s(1:n1,n1+1:n1+n1),
-end;
-f=syslin(dt,f,g,c,d,x0)
+  if dt<=0 then
+    error(msprintf(gettext("%s: Input argument #%d must be strictly positive.\n"),"dscr",2))
+  end
+
+  select typeof(a)
+  case 'rational' then
+    a=tf2ss(a);
+    [a,b,c,d,x0,dom]=a(2:7);
+  case 'state-space' then
+    [a,b,c,d,x0,dom]=a(2:7)
+  else 
+    error(97,1),
+  end;
+  if dom<>'c' then 
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"dscr",1))
+  end
+  [n1,m1]=size(b),
+  s=expm([a,b;0*ones(m1,n1+m1)]*dt),
+  f=s(1:n1,1:n1);g=s(1:n1,n1+1:n1+m1);
+  if rhs==3 then
+    s=expm([-a,m;0*a a']*dt),
+    r=f*s(1:n1,n1+1:n1+n1),
+  end;
+  f=syslin(dt,f,g,c,d,x0)
 endfunction
index 6aa71da..3da32b1 100644 (file)
@@ -20,105 +20,116 @@ function [ga,gs,gi]=dtsi(g,tol)
 // Default value: 100*%eps
 //!
 
-g1=g(1);
-[lhs,rhs]=argn(0),
-if rhs==1 then tol=100*%eps,end,
-if g1(1)=='r' then
-  //transfer
-  //----------------------------
-  num=g(2),den=g(3),var=varn(den),
-  [t1,t2]=size(num),
-  num1=0*ones(t1,t2),num2=num1,
-  den1=ones(t1,t2),den2=den1,
-  for i=1:t1,
-    for j=1:t2,
-      n=num(i,j),d=den(i,j),
-      dn=degree(n),dd=degree(d),
-      if dn>dd then error(msprintf(gettext("%s: Degree num. > degree den.\n"),"dtsi")),end,
-      //alf and bet /alf*d1(unstable) and bet*d2(stable)=n.
-      if dd==0 then 
-        num2(i,j)=n,
-      else
-        pol=roots(d),
-        k=1,no=1,
-        [a,l]=sort(real(pol)),pol=pol(l),
-        while k<=dd,
-          if real(pol(k))<=tol then 
-            k=dd+1,
-          else
-            k=k+1,no=no+1,
-          end,
-        end,
-        select no,
-        case 1 then num2(i,j)=n,den2(i,j)=d,
-        case dd+1 then num1(i,j)=n,den1(i,j)=d,
-        else
-          d1=poly(pol(1:no-1),var),d2=poly(pol(no:dd),var),
-          if dn==dd then 
-            d1o=poly([coeff(d1),0],var,'c'),
-            dd=dd+1,no=no+1,
-          else
-            d1o=d1,
-          end
-          u=sylm(d1o,d2),cn=[coeff(n),0*ones(1,dd-dn-1)],
-          x=u\cn',
-          alf=poly(x(1:dd-no+1),var,'c'),
-          bet=poly(x(dd-no+2:dd),var,'c'),
-          num1(i,j)=bet,den1(i,j)=d1,
-          num2(i,j)=alf,den2(i,j)=d2,
-        end,
+  g1=g(1);
+  [lhs,rhs]=argn(0),
+  if rhs==1 then tol=100*%eps,end,
+  select typeof(g)
+  case 'rational' then
+    //transfer
+    //----------------------------
+    num=g(2),den=g(3),var=varn(den),
+    [t1,t2]=size(num),
+    num1=0*ones(t1,t2),num2=num1,
+    den1=ones(t1,t2),den2=den1,
+    for i=1:t1,
+      for j=1:t2,
+       n=num(i,j),d=den(i,j),
+       dn=degree(n),dd=degree(d),
+       if dn>dd then
+         error(msprintf(gettext("%s: Wrong values for input argument #%d: proper elements expected.\n"),"dtsi",1))
+       end,
+       //alf and bet /alf*d1(unstable) and bet*d2(stable)=n.
+       if dd==0 then 
+         num2(i,j)=n,
+       else
+         pol=roots(d),
+         k=1,no=1,
+         [a,l]=sort(real(pol)),pol=pol(l),
+         while k<=dd,
+           if real(pol(k))<=tol then 
+             k=dd+1,
+           else
+             k=k+1,no=no+1,
+           end,
+         end,
+         select no,
+         case 1 then num2(i,j)=n,den2(i,j)=d,
+         case dd+1 then num1(i,j)=n,den1(i,j)=d,
+         else
+           d1=poly(pol(1:no-1),var),d2=poly(pol(no:dd),var),
+           if dn==dd then 
+             d1o=poly([coeff(d1),0],var,'c'),
+             dd=dd+1,no=no+1,
+           else
+             d1o=d1,
+           end
+           u=sylm(d1o,d2),cn=[coeff(n),0*ones(1,dd-dn-1)],
+           x=u\cn',
+           alf=poly(x(1:dd-no+1),var,'c'),
+           bet=poly(x(dd-no+2:dd),var,'c'),
+           num1(i,j)=bet,den1(i,j)=d1,
+           num2(i,j)=alf,den2(i,j)=d2,
+         end,
+       end,
       end,
     end,
-  end,
-  ga=syslin('c',num1,den1),gs=syslin('c',num2,den2),
-  gi1=ginfini(ga),gi2=ginfini(gs),
-  ga=ga-gi1,gs=gs-gi2,gi=gi1+gi2,return,
-else
-  //state space:
-  //---------------------------
-  [a,b,c,d]=g(2:5),gi=d,
-  [n1,n2,t]=size(g),
-  [a,u0]=balanc(a);b=u0\b;c=c*u0;
-  [u,n]=schur(a,'c'),
-  a=u'*a*u,
-  if n==t then ga=0,
-    gs=g,return,
-  end,
-  if n==0 then gs=0,
-    ga=g,return,
-  end,
-  //      [ab,w,bs]=bdiag(a);
-  a1=a(1:n,1:n),a4=a(n+1:t,n+1:t),x=a(1:n,n+1:t),
-  z=sylv(a1,-a4,-x,'c'),
-  w=[eye(n,n),z;0*ones(t-n,n),eye(t-n,t-n)],
-  wi=[eye(n,n),-z;0*ones(t-n,n),eye(t-n,t-n)],
-  tr=u*w,tri=wi*u';
-  bb=tri*b,b1=bb(1:n,:),b2=bb(n+1:t,:),
-  cc=c*tr,c1=cc(:,1:n),c2=cc(:,n+1:t),
-  ga=syslin('c',a4,b2,c2),
-  gs=syslin('c',a1,b1,c1);
-end;
+    ga=syslin('c',num1,den1),gi1=ginfini(ga)
+    gs=syslin('c',num2,den2),gi2=ginfini(gs)
+    
+    ga=ga-gi1,gs=gs-gi2,gi=gi1+gi2,return,
+  case 'state-space' then
+    //state space:
+    //---------------------------
+    [a,b,c,d]=g(2:5),gi=d,
+    [n1,n2,t]=size(g),
+    [a,u0]=balanc(a);b=u0\b;c=c*u0;
+    [u,n]=schur(a,'c'),
+    a=u'*a*u,
+    if n==t then 
+      ga=0,
+      gs=g,
+      return,
+    end,
+    if n==0 then 
+      gs=0,
+      ga=g,
+      return,
+    end,
+    //      [ab,w,bs]=bdiag(a);
+    a1=a(1:n,1:n),a4=a(n+1:t,n+1:t),x=a(1:n,n+1:t),
+    z=sylv(a1,-a4,-x,'c'),
+    w=[eye(n,n),z;0*ones(t-n,n),eye(t-n,t-n)],
+    wi=[eye(n,n),-z;0*ones(t-n,n),eye(t-n,t-n)],
+    tr=u*w,tri=wi*u';
+    bb=tri*b,b1=bb(1:n,:),b2=bb(n+1:t,:),
+    cc=c*tr,c1=cc(:,1:n),c2=cc(:,n+1:t),
+    ga=syslin('c',a4,b2,c2),
+    gs=syslin('c',a1,b1,c1);
+  else
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"dtsi",1))
+  end;
 
 endfunction
+
 function D=ginfini(g)
 //gi=ginfini(g) computes D = g(infinity) for the proper transfer matrix g
 //!
-g1=g(1);
-if type(g)==1 then D=g,return,end,
-if g1(1)<>'r' then error(90,1),end
-num=g(2),den=g(3),
-[nn,mm]=size(num),D=0*ones(nn,mm),
-for i=1:nn,
-  for j=1:mm,
-    n=num(i,j),d=den(i,j),
-    dn=degree(n),dd=degree(d),
-    if dn>dd then 
-      error(msprintf(gettext("%s: Improper system.\n"),"dtsi")),
-    else
-      if dn==dd then
-        D(i,j)=coeff(n,dn)/coeff(d,dd)
-      end,
+  g1=g(1);
+  if type(g)==1 then D=g,return,end,
+  if g1(1)<>'r' then error(90,1),end
+  num=g(2),den=g(3),
+  [nn,mm]=size(num),D=0*ones(nn,mm),
+  for i=1:nn,
+    for j=1:mm,
+      n=num(i,j),d=den(i,j),
+      dn=degree(n),dd=degree(d),
+      if dn>dd then 
+       error(msprintf(gettext("%s: Wrong values for input argument #%d: Proper transfer function expected.\n"),"dtsi/ginfini",1 )),
+      else
+       if dn==dd then
+         D(i,j)=coeff(n,dn)/coeff(d,dd)
+       end,
+      end
     end
   end
-end
 endfunction
index 4338172..951575f 100644 (file)
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 
-function []=evans(n,d,kmax)
-       // Seuil maxi et mini (relatifs) de discretisation en espace
-       // Copyright INRIA
-       
-       smax=0.002;smin=smax/3;
-       nptmax=2000 //nbre maxi de pt de discretisation en k
-       
-       //analyse de la liste d'appel
-       
-       [lhs,rhs]=argn(0)
-       
-       if rhs <= 0 then   // demo
-               n=real(poly([0.1-%i 0.1+%i,-10],'s'));
-               d=real(poly([-1 -2 -%i %i],'s'));
-               evans(n,d,80);
-               return
-       end
+function evans(n,d,kmax)
+// Seuil maxi et mini (relatifs) de discretisation en espace
+// Copyright INRIA
+  
+  smax=0.002;smin=smax/3;
+  nptmax=2000 //nbre maxi de pt de discretisation en k
+  
+  //analyse de la liste d'appel
+  
+  [lhs,rhs]=argn(0)
+  
+  if rhs <= 0 then   // demo
+    n=real(poly([0.1-%i 0.1+%i,-10],'s'));
+    d=real(poly([-1 -2 -%i %i],'s'));
+    evans(n,d,80);
+    return
+  end
 
-select type(n)
-  case 1  then
+  select typeof(n)
+  case 'constant'  then
     if rhs==2 then kmax=0,end
-  case 2  then
+  case 'polynomial'  then
     if rhs==2 then kmax=0,end
-  //-compat next case retained for list/tlist compatibility
-  case 15 then
-     if rhs==2 then kmax=d,else kmax=0,end
-     n1=n(1);
-     select n1(1)
-        case 'r' then [n,d]=n(2:3)
-        case 'lss' then n=ss2tf(n);[n,d]=n(2:3);n=clean(n);d=clean(d);
-        else error('transfer or state-space only')
-       end
-  case 16 then
-     if rhs==2 then kmax=d,else kmax=0,end
-     n1=n(1);
-     select n1(1)
-        case 'r' then [n,d]=n(2:3)
-        case 'lss' then n=ss2tf(n);[n,d]=n(2:3);n=clean(n);d=clean(d);
-        else error('transfer or state-space only')
-     end
-  else error('transfer or state-space only')
-end
-if prod(size(n))<>1 then
-    error('SISO system only'),
-end
-if kmax<=0 then
-     nm=mini([degree(n),degree(d)])
-     fact=norm(coeff(d),2)/norm(coeff(n),2)
-     kmax=round(500*fact),
-end
-//
-//calcul de la discretisation en k et racines associees
-nroots=roots(n);racines=roots(d);
-if nroots==[] then
-  nrm=maxi([norm(racines,1),norm(roots(d+kmax*n),1)])
-else
-  nrm=maxi([norm(racines,1),norm(nroots,1),norm(roots(d+kmax*n),1)])
-end
-md=degree(d)
-//
-ord=1:md;kk=0;nr=1;k=0;pas=0.99;fin='no';
+    //-compat next case retained for list/tlist compatibility
+  case 'rational' then
+    if rhs==2 then kmax=d,else kmax=0,end
+    [n,d]=n(2:3)
+  case 'state-space' then
+    if rhs==2 then kmax=d,else kmax=0,end
+    n=ss2tf(n);
+    [n,d]=n(2:3);n=clean(n);d=clean(d);
+  else 
+     error(msprintf(gettext("%s: Wrong type for input argument #%d: A syslin data structure or a polynomial expected.\n"),"evans",1));
+  end
+  if prod(size(n))<>1 then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Single input, single output system expected.\n"),"evans",1));
+  end
+  if kmax<=0 then
+    nm=mini([degree(n),degree(d)])
+    fact=norm(coeff(d),2)/norm(coeff(n),2)
+    kmax=round(500*fact),
+  end
+  //
+  //calcul de la discretisation en k et racines associees
+  nroots=roots(n);racines=roots(d);
+  if nroots==[] then
+    nrm=maxi([norm(racines,1),norm(roots(d+kmax*n),1)])
+  else
+    nrm=maxi([norm(racines,1),norm(nroots,1),norm(roots(d+kmax*n),1)])
+  end
+  md=degree(d)
+  //
+  ord=1:md;kk=0;nr=1;k=0;pas=0.99;fin='no';
 
 
-while fin=='no' then
-  k=k+pas
-  r=roots(d+k*n);r=r(ord)
-  dist=maxi(abs(racines(:,nr)-r))/nrm
-  //
-  point='nok'
-  if dist <smax then //pas correct
-    point='ok'
-  else //pas trop grand ou ordre incorrect
-    // on cherche l'ordre qui minimise la distance
-    ix=1:md
-    ord1=[]
-    for ky=1:md
-      yy=r(ky)
-      mn=10*dist*nrm
-      for kx=1:md
-       if ix(kx)>0 then
-         if  abs(yy-racines(kx,nr)) < mn then
-           mn=abs(yy-racines(kx,nr))
-           kmn=kx
-         end
-       end
-      end
-      ix(kmn)=0
-      ord1=[ord1 kmn]
-    end
-    r(ord1)=r
+  while fin=='no' then
+    k=k+pas
+    r=roots(d+k*n);r=r(ord)
     dist=maxi(abs(racines(:,nr)-r))/nrm
-    if dist <smax then
-      point='ok',
-      ord(ord1)=ord
-    else
-      k=k-pas,pas=pas/2.5
+    //
+    point='nok'
+    if dist <smax then //pas correct
+      point='ok'
+    else //pas trop grand ou ordre incorrect
+        // on cherche l'ordre qui minimise la distance
+        ix=1:md
+        ord1=[]
+        for ky=1:md
+          yy=r(ky)
+          mn=10*dist*nrm
+          for kx=1:md
+            if ix(kx)>0 then
+              if  abs(yy-racines(kx,nr)) < mn then
+                mn=abs(yy-racines(kx,nr))
+                kmn=kx
+              end
+            end
+          end
+          ix(kmn)=0
+          ord1=[ord1 kmn]
+        end
+        r(ord1)=r
+        dist=maxi(abs(racines(:,nr)-r))/nrm
+        if dist <smax then
+          point='ok',
+          ord(ord1)=ord
+        else
+          k=k-pas,pas=pas/2.5
+        end
+    end
+    if dist<smin then
+      //pas trop petit
+      pas=2*pas;
+    end
+    if point=='ok' then
+      racines=[racines,r];kk=[kk,k];nr=nr+1
+      if k>kmax then fin='kmax',end
+      if nr>nptmax then fin='nptmax',end
     end
   end
-  if dist<smin then
-    //pas trop petit
-    pas=2*pas;
+  //draw the axis
+  x1 =[nroots;matrix(racines,md*nr,1)];
+  xmin=mini(real(x1));xmax=maxi(real(x1))
+  ymin=mini(imag(x1));ymax=maxi(imag(x1))
+  dx=abs(xmax-xmin)*0.05
+  dy=abs(ymax-ymin)*0.05
+  if dx<1d-10, dx=0.01,end
+  if dy<1d-10, dy=0.01,end
+  legs=[],lstyle=[];lhandle=[]
+  rect=[xmin-dx;ymin-dy;xmax+dx;ymax+dy];
+  f=gcf();
+  cur_im_dr= f.immediate_drawing;
+  f.immediate_drawing = 'off';
+  a=gca()
+  a.data_bounds=[rect(1) rect(2);rect(3) rect(4)]
+  if nroots<>[] then 
+    xpoly(real(nroots),imag(nroots))
+    e=gce();e.line_mode='off';e.mark_mode='on';
+    e.mark_size_unit="point";e.mark_size=7;e.mark_style=5;
+    legs=[legs; _("open loop zeroes")]
+    lhandle=[lhandle; e];
   end
-  if point=='ok' then
-    racines=[racines,r];kk=[kk,k];nr=nr+1
-    if k>kmax then fin='kmax',end
-    if nr>nptmax then fin='nptmax',end
+  if racines<>[] then 
+    xpoly(real(racines(:,1)),imag(racines(:,1)))
+    e=gce();e.line_mode='off';e.mark_mode='on';
+    e.mark_size_unit="point";e.mark_size=7;e.mark_style=2;
+    legs=[legs;_("open loop poles")]
+    lhandle=[lhandle; e];
   end
-end
-//draw the axis
-x1 =[nroots;matrix(racines,md*nr,1)];
-xmin=mini(real(x1));xmax=maxi(real(x1))
-ymin=mini(imag(x1));ymax=maxi(imag(x1))
-dx=abs(xmax-xmin)*0.05
-dy=abs(ymax-ymin)*0.05
-if dx<1d-10, dx=0.01,end
-if dy<1d-10, dy=0.01,end
-legs=[],lstyle=[];
-rect=[xmin-dx;ymin-dy;xmax+dx;ymax+dy];
-f=gcf();
-cur_im_dr= f.immediate_drawing;
-f.immediate_drawing = 'off';
-a=gca()
-a.data_bounds=[rect(1) rect(2);rect(3) rect(4)]
-if nroots<>[] then 
-  plot2d(real(nroots),imag(nroots),style=-5)
-  e=gce();e=e.children;e.mark_size_unit="point";e.mark_size=7;
-  legs=[legs 'open loop zeroes']
-end
-if racines<>[] then 
-  plot2d(real(racines(:,1)),imag(racines(:,1)),style=-2)
-  e=gce();e=e.children;e.mark_size_unit="point";e.mark_size=7;
-  legs=[legs,'open loop poles']
-end
 
-dx=maxi(abs(xmax-xmin),abs(ymax-ymin));
-//plot the zeros locations
+  dx=maxi(abs(xmax-xmin),abs(ymax-ymin));
+  //plot the zeros locations
 
 
-//computes and draw the asymptotic lines
-m=degree(n);q=md-m
-if q>0 then
-  la=0:q-1;
-  so=(sum(racines(:,1))-sum(nroots))/q
-  i1=real(so);i2=imag(so);
-  if prod(size(la))<>1 then
-    ang1=%pi/q*(ones(la)+2*la)
-    x1=dx*cos(ang1),y1=dx*sin(ang1)
-  else
-    x1=0,y1=0,
-  end
-  if md==2,
-    if coeff(d,md)<0 then
-      x1=0*ones(2),y1=0*ones(2)
-    end,
+  //computes and draw the asymptotic lines
+  m=degree(n);q=md-m
+  if q>0 then
+    la=0:q-1;
+    so=(sum(racines(:,1))-sum(nroots))/q
+    i1=real(so);i2=imag(so);
+    if prod(size(la))<>1 then
+      ang1=%pi/q*(ones(la)+2*la)
+      x1=dx*cos(ang1),y1=dx*sin(ang1)
+    else
+      x1=0,y1=0,
+    end
+    if md==2,
+      if coeff(d,md)<0 then
+       x1=0*ones(2),y1=0*ones(2)
+      end,
+    end;
+    if maxi(k)>0 then
+      xpoly(i1,i2);
+      e=gce();
+      legs=[legs;_("asymptotic directions")]
+      lhandle=[lhandle; e];
+      axes = gca();
+      axes.clip_state = "clipgrf";
+      for i=1:q,xsegs([i1,x1(i)+i1],[i2,y1(i)+i2]),end,
+      
+      axes.clip_state = "off";
+    end
   end;
-  if maxi(k)>0 then
-    plot2d(i1,i2,style=1);
-    legs=[legs,'asymptotic directions']
-    
-    axes = gca();
-    axes.clip_state = "clipgrf";
-    for i=1:q,xsegs([i1,x1(i)+i1],[i2,y1(i)+i2]),end,
-    
-    axes.clip_state = "off";
-  end
-end;
-
-//lieu de evans
-[n1,n2]=size(racines);
 
-plot2d(real(racines)',imag(racines)',style=2+(1:n2));
-legend(legs,1);
-xtitle('Evans root locus','Real axis','Imag. axis');
-f=gcf();
-if(cur_im_dr=="on") then f.immediate_drawing = 'on';end
-
-if fin=='nptmax' then
-  write(%io(2),'evans : too many points required')
-end
+  //lieu de evans
+  [n1,n2]=size(racines);
 
+  plot2d(real(racines)',imag(racines)',style=2+(1:n2));
+  legend(lhandle,legs,1);
+  xtitle(_("Evans root locus"),_("Real axis"),_("Imaginary axis"));
+  f=gcf();
+  if(cur_im_dr=="on") then f.immediate_drawing = 'on';end
 
+  if fin=='nptmax' then
+    warning(msprintf(gettext("%s: Curve truncated to the first %d discretization points.\n"),"evans",nptmax))
+  end
 endfunction
index 25b3a7c..d8de6dd 100644 (file)
@@ -106,7 +106,7 @@ function [sys,K,Q,Ry,S,rcnd]=findABCD(s,n,l,R,meth,nsmpl,tol,printw)
       error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"),"findABCD",1,6));
     end
   else
-       error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"),"findABCD",1,6));
+    error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"),"findABCD",1,6));
   end
   // 
   sys = syslin(1,A,B,C,D);
index 8d23550..44b0b1e 100644 (file)
@@ -57,7 +57,7 @@ if tol==[] then tol = 0;end
 if nin<5 then meth = 1;end
 if meth==[] then meth = 1;end
 if nin<4 then
-  error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"findAC",4));
+  error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"findAC",4,7));
 end
 // 
 // Compute system matrices A and C.
index 90d8dbb..ef11d34 100644 (file)
@@ -58,7 +58,7 @@ x0=[];B=[];D=[];V=[];rcnd=[];
 ni = nargin;
 nout = nargout;
 if ni<4 then
-  error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"findx0BD",4));
+  error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"findx0BD",4,8));
 end
 if nout<1 then
   error(msprintf(gettext("%s: Wrong number of output arguments: At least %d expected.\n"),"findx0BD",1));
index 02132fe..ab29947 100644 (file)
@@ -1,6 +1,6 @@
 
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
+// Copyright (C) INRIA - Serge Steer
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 
 function [y,xf]=flts(u,sl,x0)
 
-[lhs,rhs]=argn(0)
-if type(u)<>1 then error(53,1),end
-if rhs<=1 then error(39),end
-[nu,mu]=size(u)
+  [lhs,rhs]=argn(0)
+  if type(u)<>1 then error(53,1),end
+  if rhs<=1 then error(39),end
+  [nu,mu]=size(u)
 
-if type(sl)<>16 then error(97,2),end
-flag=sl(1);
-select flag(1)
-  case 'lss' then 
-    if rhs==2 then x0=sl(6),end
-    [nb,mb]=size(sl(3))
-    if mb<>nu then
-       error(60),
-    end;
-    select sl(7)
-     case 'c' then error(94,2),
-    end;
-    np=maxi(degree(sl(5)))
-    [xf,x]=ltitr(sl(2),sl(3),u(:,1:(mu-np)),x0)
-   if type(sl(5))==1 then
-      y=sl(4)*x+sl(5)*u
+  select typeof(sl)
+  case 'state-space' then 
+    if rhs==2 then x0=sl.X0,end
+    [nb,mb]=size(sl.B)
+    if mb<>nu then error(60),end;
+    if sl.dt=='c' then error(94,2),end;
+    np=maxi(degree(sl.D))
+    [xf,x]=ltitr(sl.A,sl.B,u(:,1:(mu-np)),x0)
+    D=sl.D
+    if type(D)==1 then
+      y=sl.C*x+D*u
     else
-      y=sl(4)*x+rtitr(sl(5),eye(sl(5)),u)
+      y=sl.C*x+rtitr(D,eye(D),u)
+    end
+  case 'rational'  then  
+    if lhs>1 then 
+      error(msprintf(gettext("%s: Wrong number of output argument: %d expected.\n"),"flts",1)),
     end
-   case 'r'  then  
-    if lhs>1 then error(msprintf(gettext("%s: Wrong number of output argument: %d expected.\"),"flts",1)),end
     [num,den]=sl(['num','den']);[ns,ne]=size(num)
-       select sl('dt')
-        case 'c' then error(94,2),
-       end;
+    if sl.dt=='c' then error(94,2),end;
     if ne<>nu then error(60), end;
     for l=1:1:ns,
-       pp=den(l,1);
-       for k=2:ne,[pg,uu]=bezout(pp,den(l,k)),pp=pp*uu(1,2),end
-       nden(l)=pp
-       for k=1:ne,nnum(l,k)=num(l,k)*pdiv(pp,den(l,k)),end,
+      pp=den(l,1);
+      for k=2:ne,[pg,uu]=bezout(pp,den(l,k)),pp=pp*uu(1,2),end
+      nden(l)=pp
+      for k=1:ne,nnum(l,k)=num(l,k)*pdiv(pp,den(l,k)),end,
     end;
     for l=1:ns, nm(l)=degree(nden(l))-maxi(degree(nnum(l,:))),end
     ly=mu+mini(nm)
     if rhs==3 then
-       [mx,nx]=size(x0);maxdgd=maxi(degree(nden))
-       if nx<maxdgd then
-         error(msprintf(gettext("%s: At least %s past values.\n"),"flts",string(maxdgd)))
-       end;
-       if mx<>ns+ne then error(60),end
+      [mx,nx]=size(x0);maxdgd=maxi(degree(nden))
+      if nx<maxdgd then
+       error(msprintf(gettext("%s: At least %s past values needed.\n"),"flts",string(maxdgd)))
+      end;
+      if mx<>ns+ne then error(60),end
     end;
-      y=0*ones(ns,ly);
+    y=0*ones(ns,ly);
     for l=1:ns
       ddl=degree(nden(l))
       dnl=maxi(degree(nnum(l,:)))
       lent=ly-ddl+dnl
       select rhs
-        case 2 then yl=rtitr(nnum(l,:),nden(l),u(:,1:lent));
-                    [nn,mm]=size(yl);
-                    y(l,1:mm)=yl;
-//                    y=y(:,1:lent);
-        case 3 then
-               up=x0(1:ne,maxdgd-ddl+1:maxdgd);
-               yp=x0(ne+l,maxdgd-ddl+1:maxdgd);
-               y(l,:)=rtitr(nnum(l,:),nden(l),u(:,1:lent),up,yp);
+      case 2 then yl=rtitr(nnum(l,:),nden(l),u(:,1:lent));
+       [nn,mm]=size(yl);
+       y(l,1:mm)=yl;
+       //                    y=y(:,1:lent);
+      case 3 then
+       up=x0(1:ne,maxdgd-ddl+1:maxdgd);
+       yp=x0(ne+l,maxdgd-ddl+1:maxdgd);
+       y(l,:)=rtitr(nnum(l,:),nden(l),u(:,1:lent),up,yp);
       end;
     end,
     l=size(y,2);
     y=y(:,1:min(mu,l));
-  else error(97,2)
-end;
+  else 
+    error(97,2)
+  end;
 endfunction
index d66b062..5e3696f 100644 (file)
@@ -1,6 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
-// Copyright (C) ENPC -
+// Copyright (C) INRIA - Serge Steer
+// Copyright (C) ENPC - 
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -12,124 +12,123 @@ function [best_h,best_w]=frep2tf(frq,repf,dg,dom,tols,weight)
 // iterative use of frep2tf_b jpc fd 1997 
 
 // Copyright INRIA
-[lhs,rhs]=argn(0);
-if rhs <= 3 then dom='c' ; end 
-if rhs <= 4 then 
-  rtol=1.e-2; atol=1.e-4, N=10;
-else 
-  rtol=tols(1);atol=tols(2);N=tols(3);
-end
-if dom==[] then dom='c';end 
-if dom=='d' then dom=1;end
-if rhs <=5  then
-  [h,err]=frep2tf_b(frq,repf,dg,dom);
-  best_w = [];
-else
-  [h,err]=frep2tf_b(frq,repf,dg,dom,weight);
-  best_w = weight;
-end
-best_h = h ;
-for k=1:N
-  if dom=='c' then   
-  //    weight=(1)./abs(freq(h('den'),1,%i*frq*2*%pi));
-    weight=(1)./horner(h('den'),%i*frq*2*%pi);
+  [lhs,rhs]=argn(0);
+  if rhs <= 3 then dom='c' ; end 
+  if rhs <= 4 then 
+    rtol=1.e-2; atol=1.e-4, N=10;
+  else 
+    rtol=tols(1);atol=tols(2);N=tols(3);
+  end
+  if dom==[] then dom='c';end 
+  if dom=='d' then dom=1;end
+  if rhs <=5  then
+    [h,err]=frep2tf_b(frq,repf,dg,dom);
+    best_w = [];
   else
-    weight=(1)./horner(h('den'),exp(dom*%i*frq*2*%pi));
+    [h,err]=frep2tf_b(frq,repf,dg,dom,weight);
+    best_w = weight;
+  end
+  best_h = h ;
+  for k=1:N
+    if dom=='c' then   
+      //    weight=(1)./abs(freq(h('den'),1,%i*frq*2*%pi));
+      weight=(1)./horner(h('den'),%i*frq*2*%pi);
+    else
+      weight=(1)./horner(h('den'),exp(dom*%i*frq*2*%pi));
+    end
+    [h,err1]=frep2tf_b(frq,repf,dg,dom,weight);
+    if ( (abs(err-err1) < rtol *err & err > err1 )| err1 < atol) then break;end;
+    if err1 < err then best_err = err1 ; best_h = h; end 
+    err=err1;
+    mprintf(gettext("%s: Iteration %s, error=%s.\n"), "frep2tf", part(string(k+1),1:5), string(err1));
   end
-  [h,err1]=frep2tf_b(frq,repf,dg,dom,weight);
-  if ( (abs(err-err1) < rtol *err & err > err1 )| err1 < atol) then break;end;
-  if err1 < err then best_err = err1 ; best_h = h; end 
-  err=err1;
-  write(%io(2),msprintf(gettext("%s: Iteration %s, error=%s.\n"), "frep2tf", string(k+1), string(err1)));
-end
 endfunction
 
 function [h,err]=frep2tf_b(frq,repf,dg,dom,weight)
 // steer, jpc, fd 1997 (Nov)
 //============================
-[lhs,rhs]=argn(0);
-// test the system type 'c' 'd' or dt 
-if rhs <= 3 then dom='c' ; end 
-if rhs <= 4 then weight=[];end 
-if dom==[] then dom='c';end 
-if dom=='d' then dom=1;end
-n=size(frq,'*');
-if dom=='c' then 
-  w=2*%i*%pi*matrix(frq,n,1);
-else
-  w=exp(2*%i*%pi*dom*matrix(frq,n,1));
-end 
-//initialization
-m=2*dg
-//We compute the linear system to be solved: 
-//w(k)=%i* frq(k)*2pi 
-//for k=1,n  sum(a_i*(w(k))^i,i=1,dg)
-//             -repf(k)*sum(b_i*(w(k))^i,i=1,dg) = 0 
-//with sum x_i = 1
-//building Van der monde matrix ( w_i^j ) i=1,n j=0:dg-1
-a1=w.*.[ones(1,dg)];
-//0.^0 is not accepted in Scilab....
-a1=[ones(n,1),a1.^(ones(n,1).*.[1:(dg)])];
-a2=a1; for k=1:n; a2(k,:)= -repf(k)*a2(k,:);end 
-a=[a1,a2];
-// Computing constraints
-// We impose N(i wk) - repfk D(i wk) =0 for k=imax
-// as follows:
-// N(i wk) = repfk*(1+%i*b)
-// D(i wk) = 1+%i*b
-// L*[x;b]=[repfk;1]
-// Least squ. pb is  min norm of [A,0] [x;b]
-//  under constraint         L*[x;b]=[repfk;1]              
-[rmax,imax]=maxi(abs(repf))
-L2=a(imax,1:dg+1);
-L=[zeros(L2),L2,%i;
-   L2,zeros(L2),repf(imax)*%i];
-BigL=[real(L);imag(L)]
-c=[1;repf(imax)];
-Bigc=[real(c);imag(c)];
-[ww,dim]=rowcomp(BigL);
-BigL=ww*BigL;Bigc=ww*Bigc;
-BigL=BigL(1:dim,:);Bigc=Bigc(1:dim,:);
+  [lhs,rhs]=argn(0);
+  // test the system type 'c' 'd' or dt 
+  if rhs <= 3 then dom='c' ; end 
+  if rhs <= 4 then weight=[];end 
+  if dom==[] then dom='c';end 
+  if dom=='d' then dom=1;end
+  n=size(frq,'*');
+  if dom=='c' then 
+    w=2*%i*%pi*matrix(frq,n,1);
+  else
+    w=exp(2*%i*%pi*dom*matrix(frq,n,1));
+  end 
+  //initialization
+  m=2*dg
+  //We compute the linear system to be solved: 
+  //w(k)=%i* frq(k)*2pi 
+  //for k=1,n  sum(a_i*(w(k))^i,i=1,dg)
+  //           -repf(k)*sum(b_i*(w(k))^i,i=1,dg) = 0 
+  //with sum x_i = 1
+  //building Van der monde matrix ( w_i^j ) i=1,n j=0:dg-1
+  a1=w.*.[ones(1,dg)];
+  //0.^0 is not accepted in Scilab....
+  a1=[ones(n,1),a1.^(ones(n,1).*.[1:(dg)])];
+  a2=a1; for k=1:n; a2(k,:)= -repf(k)*a2(k,:);end 
+  a=[a1,a2];
+  // Computing constraints
+  // We impose N(i wk) - repfk D(i wk) =0 for k=imax
+  // as follows:
+  // N(i wk) = repfk*(1+%i*b)
+  // D(i wk) = 1+%i*b
+  // L*[x;b]=[repfk;1]
+  // Least squ. pb is  min norm of [A,0] [x;b]
+  //  under constraint         L*[x;b]=[repfk;1]              
+  [rmax,imax]=maxi(abs(repf))
+  L2=a(imax,1:dg+1);
+  L=[zeros(L2),L2,%i;
+     L2,zeros(L2),repf(imax)*%i];
+  BigL=[real(L);imag(L)]
+  c=[1;repf(imax)];
+  Bigc=[real(c);imag(c)];
+  [ww,dim]=rowcomp(BigL);
+  BigL=ww*BigL;Bigc=ww*Bigc;
+  BigL=BigL(1:dim,:);Bigc=Bigc(1:dim,:);
 
-a=[a,zeros(size(a,1),1)];
-// auto renormalization : if weight is not given 
-if dom == 'c' then 
-  if weight==[] then
-       nn= sqrt(sum(abs(a).^2,'c'))+ones(n,1);
-       a=a./(nn*ones(1,size(a,2)));
-  end  
-end    
-// user given renormalization
-if weight<>[] then 
-  if size(frq,'*')<>size(weight,'*') then
-         error(msprintf(gettext("%s: Wrong type for input arguments: %s and %s must have same size.\n"),"frep2tf","frq", "weight"))
-         return;
+  a=[a,zeros(size(a,1),1)];
+  // auto renormalization : if weight is not given 
+  if dom == 'c' then 
+    if weight==[] then
+      nn= sqrt(sum(abs(a).^2,'c'))+ones(n,1);
+      a=a./(nn*ones(1,size(a,2)));
+    end        
+  end    
+  // user given renormalization
+  if weight<>[] then 
+    if size(frq,'*')<>size(weight,'*') then
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same numbers of elements expected.\n"),"frep2tf",1,5))
+    end
+    w1=weight(:)*ones(1,size(a,2));
+    a= w1.*a;
   end
-  w1=weight(:)*ones(1,size(a,2));
-  a= w1.*a;
-end
-BigA=[real(a);imag(a)];
-// Constraints BigL x =Bigc
-// 
-x=LSC(BigA,BigL,Bigc);
-x=x(1:$-1);
+  BigA=[real(a);imag(a)];
+  // Constraints BigL x =Bigc
+  // 
+  x=LSC(BigA,BigL,Bigc);
+  x=x(1:$-1);
 
-h=syslin(dom,poly(x(1:dg+1),'s','c'),poly([x((dg+2):$)],'s','c'))
-if lhs==2 then
- repf1=repfreq(h,frq);
- err = sum(abs(repf1(:)-repf(:)))/n;
-end
+  h=syslin(dom,poly(x(1:dg+1),'s','c'),poly([x((dg+2):$)],'s','c'))
+  if lhs==2 then
+    repf1=repfreq(h,frq);
+    err = sum(abs(repf1(:)-repf(:)))/n;
+  end
 endfunction
 
 function [x]=LSC(A,L,c)
 // Ax=0 Least sq. + Lx = c
-[W,rk]=colcomp(L);
-LW=L*W;
-Anew=A*W
-A1=Anew(:,1:($-rk))
-A2=Anew(:,($-rk+1:$));
-x2=inv(LW(:,$-rk+1:$))*c
-b= -A2*x2
-x1=A1\b
-x=W*[x1;x2]
+  [W,rk]=colcomp(L);
+  LW=L*W;
+  Anew=A*W
+  A1=Anew(:,1:($-rk))
+  A2=Anew(:,($-rk+1:$));
+  x2=inv(LW(:,$-rk+1:$))*c
+  b= -A2*x2
+  x1=A1\b
+  x=W*[x1;x2]
 endfunction
index a817239..d910be5 100644 (file)
@@ -17,7 +17,7 @@ function [gm,fr]=g_margin(h)
     error(97,1),
   end;
   if or(size(h)<>[1 1]) then 
-    error(msprintf(_("%s: input argument must be a SISO system"),"g_margin"))
+    error(msprintf(_("%s: Wrong size for input argument #%d: Single input, single output system expected"),"g_margin",1))
   end
   //
   eps=1.e-7;// threshold used for testing if complex numbers are real or pure imaginary
index c4e9b8c..86abf97 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) INRIA Serge Steer
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
@@ -13,56 +13,61 @@ function []=gainplot(varargin)
   else
     comments=[];
   end
-  fmax=[]
+  fname="gainplot";//for error messages
+
+  fmax=[];
   if or(typeof(varargin(1))==['state-space' 'rational']) then 
     //sys,fmin,fmax [,pas] or sys,frq
+    refdim=1 //for error message
     if rhs==1 then
       [frq,repf]=repfreq(varargin(1),1d-3,1d3)
     elseif rhs==2 then //sys,frq
       if size(varargin(2),2)<2 then
-       error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "gainplot",1,1))
+       error(msprintf(_("%s: Wrong size for input argument #%d: A 1-by-n array expected with n>%d.\n"),..
+                      fname,1,1))
       end
       [frq,repf]=repfreq(varargin(1:rhs))
     elseif or(rhs==(3:4)) then //sys,fmin,fmax [,pas]
       [frq,repf]=repfreq(varargin(1:rhs))
     else
-      error(msprintf(_("%s : Invalid call: sys,fmin,fmax [,pas] [,com]'),"gainplot"))
+       error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,1,5))
     end
     [phi,d]=phasemag(repf)
   elseif  type(varargin(1))==1 then 
     //frq,db,phi [,comments] or frq, repf [,comments]
+    refdim=2
     select rhs
     case 2 then //frq,repf
       frq=varargin(1);
       if size(frq,2)<2 then
        error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "gainplot",1,1))
+                      fname,1,1))
       end
       if size(frq,2)<>size(varargin(2),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "gainplot",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
  
       [phi,d]=phasemag(varargin(2))
     case 3 then  //frq,db,phi
       [frq,d]=varargin(1:rhs-1)
       if size(frq,2)<>size(d,2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "gainplot",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
     else 
-      error(msprintf(_("%s : Invalid call: frq, db,phi [,com] or frq,repf [,com]'),"gainplot"))
+      error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
     end
   else
-    error(msprintf(_("%s : Invalid argument #%d. It must be a linear"+..
-                    " dynamical system or a real array"),"gainplot",1))
+    error(msprintf(_("%s: Wrong type for input argument #%d:  Linear state space, transfer function "+.. 
+                    " or row vector of floats expected.\n"),fname,1))
   end;
 
   frq=frq';d=d'
   [n,mn]=size(d)
   if and(size(comments,'*')<>[0 mn]) then
-    error(msprintf(_("%s : Invalid dimension for argument #%d"),"gainplot",rhs+1))
+      error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),...
+                    fname,refdim,rhs+1))
   end
 
   //
@@ -80,6 +85,6 @@ function []=gainplot(varargin)
   if comments<>[] then 
     legend(comments)
   end
-  xtitle(' ','Hz','Db');
+  xtitle(' ',_("Frequency (Hz)"),_("Magnitude (Db)"));
   drawnow()
 endfunction
index 03f11b5..ae0d267 100644 (file)
@@ -21,68 +21,68 @@ function Gt=gtild(G,flag)
 // for discrete-time matrix polynomials
 //!
 
-[lhs,rhs]=argn(0)
-if rhs==1 then
-  if typeof(G)=='rational'
-    flag=G(4)
-   elseif typeof(G)=='state-space'
-    flag=G(7)
-   elseif typeof(G)=='polynomial'
-    flag=[]
+  [lhs,rhs]=argn(0)
+  if rhs==1 then
+    if typeof(G)=='rational'
+      flag=G(4)
+    elseif typeof(G)=='state-space'
+      flag=G(7)
+    elseif typeof(G)=='polynomial'
+      flag=[]
+    end
   end
-end
 
-select typeof(G)
-case 'polynomial'
-if flag=='c'
-  Gt=cp_tilde(G);return;
-elseif flag=='d'  
-  Gt=dp_tilde(G);
-elseif flag==[]
-  warning(msprintf(gettext("%s: Wrong value for input argument #%d: %s assumed.\n"),"gtild",2,"c"));
-  Gt=cp_tilde(G);return;
-end
+  select typeof(G)
+  case 'polynomial'
+    if flag=='c'
+      Gt=cp_tilde(G);return;
+    elseif flag=='d'  
+      Gt=dp_tilde(G);return;
+    elseif flag==[]
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+                    "gtild",2,"''c'', ''d''"));
+    end
 
-case 'rational'
-v=varn([G(2),G(3)]);s=poly(0,v);
-if flag=='c'
-    Gt=horner(G',-s);return;
-elseif flag=='d' 
-  Gt=horner(G',1/s);return;
-elseif flag==[]
-  warning(msprintf(gettext("%s: Wrong value for input argument #%d: %s assumed.\n"),"gtild",2,"c"));
-  Gt=cp_tilde(G);return;
-end
+  case 'rational'
+    v=varn([G(2),G(3)]);s=poly(0,v);
+    if flag=='c'
+      Gt=horner(G',-s);return;
+    elseif flag=='d' 
+      Gt=horner(G',1/s);return;
+    elseif flag==[]
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+                    "gtild",2,"''c'', ''d''"));
+    end
 
-case 'state-space'
-if flag==[] then dom=G(7);else dom=flag;end
-[A,B,C,D]=abcd(G);
-if dom=='c' then
-     if typeof(D)=='polynomial'
+  case 'state-space'
+    if flag==[] then dom=G(7);else dom=flag;end
+    [A,B,C,D]=abcd(G);
+    if dom=='c' then
+      if typeof(D)=='polynomial'
         Dp=horner(D,-poly(0,varn(D)));
         Gt=syslin(dom,-A',-C',B',Dp');return;
-     elseif typeof(D)=='constant'
+      elseif typeof(D)=='constant'
         Gt=syslin(dom,-A',-C',B',D');return
-     end
-elseif dom=='d'
-     if typeof(G(5))=='polynomial'
+      end
+    elseif dom=='d'
+      if typeof(G(5))=='polynomial'
         Dp=horner(D,1/poly(0,varn(D)));
        Dp=tf2ss(Dp);
        [A,B,C,D]=abcd(G');
        w=tlist(['des','A','B','C','D','E'],eye(A),B,C,0*C*B,A);
        z=poly(0,'z');zss=-tf2ss(z);zss(7)='d';
        Gt=zss*des2ss(w)+Dp';
-     elseif typeof(G(5))=='constant'
+      elseif typeof(G(5))=='constant'
         z=poly(0,'z');zss=-tf2ss(z);zss(7)='d';
         [A,B,C,D]=abcd(G');  //lazy way for transposition...
         w=tlist(['des','A','B','C','D','E'],eye(A),B,C,0*D,A);
         Gt=zss*des2ss(w)+D;   //-z*C*inv(I-z*A)*B + D
-     end
-end
-//
-case 'constant'
-Gt=G';return;
-end
+      end
+    end
+    //
+  case 'constant'
+    Gt=G';return;
+  end
 
 
 
@@ -90,22 +90,22 @@ endfunction
 function mpt=dp_tilde(mp)
 //mp(z) =  polynomial matrix 
 // mpt(i,j)= z^n*conj(mp(j,i))(1/z)
-[m,n]=size(mp),z=varn(mp)
-//max degree
-nmax=maxi(degree(mp));
-for i=1:m
-  for j=1:n
-    mpt(j,i)=poly(coeff(conj(mp(i,j)),nmax:-1:0),z,'c')
+  [m,n]=size(mp),z=varn(mp)
+  //max degree
+  nmax=maxi(degree(mp));
+  for i=1:m
+    for j=1:n
+      mpt(j,i)=poly(coeff(conj(mp(i,j)),nmax:-1:0),z,'c')
+    end
   end
-end
 
 endfunction
 function mpt=cp_tilde(mp)
 //mp(s) =  polynomial matrix 
 // mpt(i,j)= conj(mp(j,i))(s)
-s=poly(0,varn(mp));
-pr=real(mp);pi=imag(mp);
-mpt=horner(pr',-s);
-if pi==0*s then return;end
-mpt=mpt+%i*horner(pi',-s);
+  s=poly(0,varn(mp));
+  pr=real(mp);pi=imag(mp);
+  mpt=horner(pr',-s);
+  if pi==0*s then return;end
+  mpt=mpt+%i*horner(pi',-s);
 endfunction
index 0df13f0..31a6e5e 100644 (file)
@@ -15,39 +15,45 @@ function [nh]=h2norm(g,tol)
 //     2           |
 //                 /-00
 
-if type(g)==1,if norm(g)==0,nh=0,return,end,end,
-[lhs,rhs]=argn(0),
-if rhs==1 then tol=1000*%eps,end;
-g1=g(1);
-if g1(1)=='lss' then
-  if norm(g(5))>0 then error(msprintf(gettext("%s: Non zero D.\n"),"h2norm")),end;
-  sp=spec(g(2)),
-  if maxi(real(sp))>=-tol then
-     error(msprintf(gettext("%s: Unstable system.\n"),"h2norm"))
-  end,
-  w=obs_gram(g(2),g(4),'c'),
-  nh=abs(sqrt(sum(diag(g(3)'*w*g(3))))),return,
-else,
-  num=g(2),den=g(3),
-  s=poly(0,varn(den)),
-  [t1,t2]=size(num),
-  for i=1:t1,
-    for j=1:t2,
-      n=num(i,j),d=den(i,j),
-      if coeff(n)==0 then 
-       nh(i,j)=0,
-      else
-       if degree(n)>=degree(d) then
-         error(msprintf(gettext("%s: Improper system.\n"),"h2norm"))
-       end
-       pol=roots(d),
-       if maxi(real(pol))>-tol then
-       error(msprintf(gettext("%s: Unstable system.\n"),"h2norm")),end,
-       nt=horner(n,-s),dt=horner(d,-s),
-       nh(i,j)=residu(n*nt,d,dt),
-      end,
+  if type(g)==1,if norm(g)==0,nh=0,return,end,end,
+  [lhs,rhs]=argn(0),
+  if rhs==1 then tol=1000*%eps,end;
+  g1=g(1);
+  select typeof(g)
+  case 'state-space' then
+    if norm(g(5))>0 then 
+      error(msprintf(gettext("%s: Wrong values for input argument #%d: Proper system expected.\n"),"h2norm",1)),
+    end;
+    sp=spec(g(2)),
+    if maxi(real(sp))>=-tol then
+      error(msprintf(gettext("%s: Wrong values for input argument #%d: Stable system expected.\n"),"h2norm",1)),
+    end,
+    w=obs_gram(g(2),g(4),'c'),
+    nh=abs(sqrt(sum(diag(g(3)'*w*g(3))))),return,
+  case 'rational' then
+    num=g(2),den=g(3),
+    s=poly(0,varn(den)),
+    [t1,t2]=size(num),
+    for i=1:t1,
+      for j=1:t2,
+       n=num(i,j),d=den(i,j),
+       if coeff(n)==0 then 
+         nh(i,j)=0,
+       else
+         if degree(n)>=degree(d) then
+           error(msprintf(gettext("%s: Wrong values for input argument #%d: Proper system expected.\n"),"h2norm",1)),
+         end
+         pol=roots(d),
+         if maxi(real(pol))>-tol then
+            error(msprintf(gettext("%s: Wrong values for input argument #%d: Stable system expected.\n"),"h2norm",1)),
+         end,
+         nt=horner(n,-s),dt=horner(d,-s),
+         nh(i,j)=residu(n*nt,d,dt),
+       end,
+      end
     end
+    nh=sqrt(sum(nh)),return,
+  else
+    error(97,1)
   end
-  nh=sqrt(sum(nh)),return,
-end
 endfunction
index c2f4ea1..043744f 100644 (file)
@@ -32,47 +32,46 @@ function [Sk,rk,mu]=h_inf(P,r,mumin,mumax,nmax)
 //P2 = normalized P.
 //
 
-P1=P(1);
-[P2,mu_inf,Uci,Yci,D22]=h_init(P,r)
-if mu_inf < mumax then 
-    write(%io(2),mu_inf,'(3x,''romax too big: max romax= '',f10.5)');end
-mumax=mini(mu_inf,mumax)
-//
-//    Gama-iteration P6 = transformed P2 with D11 removed
-[P6,Finf,mu,Uc#i,Yc#i]=h_iter(P2,r,mumin,mumax,nmax)
-if mu==0 then 
-write(%io(2),[mumin,mumax],'(1x,''no feasible ro in bounds: '',2(e10.3,2x))');
-rk=[];Sk=[];
-return,end
-//
-//    Optimal controller for P6
-[Sk,polesH,polesJ]=h_contr(P6,r,1/mu,Uc#i,Yc#i);
-[E,Ak,Bk1,Bk2,Ck1,Ck2,Dk11,Dk12,Dk21,Dk22]=Sk(:);
-//    Add the optimal controller at infinity
- if norm(Finf,1) <> 0 then Dk11=Dk11+Finf;end
-//    Back-normalization of the controller
-Bk1=Bk1*Yci;
-Ck1=Uci*Ck1;
-Dk11=Uci*Dk11*Yci;
-Dk12=Uci*Dk12;
-Dk21=Dk21*Yci;
-//Convert to descriptor form:
+  if and(typeof(P)<>['rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"h_inf",1))
+  end
+  [P2,mu_inf,Uci,Yci,D22]=h_init(P,r,%t)
+  //if mu_inf < mumax then write(%io(2),mu_inf,'(3x,''romax too big: max romax= '',f10.5)');end
+  mumax=mini(mu_inf,mumax)
+  //
+  //    Gama-iteration P6 = transformed P2 with D11 removed
+  [P6,Finf,mu,Uc#i,Yc#i]=h_iter(P2,r,mumin,mumax,nmax)
+  if mu==0 then 
+    warning(msprintf(_("%s : No feasible ro in bounds [%g  %g]\n"),"h_inf",mumin,mumax));
+    rk=[];Sk=[];
+    return,
+  end
+  //
+  //    Optimal controller for P6
+  [Sk,polesH,polesJ]=h_contr(P6,r,1/mu,Uc#i,Yc#i);
+  [E,Ak,Bk1,Bk2,Ck1,Ck2,Dk11,Dk12,Dk21,Dk22]=Sk(:);
+  //    Add the optimal controller at infinity
+  if norm(Finf,1) <> 0 then Dk11=Dk11+Finf;end
+  //    Back-normalization of the controller
+  Bk1=Bk1*Yci;
+  Ck1=Uci*Ck1;
+  Dk11=Uci*Dk11*Yci;
+  Dk12=Uci*Dk12;
+  Dk21=Dk21*Yci;
+  //Convert to descriptor form:
   Sk=des2ss(Ak,[Bk1,Bk2],[Ck1;Ck2],[Dk11,Dk12;Dk21,Dk22],E);
-//    Sk in transfer representation if P is.
-[LHS,RHS]=argn(0);
-if LHS<3 then Sk=Sk(1:r(2),1:r(1));rk=mu;
-//    Case D22 different from zero
- if norm(coeff(D22),1) <> 0 then Sk=Sk/.D22;end
-   if P1(1)=='r' then Sk=ss2tf(Sk);end;
-   return;
-end
-if LHS==3 then rk=r;
-   if P1(1)=='r' then Sk=ss2tf(Sk);end;
-end
-
-
+  if argn(2)<3 then 
+    Sk=Sk(1:r(2),1:r(1));rk=mu;
+    //    Case D22 different from zero
+    if norm(coeff(D22),1) <> 0 then Sk=Sk/.D22;end
+  else
+     rk=r;
+  end
+  //    Sk in transfer representation if P is.
+  if typeof(P)=='rational' then Sk=ss2tf(Sk);end;
 endfunction
-function [P2,mu_inf,Uci,Yci,D22]=h_init(P,r)
+
+function [P2,mu_inf,Uci,Yci,D22]=h_init(P,r,info)
 //******************************
 // Initialization of the standard plant
 // P = standard plant; r=size of P22 (1X2 vector)
@@ -82,120 +81,132 @@ function [P2,mu_inf,Uci,Yci,D22]=h_init(P,r)
 //   [C1 D12]'*[C1 D12] = Q = [Q1 S;S' Q2]
 //   [B1;D21] *[B1;D21]'= R = [R1 L';L R2]
 //!
-P1=P(1);
-if P1(1)=='r' then P=tf2ss(P);end
-     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
-     [na,na]=size(A);
-     [p1,m2]=size(D12),
-     [p2,m1]=size(D21),
-//Useful indexes
-     l1=1:p1-m2;k1=1:m1-p2;
-     l2=1+p1-m2:p1;k2=1+m1-p2:m1;
-
-//**************Check assumptions******************
-
-//Stabilizability/detectability of P22 ?
-
-P22=syslin('c',A,B2,C2);
-[ns,Us,St]=st_ility(P22,1.d-10)
-if ns<>na then warning(msprintf(gettext("%s: %s not stabilizable.\n"),"h_inf","P22"));end
-if ns==na then mprintf(gettext("%s: %s is stabilizable.\n"),"h_inf","P22");end
-
-[nd,Ud,Sd]=dt_ility(P22,1.d-10)
-
-if nd <> 0 then warning(msprintf(gettext("%s: %s not detectable.\n"),"h_inf","P22"));end
-if nd==0 then mprintf(gettext("%s: %s is detectable.\n"),"h_inf","P22");end
-
-// rank P21=[A,B2,C1,D12] = m2 ?
-     P12=syslin('c',A,B2,C1,D12);
-     [nt,dt]=trzeros(P12),rzt=real(nt./dt),
-     if size(nt,'*') > 0 then
-       if mini(abs(rzt)) < sqrt(%eps) then 
-     warning(msprintf(gettext("%s: %s has a zero on/close the imaginary axis.\n"),"h_inf","P12")),
-       end,
-     end,
-
-// rank P21=[A,B1,C2,D21] = p2 ?
-     P21=syslin('c',A,B1,C2,D21);
-     [nt,dt]=trzeros(P21),rzt=real(nt./dt),
-     if size(nt,'*')>0 then
-        if mini(abs(rzt)) < sqrt(%eps) then 
-    warning(msprintf(gettext("%s: %s has a zero on/close the imaginary axis.\n"),"h_inf","P21")),
-        end,
-     end,
-
-//***********************end***************************
-
-//Row compression of D12 (bottom)
-     [T1,r1]=rowcomp(D12),
- if r1<>m2 then error(msprintf(gettext("%s: %s not full column rank.\n"),"h_inf","D12")),end,
-     T1=[T1(r1+1:p1,:);T1(1:r1,:)],
-     D12=T1*D12,
-//Column compression of D21 (right)
-     [S1,r2]=colcomp(D21),
- if r2<>p2 then error(msprintf(gettext("%s: %s not full row rank.\n"),"h_inf","D21")),end,
-     D21=D21*S1,
-//Updating 
-     B1=B1*S1,C1=T1*C1,
-     D11=T1*D11*S1,
-
-// Scaling on U and Y
-     Uc=D12(l2,:);
-     Uci=inv(Uc);
-     B2=B2*Uci;
-     D12=D12*Uci;
-
-     Yc=D21(:,k2)
-     Yci=inv(Yc);
-     C2=Yci*C2;
-     D21=Yci*D21;
-
-//P2=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D12 and D21 scaled;
-
-//Initialization  
-
-//Solve H-infinity problem at infinity
-
-     D1111=D11(l1,k1),
-     D1112=D11(l1,k2),
-     D1121=D11(l2,k1),
-     D1122=D11(l2,k2),
-
-M11=[D1111,D1112];M22=[D1111',D1121'];
-g1=-1;g2=-1;
-if M11<>[] then g1=norm(M11);end
-if M22<>[] then g2=norm(M22);end
-
-gama_inf=maxi(g1,g2);
-if gama_inf==0 then mu_inf=1/%eps/%eps, else mu_inf=1/(gama_inf*gama_inf);end
-
-P2=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,0*D22]);
-
-//P2 = standard plant with D22=0 and D12,D21 normalized;
+  
+  P1=P(1);
+  if P1(1)=='r' then P=tf2ss(P);end
+  [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
+  [na,na]=size(A);
+  [p1,m2]=size(D12),
+  [p2,m1]=size(D21),
+  //Useful indexes
+  l1=1:p1-m2;k1=1:m1-p2;
+  l2=1+p1-m2:p1;k2=1+m1-p2:m1;
+
+  //**************Check assumptions******************
+
+  //Stabilizability/detectability of P22 ?
+
+  P22=syslin('c',A,B2,C2);
+  
+  [ns,Us,St]=st_ility(P22,1.d-10)
+  
+  if ns<>na then 
+    warning(msprintf(gettext("%s:  %s is not stabilizable.\n"),"h_inf","P22"));
+  end
+  if ns==na & info then 
+    mprintf(gettext("%s: %s is stabilizable.\n"),"h_inf","P22");
+  end
+
+  [nd,Ud,Sd]=dt_ility(P22,1.d-10)
+
+  if nd <> 0 then 
+    warning(msprintf(gettext("%s:   %s is not detectable.\n"),"h_inf","P22"));
+  end
+  if nd==0 & info then 
+    mprintf(gettext("%s: %s is detectable.\n"),"h_inf","P22");
+  end
+
+  // rank P21=[A,B2,C1,D12] = m2 ?
+  P12=syslin('c',A,B2,C1,D12);
+  [nt,dt]=trzeros(P12),rzt=real(nt./dt),
+  if size(nt,'*') > 0 then
+    if mini(abs(rzt)) < sqrt(%eps) then 
+      warning(msprintf(gettext("%s: %s has a zero on/close the imaginary axis.\n"),"h_inf","P12")),
+    end,
+  end,
+
+  // rank P21=[A,B1,C2,D21] = p2 ?
+  P21=syslin('c',A,B1,C2,D21);
+  [nt,dt]=trzeros(P21),rzt=real(nt./dt),
+  if size(nt,'*')>0 then
+    if mini(abs(rzt)) < sqrt(%eps) then 
+      warning(msprintf(gettext("%s: %s has a zero on/close the imaginary axis.\n"),"h_inf","P21")),
+    end,
+  end,
+
+  //***********************end***************************
+
+  //Row compression of D12 (bottom)
+  [T1,r1]=rowcomp(D12),
+  if r1<>m2 then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d:  %s is not full rank.\n"),"h_inf",1,"D12"));
+  end,
+  T1=[T1(r1+1:p1,:);T1(1:r1,:)],
+  D12=T1*D12,
+  //Column compression of D21 (right)
+  [S1,r2]=colcomp(D21),
+  if r2<>p2 then 
+   error(msprintf(gettext("%s: Wrong values for input argument #%d:  %s is not full rank.\n"),"h_inf",1,"D21"));
+  end,
+  D21=D21*S1,
+  //Updating 
+  B1=B1*S1,C1=T1*C1,
+  D11=T1*D11*S1,
+
+  // Scaling on U and Y
+  Uc=D12(l2,:);
+  Uci=inv(Uc);
+  B2=B2*Uci;
+  D12=D12*Uci;
+
+  Yc=D21(:,k2)
+  Yci=inv(Yc);
+  C2=Yci*C2;
+  D21=Yci*D21;
+
+  //P2=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D12 and D21 scaled;
+
+  //Initialization  
+
+  //Solve H-infinity problem at infinity
+
+  D1111=D11(l1,k1),
+  D1112=D11(l1,k2),
+  D1121=D11(l2,k1),
+  D1122=D11(l2,k2),
+
+  M11=[D1111,D1112];M22=[D1111',D1121'];
+  g1=-1;g2=-1;
+  if M11<>[] then g1=norm(M11);end
+  if M22<>[] then g2=norm(M22);end
+
+  gama_inf=maxi(g1,g2);
+  if gama_inf==0 then mu_inf=1/%eps/%eps, else mu_inf=1/(gama_inf*gama_inf);end
+
+  P2=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,0*D22]);
+
+  //P2 = standard plant with D22=0 and D12,D21 normalized;
 
 
 endfunction
 function [P6ad,Finfad,muad,Uc#iad,Yc#iad]=h_iter(P2,r,mumin,mumax,nmax)
-niter=0;muad=0;P6ad=[]; Finfad=[];Uc#iad=[];Yc#iad=[];
-while niter < nmax
-  niter=niter+1;
-  mu=(mumin+mumax)/2;
-  [P6,Finf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
-  
-  test=maxi(tv)
+  niter=0;muad=0;P6ad=[]; Finfad=[];Uc#iad=[];Yc#iad=[];
+  while niter < nmax
+    niter=niter+1;
+    mu=(mumin+mumax)/2;
+    [P6,Finf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
+    
+    test=maxi(tv)
 
     if test > 0 then
-     mumax=mu
-     else
-     mumin=mu,muad=mu;P6ad=P6;Finfad=Finf;Uc#iad=Uc#i;Yc#iad=Yc#i;
+      mumax=mu
+    else
+      mumin=mu,muad=mu;P6ad=P6;Finfad=Finf;Uc#iad=Uc#i;Yc#iad=Yc#i;
     end
 
-end  //while
-
-
+  end  //while
 endfunction
+
 function [P6,Kinf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
 //****************************
 //To test if mu is feasable for the plant P2 :
@@ -205,205 +216,212 @@ function [P6,Kinf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
 //
 //   [C1 D12]*[C1 D12]'=Q=[Q1 S;S' Q2]
 //   [B1;D21]*[B1;D21]'=R=[R1 L';L R2]
-tv=[1,1,1];
-     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P2,r);
-     [p1,m2]=size(D12),
-     [p2,m1]=size(D21),
-//Useful indexes
-     l1=1:p1-m2;k1=1:m1-p2;
-     l2=1+p1-m2:p1;k2=1+m1-p2:m1;
-//
+  tv=[1,1,1];
+  [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P2,r);
+  [p1,m2]=size(D12),
+  [p2,m1]=size(D21),
+  //Useful indexes
+  l1=1:p1-m2;k1=1:m1-p2;
+  l2=1+p1-m2:p1;k2=1+m1-p2:m1;
+  //
+
+  D1111=D11(l1,k1),
+  D1112=D11(l1,k2),
+  D1121=D11(l2,k1),
+  D1122=D11(l2,k2),
+
+  if mu==0 then mu=%eps*%eps;end
+  mu1=1/mu;
+  gama=1/sqrt(mu);
+  gam2=1/(gama*gama);
+
+  err=(m1-p2)*(p1-m2);
+
+  if err==0 then
+    Kinf=-D1122
+  else
+    Kinf=-(D1122+D1121*inv(mu1*eye()-D1111'*D1111)*D1111'*D1112);
+  end
+
+  //Kinf=admissible controller for mu
+
+  A=A+B2*Kinf*C2;
+  B1=B1+B2*Kinf*D21;
+  C1=C1+D12*Kinf*C2;
+  D11=D11+D12*Kinf*D21;
+
+  if norm(D11) >= gama then 
+    P6=[]; Kinf=[];Uc#i=[];Yc#i=[];
+    error(msprintf(gettext("%s: gamma too small.\n"),"h_inf"));
+  end
+
+  //P3=list(A,B1,B2,C1,C2,D11,D12,D21,D22) with norm(D11) < gama.
+
+  Teta11=gam2*D11;
+  Teta22=gam2*D11';
+  W12=eye()-gam2*D11*D11';
+  W21=eye()-gam2*D11'*D11;
+  Teta12=(1/gama)*sqrtm(0.5*(W12+W12'));
+  Teta21=-(1/gama)*sqrtm(0.5*(W21+W21'));
+
+  //Teta*Teta'=(1/gama*gama)*eye()
+
+  M=inv(eye()-D11*Teta22);
+  N=inv(eye()-Teta22*D11);
 
-     D1111=D11(l1,k1),
-     D1112=D11(l1,k2),
-     D1121=D11(l2,k1),
-     D1122=D11(l2,k2),
+  A=A+B1*Teta22*M*C1;
 
-if mu==0 then mu=%eps*%eps;end
-mu1=1/mu;
-gama=1/sqrt(mu);
-gam2=1/(gama*gama);
+  B2=B2+B1*Teta22*M*D12;
+  B1=B1*N*Teta21;
 
-err=(m1-p2)*(p1-m2);
+  C2=C2+D21*Teta22*M*C1;
+  C1=Teta12*M*C1;
 
-if err==0 then
-   Kinf=-D1122
-else
-   Kinf=-(D1122+D1121*inv(mu1*eye()-D1111'*D1111)*D1111'*D1112);
-end
+  D11=0*D11;     //By construction...
 
-//Kinf=admissible controller for mu
-
-A=A+B2*Kinf*C2;
-B1=B1+B2*Kinf*D21;
-C1=C1+D12*Kinf*C2;
-D11=D11+D12*Kinf*D21;
-
-if norm(D11) >= gama then 
-    P6=[]; Kinf=[];Uc#i=[];Yc#i=[];error(msprintf(gettext("%s: gamma too small.\n"),"h_inf"));end
-
-//P3=list(A,B1,B2,C1,C2,D11,D12,D21,D22) with norm(D11) < gama.
-
-Teta11=gam2*D11;
-Teta22=gam2*D11';
-W12=eye()-gam2*D11*D11';
-W21=eye()-gam2*D11'*D11;
-Teta12=(1/gama)*sqrtm(0.5*(W12+W12'));
-Teta21=-(1/gama)*sqrtm(0.5*(W21+W21'));
-
-//Teta*Teta'=(1/gama*gama)*eye()
-
-M=inv(eye()-D11*Teta22);
-N=inv(eye()-Teta22*D11);
-
-A=A+B1*Teta22*M*C1;
-
-B2=B2+B1*Teta22*M*D12;
-B1=B1*N*Teta21;
-
-C2=C2+D21*Teta22*M*C1;
-C1=Teta12*M*C1;
-
-D11=0*D11;     //By construction...
-
-D22#=D22+D21*Teta22*M*D12;
-
-D12=Teta12*M*D12;
-D21=D21*N*Teta21;
-
-//P4 =syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22] 
-//          with D11=0; P4=Fl(Teta,size(D11'),P3,r);
-
-D22=0*D22#;
-
-//P5 = [A,[B1,B2],[C1;C2],[D11,D12;D21,D22] with D11=0 and D22=0;
-
-//Row compression of D12
-     [T1,r1]=rowcomp(D12);
- if r1<>m2 then error(msprintf(gettext("%s: %s not full rank.\n"),"h_inf_st","D12")),end
-     T1=[T1(r1+1:p1,:);T1(1:r1,:)],
-     D12=T1*D12,
-//Column compression of D21
-     [S1,r2]=colcomp(D21),
- if r2<>p2 then error(msprintf(gettext("%s: %s not full rank.\n"),"h_inf_st","D21")),end,
-     D21=D21*S1,
-//Updating
-     B1=B1*S1,C1=T1*C1,
-     D11=T1*D11*S1,
-// Scaling on U and Y
-     Uc#=D12(l2,:);
-     Uc#i=inv(Uc#);
-     B2=B2*Uc#i;
-     D12=D12*Uc#i;
-
-     Yc#=D21(:,k2)
-     Yc#i=inv(Yc#);
-     C2=Yc#i*C2;
-     D21=Yc#i*D21;
-
-//P6=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D11=0,D22=0;D12 and D21 scaled.
-//Standard assumptions now satisfied
-
-//P6=[A,B1,B2,C1,C2,D11,D12,D21,D22];
-
-//     Test of mu for P6  <=> Test of mu^-1 for P2
-//Optimal controller :
-indic=0;     
-
-mu_test=1/mu;
-
-     R1=B1*B1';
-     S=D12'*C1;
-     C1#=(eye()-D12*D12')*C1;
-     Ax=A-B2*S;
-     Qx=-C1#'*C1#;
-
-     Rx=mu_test*R1-B2*B2';
-H=[Ax Rx;
-   Qx -Ax'];
-
-dx=mini(abs(real(spec(H))));
-//write(%io(2),dx);
-       if dx < 1.d-9 then
-                mprintf(gettext("%s: An eigenvalue of %s (controller) is close to Imaginary axis.\n"),"h_inf","H");
-     write(%io(2),dx);
-       indic=1;test=1;
-       end
- if indic ==0 then
-   [X1,X2,errx]=ric_desc(H);
-     if errx > 1.d-4 then
-       mprintf(gettext("%s: Riccati solution inaccurate.\n"),"h_inf");
-       write(%io(2),errx);
+  D22#=D22+D21*Teta22*M*D12;
+
+  D12=Teta12*M*D12;
+  D21=D21*N*Teta21;
+
+  //P4 =syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22] 
+  //          with D11=0; P4=Fl(Teta,size(D11'),P3,r);
+
+  D22=0*D22#;
+
+  //P5 = [A,[B1,B2],[C1;C2],[D11,D12;D21,D22] with D11=0 and D22=0;
+
+  //Row compression of D12
+  [T1,r1]=rowcomp(D12);
+  if r1<>m2 then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d:  %s is not full rank.\n"),"h_inf",1,"D12"));
+  end
+  T1=[T1(r1+1:p1,:);T1(1:r1,:)],
+  D12=T1*D12,
+  //Column compression of D21
+  [S1,r2]=colcomp(D21),
+  if r2<>p2 then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d:  %s is not full rank.\n"),"h_inf",1,"D21"));
+  end,
+  D21=D21*S1,
+  //Updating
+  B1=B1*S1,C1=T1*C1,
+  D11=T1*D11*S1,
+  // Scaling on U and Y
+  Uc#=D12(l2,:);
+  Uc#i=inv(Uc#);
+  B2=B2*Uc#i;
+  D12=D12*Uc#i;
+
+  Yc#=D21(:,k2)
+  Yc#i=inv(Yc#);
+  C2=Yc#i*C2;
+  D21=Yc#i*D21;
+
+  //P6=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D11=0,D22=0;D12 and D21 scaled.
+  //Standard assumptions now satisfied
+
+  //P6=[A,B1,B2,C1,C2,D11,D12,D21,D22];
+
+  //     Test of mu for P6  <=> Test of mu^-1 for P2
+  //Optimal controller :
+  indic=0;     
+
+  mu_test=1/mu;
+
+  R1=B1*B1';
+  S=D12'*C1;
+  C1#=(eye()-D12*D12')*C1;
+  Ax=A-B2*S;
+  Qx=-C1#'*C1#;
+
+  Rx=mu_test*R1-B2*B2';
+  H=[Ax Rx;
+     Qx -Ax'];
+
+  dx=mini(abs(real(spec(H))));
+  //write(%io(2),dx);
+  if dx < 1.d-9 then
+    mprintf(gettext("%s: An eigenvalue of %s (controller) is close to Imaginary axis.\n"),"h_inf","H");
+    write(%io(2),dx);
+    indic=1;test=1;
+  end
+  if indic ==0 then
+    [X1,X2,errx]=ric_desc(H);
+    if errx > 1.d-4 then
+      mprintf(gettext("%s: Riccati solution inaccurate: equation error = %g.\n"),"h_inf",errx);
      end
-//Optimal observer :
+    //Optimal observer :
 
-     Q1=C1'*C1;
-     L=B1*D21';
-     B1#=B1*(eye()-D21'*D21);
-     Ay=A-L*C2;
-     Qy=-B1#*B1#';
-     Ry=mu_test*Q1-C2'*C2;
+    Q1=C1'*C1;
+    L=B1*D21';
+    B1#=B1*(eye()-D21'*D21);
+    Ay=A-L*C2;
+    Qy=-B1#*B1#';
+    
+    Ry=mu_test*Q1-C2'*C2;
 
     J=[Ay' Ry;
        Qy -Ay];
     dy=mini(abs(real(spec(J))));
-//write(%io(2),dy);
-      if dy < 1.d-9 then
-               mprintf(gettext("%s: An eigenvalue of %s (observer) is close to Imaginary axis.\n"),"h_inf","J");
-               write(%io(2),dy);
-               indic=1 ;test=1;
-       end
-     if indic==0 then
-       [Y1,Y2,erry]=ric_desc(J);
-        if erry > 1.d-4 then 
-                 mprintf(gettext("%s: Riccati solution inaccurate.\n"),"h_inf");
-          write(%io(2),erry);
-        end
-//Tests
-//
-//     E=(Y2'*X2-mu*Y1'*X1);
-//     write(%io(2),mini(svd(E)),'(5x,''mini(svd(E)) = '',f10.2)')
-     [al1,be1]=spec(A*X2 -B2*(S*X2 +B2'*X1 ),X2);
-     [al2,be2]=spec(Y2'*A-(Y2'*L+Y1'*C2')*C2,Y2');
-     [al3,be3]=spec(mu_test*Y1'*X1,Y2'*X2);
-
-//Here division by zero may appear...
-//If such division appear try to uncomment the 3 following lines:
-w1=find(be1==0);be1(w1)=%eps*ones(be1(w1));
-w2=find(be2==0);be2(w2)=%eps*ones(be2(w2));
-w3=find(be3==0);be3(w3)=%eps*ones(be3(w3));
-
-     test1=maxi(real(al1./be1));
-     test2=maxi(real(al2./be2));
-     test3=maxi(real(al3./be3))-1;
-     tv   =[test1,test2,test3]
+    //write(%io(2),dy);
+    if dy < 1.d-9 then
+      mprintf(gettext("%s: An eigenvalue of %s (observer) is close to Imaginary axis.\n"+.. 
+                     "The distance to the imaginary axis is less than %g "),"h_inf","J",1.d-9);
+      write(%io(2),dy);
+      indic=1 ;test=1;
+    end
+    if indic==0 then
+      [Y1,Y2,erry]=ric_desc(J);
+      if erry > 1.d-4 then 
+       mprintf(gettext("%s: Riccati solution inaccurate: equation error = %g.\n"),"h_inf",erry);
+      end
+      //Tests
+      //
+      //     E=(Y2'*X2-mu*Y1'*X1);
+      //     write(%io(2),mini(svd(E)),'(5x,''mini(svd(E)) = '',f10.2)')
+      [al1,be1]=spec(A*X2 -B2*(S*X2 +B2'*X1 ),X2);
+      [al2,be2]=spec(Y2'*A-(Y2'*L+Y1'*C2')*C2,Y2');
+      [al3,be3]=spec(mu_test*Y1'*X1,Y2'*X2);
+
+      //Here division by zero may appear...
+      //If such division appear try to uncomment the 3 following lines:
+      w1=find(be1==0);be1(w1)=%eps*ones(be1(w1));
+      w2=find(be2==0);be2(w2)=%eps*ones(be2(w2));
+      w3=find(be3==0);be3(w3)=%eps*ones(be3(w3));
+
+      test1=maxi(real(al1./be1));
+      test2=maxi(real(al2./be2));
+      test3=maxi(real(al3./be3))-1;
+      tv   =[test1,test2,test3]
+    end
   end
-end
-
-//write(%io(2),1/sqrt(mu),'(10x,'' Try gama = '',f18.10)');
-[answer,no]=maxi(tv);
-//if exists('tv')==1 then write(%io(2),[tv,maxi(tv)],'(4f15.10)');end
-if exists('tv')==1 then 
-   if answer>0 then 
-        // @TODO This stuff should be localized... To bored to understand it for now.
-               if no==1 then
- write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (Hx hamiltonian)  test = '',e15.5)');
-                       end
-               if no==2 then
- write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (Hy hamiltonian)  test = '',e15.5)');
-                       end
-               if no==3 then
- write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (spectral radius) test = '',e15.5)');
-                       end
-                    else 
- write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,''              OK              test = '',e15.5)');
-    end;
-end;
-     P6=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22])
-
 
+  //write(%io(2),1/sqrt(mu),'(10x,'' Try gama = '',f18.10)');
+  [answer,no]=maxi(tv);
+  //if exists('tv')==1 then write(%io(2),[tv,maxi(tv)],'(4f15.10)');end
+  comm1=_("Unfeasible (Hx hamiltonian)")
+  comm2=_("Unfeasible (Hy hamiltonian)")
+  comm3=_("Unfeasible (Hy hamiltonian)")
+  if exists('tv')==1 then 
+    if answer>0 then 
+      // @TODO This stuff should be localized... To bored to understand it for now.
+      select no
+      case 1  then
+       fmt='('' gama = '',f18.10,'' '+_("Unfeasible (Hx hamiltonian)")+'   test = '',e15.5)'
+      case 2 then
+       fmt='('' gama = '',f18.10,'' '+_("Unfeasible (Hy hamiltonian)")+'   test = '',e15.5)'
+      case 3 then
+       fmt='('' gama = '',f18.10,'' '+_("Unfeasible (spectral radius)")+'  test = '',e15.5)'
+      else 
+       fmt='('' gama = '',f18.10,''             ok             )  test = '',e15.5)'
+      end;
+      write(%io(2),[1/sqrt(mu),answer],fmt);
+    end
+  end
+  P6=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22])
 endfunction
+
 function [Sk,polesH,polesJ]=h_contr(P,r,mu,U2i,Y2i)
 // ****************************
 // Computation of the optimal controller Sk for a standard
@@ -415,90 +433,90 @@ function [Sk,polesH,polesJ]=h_contr(P,r,mu,U2i,Y2i)
 //   [B1;D21]*[B1;D21]'=R=[R1 L';L R2]
 // 
 
-     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
-     if norm(D11,1) > %eps then error('D11 <> 0'),return end
+  [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
+  if norm(D11,1) > %eps then 
+    error('D11 <> 0'),
+  end
 
-     [p2,m1]=size(D21),
-     [p1,m2]=size(D12),
-     l1=1:p1-m2;k1=1:m1-p2;
-     l2=1+p1-m2:p1;k2=1+m1-p2:m1;
+    [p2,m1]=size(D21),
+    [p1,m2]=size(D12),
+    l1=1:p1-m2;k1=1:m1-p2;
+    l2=1+p1-m2:p1;k2=1+m1-p2:m1;
 
-//Initialization  : constants 
+    //Initialization  : constants 
 
-     R1=B1*B1';
-     S=D12'*C1;
-     C1#=(eye()-D12*D12')*C1;
-     Ax=A-B2*S;
-     Qx=-C1#'*C1#;
+    R1=B1*B1';
+    S=D12'*C1;
+    C1#=(eye()-D12*D12')*C1;
+    Ax=A-B2*S;
+    Qx=-C1#'*C1#;
 
-     Q1=C1'*C1;
-     L=B1*D21';
-     B1#=B1*(eye()-D21'*D21);
-     Ay=A-L*C2;
-     Qy=-B1#*B1#';
+    Q1=C1'*C1;
+    L=B1*D21';
+    B1#=B1*(eye()-D21'*D21);
+    Ay=A-L*C2;
+    Qy=-B1#*B1#';
 
-//               mu-dependent part
+    //               mu-dependent part
 
-//Optimal controller
+    //Optimal controller
 
-  Rx=mu*R1-B2*B2';
+    Rx=mu*R1-B2*B2';
 
-  H=[Ax Rx;
-     Qx -Ax'];
-  polesH=spec(H);
-  dx=mini(abs(real(polesH)));
-//write(%io(2),dx);
-if dx < 1.d-6 then
-  mprintf(gettext("%s: An eigenvalue of %s (controller) is close to Imaginary axis.\n"),"h_inf","H");
-
-end
-   [X1,X2,errx]=ric_desc(H);
-if errx > 1.d-4 then 
-   mprintf(gettext("%s: Riccati solution inaccurate.\n"),"h_inf");
-   write(%io(2),errx);
-end
-
-//Optimal observer :
-
-  Ry=mu*Q1-C2'*C2;
-
-  J=[Ay' Ry;
-     Qy -Ay];
-  polesJ=spec(J);
-  dy=mini(abs(real(polesJ)));
-//write(%io(2),dy);
-if dy < 1.d-6 then
-   mprintf(gettext("%s: An eigenvalue of %s (observer) is close to Imaginary axis.\n"),"h_inf","J");
-end
-  [Y1,Y2,erry]=ric_desc(J);
-if erry > 1.d-4 then 
-  mprintf(gettext("%s: Riccati solution inaccurate.\n"),"h_inf");
-     write(%io(2),erry);
-end
-
-//Controller in descriptor form
-
-  E=(Y2'*X2-mu*Y1'*X1);
-  A#=A-B2*S-L*C2;
-  Ak=Y2'*A#*X2+mu*Y1'*A#'*X1-Y2'*(mu*Qy+B2*B2')*X1-Y1'*(mu*Qx+C2'*C2)*X2;
-  Bk1=(Y2'*L+Y1'*C2');
-  Ck1=-(S*X2+B2'*X1);
-
-  Bk2=Y2'*B2+Y1'*S'
-  Ck2=-(C2*X2+L'*X1)
-
-  Dk11=0*Ck1*Bk1;
-  Dk22=0*Ck2*Bk2;
-  Dk12=eye(Ck1*Bk2);
-  Dk21=eye(Ck2*Bk1);
-
-//Scaling back
+    H=[Ax Rx;
+       Qx -Ax'];
+    polesH=spec(H);
+    dx=mini(abs(real(polesH)));
+    //write(%io(2),dx);
+    if dx < 1.d-6 then
+      mprintf(gettext("%s: An eigenvalue of %s (controller) is close to Imaginary axis.\n"),"h_inf","H");
+
+    end
+    [X1,X2,errx]=ric_desc(H);
+    if errx > 1.d-4 then 
+      mprintf(gettext("%s: Riccati solution inaccurate: equation error = %g.\n"),"h_inf",errx);
+    end
+
+    //Optimal observer :
+
+    Ry=mu*Q1-C2'*C2;
+
+    J=[Ay' Ry;
+       Qy -Ay];
+    polesJ=spec(J);
+    dy=mini(abs(real(polesJ)));
+    //write(%io(2),dy);
+    if dy < 1.d-6 then
+      mprintf(gettext("%s: An eigenvalue of %s (observer) is close to Imaginary axis.\n"),"h_inf","J");
+    end
+    [Y1,Y2,erry]=ric_desc(J);
+    if erry > 1.d-4 then 
+      mprintf(gettext("%s: Riccati solution inaccurate: equation error = %g.\n"),"h_inf",erry);
+    end
+
+    //Controller in descriptor form
+
+    E=(Y2'*X2-mu*Y1'*X1);
+    A#=A-B2*S-L*C2;
+    Ak=Y2'*A#*X2+mu*Y1'*A#'*X1-Y2'*(mu*Qy+B2*B2')*X1-Y1'*(mu*Qx+C2'*C2)*X2;
+    Bk1=(Y2'*L+Y1'*C2');
+    Ck1=-(S*X2+B2'*X1);
+
+    Bk2=Y2'*B2+Y1'*S'
+    Ck2=-(C2*X2+L'*X1)
+
+    Dk11=0*Ck1*Bk1;
+    Dk22=0*Ck2*Bk2;
+    Dk12=eye(Ck1*Bk2);
+    Dk21=eye(Ck2*Bk1);
+
+    //Scaling back
 
     Bk1=Bk1*Y2i;
     Ck1=U2i*Ck1;
     Dk21=Dk21*Y2i;
     Dk12=U2i*Dk12;
-//  Dk11=U2i*Dk11*Y2i
+    //  Dk11=U2i*Dk11*Y2i
 
     Sk=list(E,Ak,Bk1,Bk2,Ck1,Ck2,Dk11,Dk12,Dk21,Dk22);
 endfunction
index feb2915..478c7ef 100644 (file)
@@ -24,11 +24,15 @@ function [hinfnorm,frequency]=h_norm(Sl,rerr)
 //  Adapted from 
 //  N.A. Bruinsma   T.U.Delft/Philips Research Eindhoven, see also
 //  Systems & Control Letters, vol. 14 pp. 287-293.
-  Sl1=Sl(1);
-  [lhs,rhs]=argn(0);
+  
+  sltyp=typeof(Sl)
+  if and(sltyp<>['rational','state-space']) then
+     error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"h_norm",1))
+  end
+  if sltyp=='rational' then Sl=tf2ss(Sl);end
+
   eps=1.d-8;
-  flag='ss';if Sl1(1)=='r' then Sl=tf2ss(Sl);end
-  if Sl(7)=='d' then hinfnorm=dhnorm(Sl);frequency=[];return;end
+  if Sl.dt=='d'|type(sl.dt)==1 then hinfnorm=dhnorm(Sl);frequency=[];return;end
   [a,b,c,d]=Sl(2:5);
   eiga=spec(a);
   if maxi(real(eiga)) >= -1e-12 then 
@@ -96,7 +100,10 @@ function gama=dhnorm(Sl,tol,gamamax)
   n=0;
   while %T
     gama=(gamamin+gamamax)/2;n=n+1;
-    if n>1000 then warning(msprintf(gettext("%s: More than %d iterations.\n"),"dhnorm",1000));return;end
+    if n>1000 then 
+      warning(msprintf(gettext("%s: More than %d iterations.\n"),"dhnorm" ,1000));
+      return;
+    end
     if dhtest(Sl,gama) then
       gamamax=gama; else gamamin=gama
     end
index 0b754cb..71903f3 100644 (file)
@@ -9,20 +9,26 @@
 
 function [nk,W]=hankelsv(sl,tol)
 //!
-
-sl1=sl(1);
-if sl1(1)<>'lss' then error(msprintf(gettext("%s: State-space only.\n"),"hankelsv")),end
-if sl(7)=='d' then error(msprintf(gettext("%s: Continuous-time only.\n'),"hankelsv")),end
-sl(7)='c'
-//
-[lhs,rhs]=argn(0),
-if rhs==1 then tol=1000*%eps,end,
-lf=spec(sl(2)),
-if mini(abs(lf))<=tol then
-     error(msprintf(gettext("%s: Imaginary axis poles.\n"),"hankelsv")),
-end
-if maxi(real(lf)) > tol then warning(msprintf(gettext("%s: Unstable.\n"),"hankelsv")),end,
-[sla,sls,d]=dtsi(sl);
-lc=ctr_gram(sls),lo=obs_gram(sls),W=lc*lo;
-nk=sort(real(spec(W)));
+  if typeof(sl)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: State-space linear system expected.\n"),"hankelsv",1)),
+  end
+  if sl.dt==[] then
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"hankelsv",1));
+    sl.dt='c'
+  elseif sl.dt<>'c' then 
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Continuous-time linear system expected.\n'),"hankelsv",1)),
+  end
+  //
+  [lhs,rhs]=argn(0),
+  if rhs==1 then tol=1000*%eps,end,
+  lf=spec(sl(2)),
+  if mini(abs(lf))<=tol then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Pure imaginary  poles unexpected.\n"),"hankelsv",1)),
+  end
+  if maxi(real(lf)) > tol then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Stable system expected.\n"),"hankelsv",1)),
+  end,
+  [sla,sls,d]=dtsi(sl);
+  lc=ctr_gram(sls),lo=obs_gram(sls),W=lc*lo;
+  nk=sort(real(spec(W)));
 endfunction
index 2400d45..a0841a2 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
+// Copyright (C) INRIA - Serge Steer
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -9,19 +9,19 @@
 
 function [sl]=imrep2ss(v,deg)
 
-[lhs,rhs]=argn(0)
-// hankel
-[no,nv]=size(v);
-n=nv/2;
-ns1=no-1;n2=n-1;
-l=1;
-h=0*ones(n,n);
-for k=1:n,h(l:l+ns1,:)=v(:,k:k+n2),l=l+no,end;
-//factorization
-if rhs==1 then [u,h1,v1,deg]=svd(h);else [u,h1,v1]=svd(h);end
-//extraction
-obs=u(:,1:deg);con=h1*v1';con=con(1:deg,:);
-//shift
-obstild=obs(no+1:n*no,:);obstild(n*no,deg)=0;
-sl=syslin('d',obs'*obstild,con(:,1),obs(1:no,:))
+  [lhs,rhs]=argn(0)
+  // hankel
+  [no,nv]=size(v);
+  n=nv/2;
+  ns1=no-1;n2=n-1;
+  l=1;
+  h=0*ones(n,n);
+  for k=1:n,h(l:l+ns1,:)=v(:,k:k+n2),l=l+no,end;
+  //factorization
+  if rhs==1 then [u,h1,v1,deg]=svd(h);else [u,h1,v1]=svd(h);end
+  //extraction
+  obs=u(:,1:deg);con=h1*v1';con=con(1:deg,:);
+  //shift
+  obstild=obs(no+1:n*no,:);obstild(n*no,deg)=0;
+  sl=syslin('d',obs'*obstild,con(:,1),obs(1:no,:))
 endfunction
index 53fcd1b..540e80f 100644 (file)
@@ -52,7 +52,7 @@ if mtlb_isa(A,'lti') then
   // Special call     x0 = inistate(sys,y,u,tol,printw); 
   // 
   if A.dt=='c' then
-    error(msprintf(gettext("%s: The system %s must be a discrete-time system.\n"),"inistate","SYS"));
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Discrete time system expected.\n"),"inistate",1))
   end
   if ni<2 then
     error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"inistate",2));
index abe2b70..31bf869 100644 (file)
@@ -7,29 +7,32 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function [Sli]=invrs(Sl,alfa);
+function Sli=invrs(Sl,alfa);
 // Sli=invrs(Sl,alfa) computes Sli, the PSSD
 // inverse of PSSD Sl.
 //!
+  if typeof(Sl)<>'state-space' then
+     error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"invrs",1))
+  end
 
-D=Sl(5);
-if type(D)==2 then 
-  s=poly(0,varn(D));
-  Sl(5)=horner(Sl(5),s+alfa);
-end
-Sl(2)=Sl(2)-alfa*eye(Sl(2)); //Slnew(s)=Slold(s+alfa)
+  D=Sl.D;
+  if type(D)==2 then 
+    s=poly(0,varn(D));
+    Sl.D=horner(Sl.D,s+alfa);
+  end
+  Sl.A=Sl.A-alfa*eye(Sl.A); //Slnew(s)=Slold(s+alfa)
 
-[Sreg,Wss]=rowregul(Sl,0,0);
-if rcond(Sreg(5)) >1.d-6 then
-  Sli=invsyslin(Sreg)*Wss;
-else
-  error(msprintf(gettext("%s: Square but singular system.\n"),"invrs"));
-end
-[Q,M]=pbig(Sli(2),0.001,'d');
-Sli=projsl(Sli,Q,M);//Remove poles at zero.
+  [Sreg,Wss]=rowregul(Sl,0,0);
+  if rcond(Sreg.D) >1.d-6 then
+    Sli=invsyslin(Sreg)*Wss;
+  else
+    error(msprintf(gettext("%s: Square but singular system.\n"),"invrs"));
+  end
+  [Q,M]=pbig(Sli.A,0.001,'d');
+  Sli=projsl(Sli,Q,M);//Remove poles at zero.
 
-if Sli(2)~=[] then Sli(2)=Sli(2)+alfa*eye();end
-if type(Sli(5))==2 then 
-  Sli(5)=horner(Sli(5),s-alfa);
-end
+  if Sli.A~=[] then Sli.A=Sli.A+alfa*eye();end
+  if type(Sli.D)==2 then 
+    Sli.D=horner(Sli.D,s-alfa);
+  end
 endfunction
index 0650dcd..acfc479 100644 (file)
@@ -9,17 +9,15 @@
 
 function it=invsyslin(t)
 
+  if typeof(t)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"invsyslin",1))
+  end
 
-
-if type(t)<>16 then error(91,1),end
-flag=t(1);
-if flag(1) <> 'lss' then error(91,1),end;
-[p,m]=size(t(5));
-if p <> m then  warning(msprintf(gettext("%s: Wrong size for input argument #%d: Square matrix expected.\n"),"invsyslin",1)),end
-//
-d=pinv(t(5));
-a=t(2)-t(3)*d*t(4);
-b=t(3)*d;
-c=-d*t(4);
-it=syslin(t(7),a,b,c,d,t(6));
+  [p,m]=size(t.D);
+  if p <> m then  
+    warning(msprintf(gettext("%s: Wrong size for input argument #%d: Square system expected.\n"),"invsyslin",1)),
+  end
+  //
+  d=pinv(t.D);
+  it=syslin(t.dt,t.A-t.B*d*t.C,t.B*d,-d*t.C,d,t.X0);
 endfunction
index 31a4f18..c13a5a3 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
+// Copyright (C) INRIA - Serge Steer
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -17,9 +17,14 @@ function [y,R]=kpure(sl,eps)
     sl=ss2tf(sl)
     if size(sl.num,'*') > 1 then error(95,1),end
   else
-    error(gettext(msprintf("%s: Wrong type for argument #%d: Linear dynamic system expected.\n"),"kpure",1))
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"kpure",1))
+  end
+  if sl.dt<>'c' then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Continuous time system expected.\n"),"kpure",1))
+  end
+  if size(sl.D,'*')<>1 then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"kpure",1))
   end
-  if sl.dt<>'c' then error(msprintf(gettext("%s: System must be continuous.\n"),"kpure")),end
 
   //build the Routh table of the given system
   r=routh_t(sl,poly(0,'k')),
index e746077..5a9fc4e 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
+// Copyright (C) INRIA - Serge Steer
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -9,25 +9,30 @@
 
 function kp=krac2(n)
 
-if type(n)<>16 then error(97,1),end;
-flag=n(1)
-select flag(1)
-case 'r' then [n,d,dom]=n(2:4)
-case 'lss' then n=ss2tf(n);[n,d,dom]=n(['num','den','dt'])
-else error(97,1),
-end;
-if dom<>'c' then error(gettext(msprintf("%s: System must be continuous.\n"),"krac2")),end
-if size(n,'*')<>1 then error(95,1),end
+  select typeof(n)
+  case 'rational' then
+    [n,d,dom]==n(['num','den','dt'])
+  case 'state-space' then
+    n=ss2tf(n);[n,d,dom]=n(['num','den','dt'])
+  else
+     error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"kpure",1))
+  end
+  if dom<>'c' then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Continuous time system expected.\n"),"krac2",1))
+  end
+  if size(n,'*')<>1 then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"krac2",1))
+  end
 
-x=[];
-q1=derivat(n/d);s=roots(q1(2));
-//
-for a=s',
-  if abs(imag(a))<=10*%eps then 
-    x=[x;a],
-  end,
-end
-//x(x==0)=[]
-if x==[] then;return,end
-kp=sort(-real(freq(d,n,real(x))))
+  x=[];
+  q1=derivat(n/d);s=roots(q1(2));
+  //
+  for a=s',
+    if abs(imag(a))<=10*%eps then 
+      x=[x;a],
+    end,
+  end
+  //x(x==0)=[]
+  if x==[] then;return,end
+  kp=sort(-real(freq(d,n,real(x))))
 endfunction
index e853706..ba44276 100644 (file)
@@ -16,17 +16,21 @@ function [N,M]=lcf(Sl)
 //       see syslin
 //  N,M : is realization of Sl: Sl = M^-1 N
 //!
+  
+  if and(typeof(Sl)<>['rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"lcf",1))
+  end
+  flag=0;
+  if typeof(Sl)=='rational' then Sl=tf2ss(Sl),flag=1;end
 
-flag=0;Sl1=Sl(1);
-if Sl1(1)=='r' then Sl=tf2ss(Sl),flag=1;end
-[A,B,C,D]=Sl(2:5);[nw,nb]=size(B);[nc,nw]=size(C);
-R=eye()+D*D';
-[Z,H]=gfare(Sl);
-Ar=A+H*C;
-Bn=B+H*D;Bm=H;
-Rm12=inv(sqrtm(R));
-Cr=Rm12*C;Dn=Rm12*D;Dm=Rm12;
-N=syslin('c',Ar,Bn,Cr,Dn);
-M=syslin('c',Ar,Bm,Cr,Dm);
-if flag==1 then N=ss2tf(N);M=ss2tf(M);end
+  [A,B,C,D]=Sl(2:5);[nw,nb]=size(B);[nc,nw]=size(C);
+  R=eye()+D*D';
+  [Z,H]=gfare(Sl);
+  Ar=A+H*C;
+  Bn=B+H*D;Bm=H;
+  Rm12=inv(sqrtm(R));
+  Cr=Rm12*C;Dn=Rm12*D;Dm=Rm12;
+  N=syslin('c',Ar,Bn,Cr,Dn);
+  M=syslin('c',Ar,Bm,Cr,Dm);
+  if flag==1 then N=ss2tf(N);M=ss2tf(M);end
 endfunction
index 81a7be4..e02c136 100644 (file)
@@ -8,8 +8,11 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function [K,Y,err]=leqe(P21,Qx)
+  if typeof(P21)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"leqe",1))
+  end
 
-[A,B1,C2,D21,xo,dom]=P21(2:7)
-[KT,Y,err]=leqr(syslin(dom,A',C2',B1',D21'),Qx);
-K=KT';
+  [A,B1,C2,D21,xo,dom]=P21(2:7)
+  [KT,Y,err]=leqr(syslin(dom,A',C2',B1',D21'),Qx);
+  K=KT';
 endfunction
index 91fc25f..4750934 100644 (file)
@@ -18,15 +18,17 @@ function [k,x,err]=leqr(p12,vx)
 //
 
 [lhs,rhs]=argn(0);
-p121=p12(1);
-if p121(1)<>'lss' then error(msprintf(gettext("%s: State-space only.\n"),"leqr"));end
+
+if typeof(p12)<>'state-space' then
+  error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"leqr",1))
+end
 [a,b2,c1,d12]=p12(2:5);
 [n,nu]=size(b2);
 [ny,n]=size(c1);
 dom=p12(7);
 if dom==[] then 
   dom='c';
-  warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"leqr"))
+  warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"leqr",1));
 end
 select dom
 //      continuous
@@ -42,13 +44,17 @@ case 'c' then
 
   [bige,biga,dummy,z]=balanc(bige,biga);
   [w,k]=schur(biga,bige,'c');
-  if k<>n then warning(msprintf(gettext("%s: Stable subspace too small.\n"),"leqr"));...
-            k=[];w=[];err=[];return;
+  if k<>n then 
+    warning(msprintf(gettext("%s: Stable subspace is too small.\n"),"leqr"));
+    k=[];w=[];err=[];
+    return;
   end
 
   ws=z*w(:,1:n);
   x12=ws(1:n,:);
-  if rcond(x12) < 1.d-6 then warning(msprintf(gettext("%s: Bad conditionning.\n"),"leqr"));end
+  if rcond(x12) < 1.d-6 then 
+    warning(msprintf(gettext("%s: Bad conditionning.\n"),"leqr"));
+  end
   k=ws(2*n+1:2*n+nu,:)/x12;
   x=ws(n+1:2*n,:)/x12;
   if lhs~=3 then return;end
@@ -67,18 +73,25 @@ case 'd' then
         s', 0*b2', r];
   [bige,biga,dummy,z]=balanc(bige,biga);
   [w,k]=schur(biga,bige,'d');
-  if k<>n then warning(msprintf(gettext("%s: Stable subspace too small.\n"),"leqr"));...
-            k=[];w=[];err=[];return;end
+  if k<>n then 
+    warning(msprintf(gettext("%s: Stable subspace is too small.\n"),"leqr"));
+    k=[];w=[];err=[];
+    return;
+  end
   ws=z*w(:,1:n);
   x12=ws(1:n,:);
-  if rcond(x12) <1.d-6 then warning(msprintf(gettext("%s: Bad conditionning.\n"),"leqr"));...
-            k=[];w=[];return;end
+  if rcond(x12) <1.d-6 then 
+    warning(msprintf(gettext("%s: Bad conditionning.\n"),"leqr"));
+    k=[];w=[];
+    return;
+  end
 
   k=ws(2*n+1:2*n+nu,:)/x12;
   x=ws(n+1:2*n,:)/x12;
   if norm(x-x',1)>0.0001 then 
-        warning(msprintf(gettext("%s: %s non symmetric.\n"),"leqr","x"));...
-        k=[];w=[];return;
+    warning(msprintf(gettext("%s: %s non symmetric.\n"),"leqr","x"));
+    k=[];w=[];
+    return;
   end
 
 //a'*x*a-(a'*x*b2+c1'*d12)*pinv(b2'*x*b2+d12'*d12)*(b2'*x*a+d12'*c1)+c1'*c1
index 7d66307..600dbf0 100644 (file)
@@ -17,288 +17,302 @@ function [p1,r1]=lft(p,r,p#,r#)
 // state space form or in transfer form);
 // lft(p,k) is lft(p,r,k) with r=size of k transpose;
 //!
-if type(p)==1 then p=syslin([],[],[],[],p);end
-pof1=p(1);
-if pof1(1)=='lss' then dom=p(7);else dom=p(4);end
-[lhs,rhs]=argn(0);
-if rhs==2 then
-  rhs=3;p#=r;
-  r=size(p#');
-end  //rhs=2
-pssdflag=%f;
-if typeof(p)=='state-space' then
-  if typeof(p(5))=='polynomial' then
-    pssdflag=%t;
+  [lhs,rhs]=argn(0);
+  
+  if type(p)==1 then 
+    p=syslin([],[],[],[],p);
+  else
+    if and(typeof(p)<>['rational','state-space']) then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"lft",1))
+    end
   end
-end
-if typeof(p#)=='state-space' then
-  if typeof(p#(5))=='polynomial' then
-    pssdflag=%t;
+  dom=p.dt
+  
+  p#pos=3
+  if rhs==2 then
+    rhs=3;p#=r;
+    r=size(p#');
+    p#pos=2
+  end  //rhs=2
+  
+  if and(typeof(p#)<>['constant','rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"lft",p#pos))
   end
-end
-if pssdflag then
-  if rhs==3 then
-    [p1,r1]=lftpssd(p,r,p#);return;
+  
+  pssdflag=%f;
+  if typeof(p)=='state-space' then
+    if typeof(p.D)=='polynomial' then
+      pssdflag=%t;
+    end
   end
-  if rhs==4 then
-    [p1,r1]=lftpssd(p,r,p#,r#);return;
+  if typeof(p#)=='state-space' then
+    if typeof(p#.D)=='polynomial' then
+      pssdflag=%t;
+    end
   end
-end
-if rhs==3 then
-  if type(p)==1 then
-    // lft( gain, linear system in ss form)
-    [nl,nc]=size(p);
-    l1=1:nc-r(1);
-    l2=nc-r(1)+1:nc;
-    k1=1:nl-r(2);
-    k2=nl-r(2)+1:nl;
-    d11=p(l1,k1);d12=p(l1,k2);d21=p(l2,k1);d22=p(l2,k2);
-    if type(p#)==1 then
-      //p# is a gain
-      dk=p#,
-      id=inv(eye(d22*dk)-d22*dk),
-      dd=d11+d12*dk*id*d21,
-      p1=dd;
-    else
-      // p# is not a gain
-      p#1=p#1(1)
-      if p#1(1)=='lss' then
-        [ak,bk,ck,dk]=p#(2:5);
-        id=inv(eye(d22*dk)-d22*dk),
-        aa= ak+bk*id*d22*ck,
-        bb=bk*id*d21,
-        cc=d12*(ck+dk*id*d22*ck),
-        dd=d11+d12*dk*id*d21;
-        p1=syslin(dom,aa,bb,cc,dd)
-      end
-      if p#1(1)=='r' then
-        p1=d11+d12*p#*invr(eye()-d22*p#)*d21;
-      end
+  if pssdflag then
+    if rhs==3 then
+      [p1,r1]=lftpssd(p,r,p#);return;
     end
-  end   //type(p)=1
-  pof1=p(1);
-  if pof1(1)=='lss' then
-    // lft(standard in ss form,linear system in ss form)
-    [a,b1,b2,c1,c2,d11,d12,d21,d22]=smga(p,r);
-    if type(p#)==1 then
-      //p# is a gain
-      dk=p#,
-      id=inv(eye(d22*dk)-d22*dk),
-      aa=a+b2*dk*id*c2;
-      bb=b1+b2*dk*id*d21,
-      cc=c1+d12*dk*id*c2,
-      dd=d11+d12*dk*id*d21,
-      p1=syslin(dom,aa,bb,cc,dd)
-    else
-// p# is not a gain
-      [ak,bk,ck,dk]=p#(2:5);
-      id=inv(eye(d22*dk)-d22*dk);
-      aa=[a+b2*dk*id*c2, b2*(ck+dk*id*d22*ck);
-          bk*id*c2, ak+bk*id*d22*ck],
-      bb=[b1+b2*dk*id*d21;bk*id*d21],
-      cc=[c1+d12*dk*id*c2, d12*(ck+dk*id*d22*ck)],
-      dd=d11+d12*dk*id*d21;
-      p1=syslin(dom,aa,bb,cc,dd)
+    if rhs==4 then
+      [p1,r1]=lftpssd(p,r,p#,r#);return;
     end
   end
-  if pof1(1)=='r' then
-    //lft(standard plant in tf form,linear system in tf form)
-    [p11,p12,p21,p22]=smga(p,r);
-    p1=p11+p12*p#*invr(eye()-p22*p#)*p21
-  end  //p(1)=='lss'
-end  //rhs=3
-if rhs==4 then
-  
-  if type(p)==1 then
-    //lft(gain,standard plant )
-    [nl,nc]=size(p);
-    l1=1:nc-r(1);
-    l2=nc-r(1)+1:nc;
-    k1=1:nl-r(2);
-    k2=nl-r(2)+1:nl;
-    d11=p(l1,k1);d12=p(l1,k2);d21=p(l2,k1);d22=p(l2,k2);
-    if type(p#)==1 then
-      //p# is a gain
-      [nl,nc]=size(p#);
-      l1=1:nc-r#(1);
-      l2=nc-r#(1)+1:nc;
-      k1=1:nl-r#(2);
-      k2=nl-r#(2)+1:nl;
-      d#11=p#(l1,k1);d#12=p#(l1,k2);d#21=p#(l2,k1);d#22=p#(l2,k2);
-      
-      g=inv(eye()-d22*d#11);
-      g#=inv(eye()-d#11*d22);
-      
-      dd11=d11+d12*g#*d#11*d21;
-      dd12=d12*g#*d#12;
-      dd21=d#21*g*d21;
-      dd22=d#22+d#21*g*d22*d#12;
-      
-      p1=[dd11,dd12;dd21,dd22];
-      r1=size(dd22);
+  if rhs==3 then
+    if type(p)==1 then
+      // lft( gain, linear system in ss form)
+      [nl,nc]=size(p);
+      l1=1:nc-r(1);
+      l2=nc-r(1)+1:nc;
+      k1=1:nl-r(2);
+      k2=nl-r(2)+1:nl;
+      d11=p(l1,k1);d12=p(l1,k2);d21=p(l2,k1);d22=p(l2,k2);
+      if type(p#)==1 then
+       //p# is a gain
+       dk=p#,
+       id=inv(eye(d22*dk)-d22*dk),
+       dd=d11+d12*dk*id*d21,
+       p1=dd;
+      else
+       // p# is not a gain
+       p#1=p#1(1)
+       if p#1(1)=='lss' then
+         [ak,bk,ck,dk]=p#(2:5);
+         id=inv(eye(d22*dk)-d22*dk),
+         aa= ak+bk*id*d22*ck,
+         bb=bk*id*d21,
+         cc=d12*(ck+dk*id*d22*ck),
+         dd=d11+d12*dk*id*d21;
+         p1=syslin(dom,aa,bb,cc,dd)
+       end
+       if p#1(1)=='r' then
+         p1=d11+d12*p#*invr(eye()-d22*p#)*d21;
+       end
+      end
+    end   //type(p)=1
+    pof1=p(1);
+    if pof1(1)=='lss' then
+      // lft(standard in ss form,linear system in ss form)
+      [a,b1,b2,c1,c2,d11,d12,d21,d22]=smga(p,r);
+      if type(p#)==1 then
+       //p# is a gain
+       dk=p#,
+       id=inv(eye(d22*dk)-d22*dk),
+       aa=a+b2*dk*id*c2;
+       bb=b1+b2*dk*id*d21,
+       cc=c1+d12*dk*id*c2,
+       dd=d11+d12*dk*id*d21,
+       p1=syslin(dom,aa,bb,cc,dd)
+      else
+       // p# is not a gain
+       [ak,bk,ck,dk]=p#(2:5);
+       id=inv(eye(d22*dk)-d22*dk);
+       aa=[a+b2*dk*id*c2, b2*(ck+dk*id*d22*ck);
+           bk*id*c2, ak+bk*id*d22*ck],
+       bb=[b1+b2*dk*id*d21;bk*id*d21],
+       cc=[c1+d12*dk*id*c2, d12*(ck+dk*id*d22*ck)],
+       dd=d11+d12*dk*id*d21;
+       p1=syslin(dom,aa,bb,cc,dd)
+      end
     end
-    p#1=p#(1);
-    if p#1(1)=='lss'
-      //p# in state form
-      [a#,b#1,b#2,c#1,c#2,d#11,d#12,d#21,d#22]=smga(p#,r#);
-      g=inv(eye()-d22*d#11);
-      g#=inv(eye()-d#11*d22);
-      
-      aa=a#+b#1*g*d22*c#1;
-      
-      bb1= b#1*g*d21;
-      bb2= b#2+b#1*g*d22*d#12;
-      
-      cc1= d12*g#*c#1;
-      cc2= c#2+d#21*g*d22*c#1;
-      
-      dd11=d11+d12*g#*d#11*d21;
-      dd12=d12*g#*d#12;
-      dd21=d#21*g*d21;
-      dd22=d#22+d#21*g*d22*d#12;
+    if pof1(1)=='r' then
+      //lft(standard plant in tf form,linear system in tf form)
+      [p11,p12,p21,p22]=smga(p,r);
+      p1=p11+p12*p#*invr(eye()-p22*p#)*p21
+    end  //p(1)=='lss'
+  end  //rhs=3
+  if rhs==4 then
+    
+    if type(p)==1 then
+      //lft(gain,standard plant )
+      [nl,nc]=size(p);
+      l1=1:nc-r(1);
+      l2=nc-r(1)+1:nc;
+      k1=1:nl-r(2);
+      k2=nl-r(2)+1:nl;
+      d11=p(l1,k1);d12=p(l1,k2);d21=p(l2,k1);d22=p(l2,k2);
+      if type(p#)==1 then
+       //p# is a gain
+       [nl,nc]=size(p#);
+       l1=1:nc-r#(1);
+       l2=nc-r#(1)+1:nc;
+       k1=1:nl-r#(2);
+       k2=nl-r#(2)+1:nl;
+       d#11=p#(l1,k1);d#12=p#(l1,k2);d#21=p#(l2,k1);d#22=p#(l2,k2);
+       
+       g=inv(eye()-d22*d#11);
+       g#=inv(eye()-d#11*d22);
+       
+       dd11=d11+d12*g#*d#11*d21;
+       dd12=d12*g#*d#12;
+       dd21=d#21*g*d21;
+       dd22=d#22+d#21*g*d22*d#12;
+       
+       p1=[dd11,dd12;dd21,dd22];
+       r1=size(dd22);
+      end
+      p#1=p#(1);
+      if p#1(1)=='lss'
+       //p# in state form
+       [a#,b#1,b#2,c#1,c#2,d#11,d#12,d#21,d#22]=smga(p#,r#);
+       g=inv(eye()-d22*d#11);
+       g#=inv(eye()-d#11*d22);
+       
+       aa=a#+b#1*g*d22*c#1;
+       
+       bb1= b#1*g*d21;
+       bb2= b#2+b#1*g*d22*d#12;
+       
+       cc1= d12*g#*c#1;
+       cc2= c#2+d#21*g*d22*c#1;
+       
+       dd11=d11+d12*g#*d#11*d21;
+       dd12=d12*g#*d#12;
+       dd21=d#21*g*d21;
+       dd22=d#22+d#21*g*d22*d#12;
+       
+       p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
+       r1=size(dd22);
+      end
+      if p#1(1)=='r' then
+       [j11,j12,j21,j22]=smga(p#,r#);
+       
+       g=invr(eye()-d22*j11);
+       g#=invr(eye()-j11*d22);
+       
+       ptfg11=d11+d12*j11*g*d21;
+       ptfg12=d12*g#*j12;
+       //ptfg21=j21*g*p21;
+       ptfg21=j21*(eye()+d22*g#*j11)*d21;
+       ptfg22=j22+j21*d22*g#*j12;
+       
+       p1=[ptfg11,ptfg12;ptfg21,ptfg22];
+       r1=size(ptfg22)
+       
+      end
+    end  //type(p)=1
+    pof1=p(1);
+    if pof1(1)=='lss' then
+      //lft(standard plant in ss form,standard plant in ss form)
+      [a ,b1,b2,c1,c2,d11,d12,d21,d22]=smga(p,r);
       
-      p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
-      r1=size(dd22);
-    end
-    if p#1(1)=='r' then
+      if type(p#)==1 then
+       //p# is a gain
+       [nl,nc]=size(p#);
+       l1=1:nc-r#(1);
+       l2=nc-r#(1)+1:nc;
+       k1=1:nl-r#(2);
+       k2=nl-r#(2)+1:nl;
+       d#11=p#(l1,k1);d#12=p#(l1,k2);d#21=p#(l2,k1);d#22=p#(l2,k2);
+       
+       g=inv(eye()-d22*d#11);
+       g#=inv(eye()-d#11*d22);
+       
+       aa=a+b2*g#*d#11*c2;
+       
+       bb1=b1+b2*g#*d#11*d21;
+       bb2=b2*g#*d#12;
+       
+       cc1=c1+d12*g#*d#11*c2;
+       cc2=d#21*g*c2;
+       
+       dd11=d11+d12*g#*d#11*d21;
+       dd12=d12*g#*d#12;
+       dd21=d#21*g*d21;
+       dd22=d#22+d#21*g*d22*d#12;
+       
+       p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
+       r1=size(dd22);
+       
+      else
+       //p# in state form
+       [a#,b#1,b#2,c#1,c#2,d#11,d#12,d#21,d#22]=smga(p#,r#);
+       g=inv(eye()-d22*d#11);
+       g#=inv(eye()-d#11*d22);
+       
+       aa=[a+b2*g#*d#11*c2 b2*g#*c#1;
+           b#1*g*c2 a#+b#1*g*d22*c#1];
+       
+       bb1=[b1+b2*g#*d#11*d21;
+            b#1*g*d21];
+       
+       bb2=[b2*g#*d#12;
+            b#2+b#1*g*d22*d#12];
+       
+       cc1=[c1+d12*g#*d#11*c2 d12*g#*c#1];
+       
+       cc2=[d#21*g*c2 c#2+d#21*g*d22*c#1];
+       dd11=d11+d12*g#*d#11*d21;
+       
+       dd12=d12*g#*d#12;
+       
+       dd21=d#21*g*d21;
+       
+       dd22=d#22+d#21*g*d22*d#12;
+       
+       p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
+       r1=size(dd22);return;
+      end // type(p#)=1
+    end  //p(1)=='lss'
+    pof1=p(1);
+    if pof1(1)=='r' then
+      //lft(standard plant in tf form,standard plant in tf form)
+      [p11,p12,p21,p22]=smga(p,r);
       [j11,j12,j21,j22]=smga(p#,r#);
       
-      g=invr(eye()-d22*j11);
-      g#=invr(eye()-j11*d22);
+      g=invr(eye()-p22*j11);
+      g#=invr(eye()-j11*p22);
       
-      ptfg11=d11+d12*j11*g*d21;
-      ptfg12=d12*g#*j12;
+      ptfg11=p11+p12*j11*g*p21;
+      ptfg12=p12*g#*j12;
       //ptfg21=j21*g*p21;
-      ptfg21=j21*(eye()+d22*g#*j11)*d21;
-      ptfg22=j22+j21*d22*g#*j12;
+      ptfg21=j21*(eye()+p22*g#*j11)*p21;
+      ptfg22=j22+j21*p22*g#*j12;
       
       p1=[ptfg11,ptfg12;ptfg21,ptfg22];
       r1=size(ptfg22)
-      
-    end
-  end  //type(p)=1
-  pof1=p(1);
-  if pof1(1)=='lss' then
-    //lft(standard plant in ss form,standard plant in ss form)
-    [a ,b1,b2,c1,c2,d11,d12,d21,d22]=smga(p,r);
-    
-    if type(p#)==1 then
-      //p# is a gain
-      [nl,nc]=size(p#);
-      l1=1:nc-r#(1);
-      l2=nc-r#(1)+1:nc;
-      k1=1:nl-r#(2);
-      k2=nl-r#(2)+1:nl;
-      d#11=p#(l1,k1);d#12=p#(l1,k2);d#21=p#(l2,k1);d#22=p#(l2,k2);
-      
-      g=inv(eye()-d22*d#11);
-      g#=inv(eye()-d#11*d22);
-      
-      aa=a+b2*g#*d#11*c2;
-      
-      bb1=b1+b2*g#*d#11*d21;
-      bb2=b2*g#*d#12;
-      
-      cc1=c1+d12*g#*d#11*c2;
-      cc2=d#21*g*c2;
-      
-      dd11=d11+d12*g#*d#11*d21;
-      dd12=d12*g#*d#12;
-      dd21=d#21*g*d21;
-      dd22=d#22+d#21*g*d22*d#12;
-      
-      p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
-      r1=size(dd22);
-      
-    else
-      //p# in state form
-      [a#,b#1,b#2,c#1,c#2,d#11,d#12,d#21,d#22]=smga(p#,r#);
-      g=inv(eye()-d22*d#11);
-      g#=inv(eye()-d#11*d22);
-      
-      aa=[a+b2*g#*d#11*c2 b2*g#*c#1;
-          b#1*g*c2 a#+b#1*g*d22*c#1];
-      
-      bb1=[b1+b2*g#*d#11*d21;
-          b#1*g*d21];
-      
-      bb2=[b2*g#*d#12;
-          b#2+b#1*g*d22*d#12];
-      
-      cc1=[c1+d12*g#*d#11*c2 d12*g#*c#1];
-      
-      cc2=[d#21*g*c2 c#2+d#21*g*d22*c#1];
-      dd11=d11+d12*g#*d#11*d21;
-      
-      dd12=d12*g#*d#12;
-      
-      dd21=d#21*g*d21;
-      
-      dd22=d#22+d#21*g*d22*d#12;
-      
-      p1=syslin(dom,aa,[bb1,bb2],[cc1;cc2],[dd11,dd12;dd21,dd22]);
-      r1=size(dd22);return;
-    end // type(p#)=1
-  end  //p(1)=='lss'
-  pof1=p(1);
-  if pof1(1)=='r' then
-    //lft(standard plant in tf form,standard plant in tf form)
-    [p11,p12,p21,p22]=smga(p,r);
-    [j11,j12,j21,j22]=smga(p#,r#);
-    
-    g=invr(eye()-p22*j11);
-    g#=invr(eye()-j11*p22);
-    
-    ptfg11=p11+p12*j11*g*p21;
-    ptfg12=p12*g#*j12;
-    //ptfg21=j21*g*p21;
-    ptfg21=j21*(eye()+p22*g#*j11)*p21;
-    ptfg22=j22+j21*p22*g#*j12;
-    
-    p1=[ptfg11,ptfg12;ptfg21,ptfg22];
-    r1=size(ptfg22)
-  end //p(1)='r'
-end //rhs=4
+    end //p(1)='r'
+  end //rhs=4
 
 endfunction
 function [lf,r1]=lftpssd(p,r,k,r2)
 //lft for pssd (inria report #1827, dec. 1992)
-[lhs,rhs]=argn(0);
-if rhs==2 then
-  rhs=3;k=r;r=size(k');
-end
-if rhs==3 then
-  [pp,qq]=size(p);
-  l1=pp-r(1);k1=qq-r(2);
-  l2=r(1);k2=r(2);
-  [l3,k4]=size(k);
-  l4=k1;k3=l1;
-  psi=[p,[-eye(l1,k3),zeros(l1,k4);
-          zeros(l2,k3),-eye(l2,k4)];
-      zeros(l3,k1),-eye(l3,k2),zeros(l3,k3),k;
-      eye(l4,k1),zeros(l4,k2+k3+k4)];
-  w=clean(ss2tf(psi));
-  lf=[zeros(k3,k1+k2),eye(k3,k3),zeros(k3,k4)]*inv(psi)*...
-      [zeros(l1+l2+l3,l4);eye(l4,l4)];
-  r1=[l1,k1];
-  return;
-end
-if rhs==4 then
-  [pp,qq]=size(p);
-  l1=pp-r(1);k1=qq-r(2);
-  l2=r(1);k2=r(2);
-  [pk,qk]=size(k);
-  l3=pk-r2(1);k5=qk-r2(2);
-  l4=r2(1);k6=r2(2);
-  l5=k1;k3=l4;k4=l1;l6=k6;
-  psi=...
-      [p,[zeros(l1,k3),-eye(l1,k4);zeros(l2,k3+k4)],[zeros(l1,k5+k6);-eye(l2,k5),zeros(l2,k6)];
-      [zeros(l3,k1),-eye(l3,k2);zeros(l4,k1+k2)],[zeros(l3,k3+k4);-eye(l4,k3),zeros(l4,k4)],k;
-      [eye(l5,k1),zeros(l5,k2+k3+k4+k5+k6);zeros(l6,k1+k2+k3+k4+k5),eye(l6,k6)]];
-  lf=...
-      [zeros(k4,k1+k2+k3),eye(k4,k4),zeros(k4,k5+k6);
-      zeros(k3,k1+k2),eye(k3,k3),zeros(k3,k4+k5+k6)]*inv(psi)*...
-      [zeros(l1+l2+l3+l4,l5+l6);eye(l5+l6,l5+l6)];
-  r1=[k3,l6];
-end
+  [lhs,rhs]=argn(0);
+  if rhs==2 then
+    rhs=3;k=r;r=size(k');
+  end
+  if rhs==3 then
+    [pp,qq]=size(p);
+    l1=pp-r(1);k1=qq-r(2);
+    l2=r(1);k2=r(2);
+    [l3,k4]=size(k);
+    l4=k1;k3=l1;
+    psi=[p,[-eye(l1,k3),zeros(l1,k4);
+           zeros(l2,k3),-eye(l2,k4)];
+        zeros(l3,k1),-eye(l3,k2),zeros(l3,k3),k;
+        eye(l4,k1),zeros(l4,k2+k3+k4)];
+    w=clean(ss2tf(psi));
+    lf=[zeros(k3,k1+k2),eye(k3,k3),zeros(k3,k4)]*inv(psi)*...
+       [zeros(l1+l2+l3,l4);eye(l4,l4)];
+    r1=[l1,k1];
+    return;
+  end
+  if rhs==4 then
+    [pp,qq]=size(p);
+    l1=pp-r(1);k1=qq-r(2);
+    l2=r(1);k2=r(2);
+    [pk,qk]=size(k);
+    l3=pk-r2(1);k5=qk-r2(2);
+    l4=r2(1);k6=r2(2);
+    l5=k1;k3=l4;k4=l1;l6=k6;
+    psi=...
+       [p,[zeros(l1,k3),-eye(l1,k4);zeros(l2,k3+k4)],[zeros(l1,k5+k6);-eye(l2,k5),zeros(l2,k6)];
+        [zeros(l3,k1),-eye(l3,k2);zeros(l4,k1+k2)],[zeros(l3,k3+k4);-eye(l4,k3),zeros(l4,k4)],k;
+        [eye(l5,k1),zeros(l5,k2+k3+k4+k5+k6);zeros(l6,k1+k2+k3+k4+k5),eye(l6,k6)]];
+    lf=...
+       [zeros(k4,k1+k2+k3),eye(k4,k4),zeros(k4,k5+k6);
+        zeros(k3,k1+k2),eye(k3,k3),zeros(k3,k4+k5+k6)]*inv(psi)*...
+       [zeros(l1+l2+l3+l4,l5+l6);eye(l5+l6,l5+l6)];
+    r1=[k3,l6];
+  end
 endfunction
index 56c203c..bd754a6 100644 (file)
@@ -16,51 +16,53 @@ function [n]=linf(g,eps,tol)
 //-- tol threshold for imaginary axis poles.
 // See also: h_norm
 //!
+  if type(g)==1,if norm(g)==0,n=0,return,end,end,
+  
+  if and(typeof(g)<>['rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"linf",1))
+  end
+  if g.dt<>'c'&g.dt<>[] then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Continuous time system expected.\n"),"linf",1))
+  end
+  g.dt='c'
+  if typeof(g)=='rational' then g=tf2ss(g),end
 
-g1=g(1);
-if g1(1)=='r' then g=tf2ss(g);end
-      if type(g)==1,if norm(g)==0,n=0,return,end,end,
-      if g(7)=='d' then
-         error(gettext(msprintf("%s: System must be continuous.\n"),"linf"))
-      else
-         g(7)='c'
-      end
-      [lhs,rhs]=argn(0),
-      select rhs,
-        case 1 then eps=1e-7,tol=1000*%eps,
-        case 2 then tol=1000*%eps,
-      end,
-      [a,b,c,d]=g(2:5),[t,t]=size(a),
-      p=ctr_gram(g),q=obs_gram(g);
-//Algorithm:
-//----------
-//1. min , max.
-//----------------------------------
-      [slp,slm]=dtsi(g),
-      if slp==0 then pp=0,qq=0,tp=1,
-         pm=p,qm=q,tm=t,
-      else
-         if slm==0 then pm=0,qm=0,tm=1,
-            pp=p,qq=q,tp=t,
-         else
-            [tp,tp]=size(slp(2)),[tm,tm]=size(slm(2)),
-            pp=ctr_gram(slp),qq=obs_gram(slp),
-            pm=ctr_gram(slm),qm=obs_gram(slm),
-         end,
-       end,
-       hsvp=sqrt(spec(pp*qq)),hsvp=sort(real(hsvp)),
-       hsvm=sqrt(spec(pm*qm)),hsvm=sort(real(hsvm)),
-       gl=maxi([norm(d),hsvp(tp),hsvm(tm)]),
-       gu=norm(d)+2*(sum(hsvp)+sum(hsvm)),
-//2. binary search
-//----------------------
-       while gu-gl>2*eps*gl,
-         x=(gl+gu)/2,
-         r=d'*d-(x*x)*eye(),s=d*d'-(x*x)*eye(),
-         mx=[a-b/r*d'*c, -x*b/r*b'; ..
-             x*c'/s*c,   -a'+c'*d/r*b'],
-         mp=abs(real(spec(mx))),mp=mini(mp),
-         if mp>tol then gu=x, else gl=x, end,
-       end;
-       n=(gu+gl)/2
+  [lhs,rhs]=argn(0),
+  select rhs,
+  case 1 then eps=1e-7,tol=1000*%eps,
+  case 2 then tol=1000*%eps,
+  end,
+  [a,b,c,d]=g(2:5),[t,t]=size(a),
+  p=ctr_gram(g),q=obs_gram(g);
+  //Algorithm:
+  //----------
+  //1. min , max.
+  //----------------------------------
+  [slp,slm]=dtsi(g),
+  if slp==0 then pp=0,qq=0,tp=1,
+    pm=p,qm=q,tm=t,
+  else
+    if slm==0 then pm=0,qm=0,tm=1,
+      pp=p,qq=q,tp=t,
+    else
+      [tp,tp]=size(slp(2)),[tm,tm]=size(slm(2)),
+      pp=ctr_gram(slp),qq=obs_gram(slp),
+      pm=ctr_gram(slm),qm=obs_gram(slm),
+    end,
+  end,
+  hsvp=sqrt(spec(pp*qq)),hsvp=sort(real(hsvp)),
+  hsvm=sqrt(spec(pm*qm)),hsvm=sort(real(hsvm)),
+  gl=maxi([norm(d),hsvp(tp),hsvm(tm)]),
+  gu=norm(d)+2*(sum(hsvp)+sum(hsvm)),
+  //2. binary search
+  //----------------------
+  while gu-gl>2*eps*gl,
+    x=(gl+gu)/2,
+    r=d'*d-(x*x)*eye(),s=d*d'-(x*x)*eye(),
+    mx=[a-b/r*d'*c, -x*b/r*b'; ..
+       x*c'/s*c,   -a'+c'*d/r*b'],
+    mp=abs(real(spec(mx))),mp=mini(mp),
+    if mp>tol then gu=x, else gl=x, end,
+  end;
+  n=(gu+gl)/2
 endfunction
index eecca3f..2e63e2c 100644 (file)
 function K=lqg(P,r)
 // returns the (strictly proper) lqg (H2) controller
 // for the augmented plant P
-
-  if P(1)(1)=='r' then
-    flag=%f
-    P=tf2ss(P)
-  elseif P(1)(1)=='lss'
-    flag=%t
+  if and(typeof(P)<>['rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"lqg",1))
+  end
+  if typeof(P)=='rational' then 
+    P=tf2ss(P),flag=%f
   else
-       error(gettext(msprintf("%s: Wrong type for argument #%d: Linear system expected.\n"),"lqg",1))
+    flag=%t
+  end
+
+  [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
+  if norm(D11,1) <> 0 then 
+    warning(msprintf(gettext("%s: %s is not zero! (set to zero)"),"lqg","D11"));
+  end
+  //if norm(D22,1) <> 0 then warning('lqg: D22 is not zero!');end
+  dom=P.dt;
+  if dom==[] then 
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"lqg",1));
+    dom='c';
   end
-[A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
-if norm(D11,1) <> 0 then warning(msprintf(gettext("%s: %s is not zero! (set to zero)"),"lqg","D11"));end
-//if norm(D22,1) <> 0 then warning('lqg: D22 is not zero!');end
-dom=P(7);
-if dom==[] then warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"lqg"))
-               dom='c';end
-P12=syslin(dom,A,B2,C1,D12);
-Kc=lqr(P12);
-P21=syslin(dom,A,B1,C2,D21);
-Kf=lqe(P21);
-P22=syslin(dom,A,B2,C2,D22);
-K=obscont(P22,Kc,Kf);
-if ~flag then K=ss2tf(K);end
+  P12=syslin(dom,A,B2,C1,D12);
+  Kc=lqr(P12);
+  P21=syslin(dom,A,B1,C2,D21);
+  Kf=lqe(P21);
+  P22=syslin(dom,A,B2,C2,D22);
+  K=obscont(P22,Kc,Kf);
+  if ~flag then K=ss2tf(K);end
 endfunction
index ff3234a..3ffa927 100644 (file)
@@ -36,7 +36,9 @@ C1=Qhalf(:,1:nx);D12=Qhalf(:,nx+1:nx+nu);
 C2=C;
 D11=0*C1*B1;
 dom=P22(7);
-if dom==[] then warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"lqg2stan"));end
+if dom==[] then 
+  warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"lqg2stan",1)); 
+end
 P=syslin(dom,A,real([B1,B2]),real([C1;C2]),real([D11,D12;D21,D22]));
 m=size(C2*B2);
 if flag==1 then
index 0e4de7c..c2fc98c 100644 (file)
@@ -14,53 +14,62 @@ function [K,X]=lqr(P12)
 //      |I   0   0|   | A    0   B  |      |I   0   0|   | A    0    B  |
 //     z|0   A'  0| - |-C'C  I   -S'|    s |0   I   0| - |-C'C -A'  -S' |
 //      |0   B'  0|   | S    0   D'D|      |0   0   0|   | S   -B'   D'D|
+  if typeof(P12)<>'state-space' then
+     error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"lqr",1))
+  end
 
-flag=P12(1)
-if flag(1)<>'lss' then error(msprintf(gettext("%s: state-space only.\n"),"lqr"));end
-[A,B2,C1,D12]=P12(2:5);
-[n,nu]=size(B2);
-[ny,n]=size(C1);
-select P12(7)
+  [A,B2,C1,D12]=P12(2:5);
+  [n,nu]=size(B2);
+  [ny,n]=size(C1);
+  select P12(7)
   case [] then
-   error(msprintf(gettext("%s: Time domain is not defined (P(7)=''c'' or ''d'').\n"),"lqr"))
+    error(msprintf(gettext("%s: Wrong value for input argument #%d: Time domain must be ''c'' or ''d''.\n"),"lqr",1))
   case 'c' then
-Z=0*A;I=eye(A);
-E=[I,Z,0*B2;
-    Z,I,0*B2;
-    0*ones(nu,2*n+nu)];
+    Z=0*A;I=eye(A);
+    E=[I,Z,0*B2;
+       Z,I,0*B2;
+       0*ones(nu,2*n+nu)];
 
-Aa=[A,Z,B2;
-    -C1'*C1,-A',-C1'*D12;
-     D12'*C1,B2',D12'*D12];
-[w,ks]=schur(Aa,E,'c');
-if ks<>n then error(msprintf(gettext("%s: Stable subspace too small.\n"),"lqr"));end
-ws=w(:,1:n);
-X12=ws(1:n,:);
-phi12=ws(n+1:2*n,:);
-u12=ws(2*n+1:2*n+nu,:);
-if rcond(X12)< 1.d-5 then warning(msprintf(gettext("%s: Bad conditionning.\n"),"lqr"));end
-K=u12/X12;
-X=phi12/X12;
-return
+    Aa=[A,Z,B2;
+       -C1'*C1,-A',-C1'*D12;
+       D12'*C1,B2',D12'*D12];
+    [w,ks]=schur(Aa,E,'c');
+    if ks<>n then 
+      error(msprintf(gettext("%s: Stable subspace is too small.\n"),"lqr"));
+    end
+    ws=w(:,1:n);
+    X12=ws(1:n,:);
+    phi12=ws(n+1:2*n,:);
+    u12=ws(2*n+1:2*n+nu,:);
+    if rcond(X12)< 1.d-5 then 
+      warning(msprintf(gettext("%s: Bad conditionning.\n"),"lqr"));
+    end
+    K=u12/X12;
+    X=phi12/X12;
+    return
   case 'd' then
-I=eye(A);Z=0*I;
-E=[I,Z,0*B2;
-   Z,A',0*B2;
-   0*B2',-B2',0*B2'*B2];
+    I=eye(A);Z=0*I;
+    E=[I,Z,0*B2;
+       Z,A',0*B2;
+       0*B2',-B2',0*B2'*B2];
 
-Aa=[A,Z, B2;
-    -C1'*C1,I, -C1'*D12;
-     D12'*C1, 0*B2', D12'*D12];
+    Aa=[A,Z, B2;
+       -C1'*C1,I, -C1'*D12;
+       D12'*C1, 0*B2', D12'*D12];
 
-[w,ks]=schur(Aa,E,'d');
-if ks<>n then error(msprintf(gettext("%s: Stable subspace too small.\n"),"lqr"));end
-ws=w(:,1:n);
-X12=ws(1:n,:);
-phi12=ws(n+1:2*n,:);
-u12=ws(2*n+1:2*n+nu,:);
-if rcond(X12)< 1.d-5 then warning(msprintf(gettext("%s: Bad conditionning.\n"),"lqr"));end
-K=u12/X12;
-X=phi12/X12;
-return
-end
+    [w,ks]=schur(Aa,E,'d');
+    if ks<>n then 
+      error(msprintf(gettext("%s: Stable subspace is too small.\n"),"lqr"));
+    end
+    ws=w(:,1:n);
+    X12=ws(1:n,:);
+    phi12=ws(n+1:2*n,:);
+    u12=ws(2*n+1:2*n+nu,:);
+    if rcond(X12)< 1.d-5 then 
+      warning(msprintf(gettext("%s: Bad conditionning.\n"),"lqr"));
+    end
+    K=u12/X12;
+    X=phi12/X12;
+    return
+  end
 endfunction
index 2213be1..99ac6b8 100644 (file)
 function [a,b,c]=minreal(a,b,c,domaine,tol)
 //
 
-[lhs,rhs]=argn(0)
-select type(a)
-case 16
-  flag=a(1)
-  if flag(1)<>'lss' then error(91,1),end
-  if lhs<>1 then error(msprintf(gettext("%s: Wrong number of output arguments.\n"),"minreal")),end;
-  select rhs
-  case 1 then istol=0
-  case 2 then istol=1,tol=b,
-  else error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"minreal",1,2)),
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'state_space' then
+    if lhs<>1 then 
+      error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"),"minreal",1)),
+    end;
+    select rhs
+    case 1 then 
+      istol=%f
+    case 2 then 
+      istol=T,
+      tol=b,
+    else 
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"minreal",1,2)),
+    end;
+    [a,b,c,d,x0,dom]=a(2:7);
+    if dom==[] then error(96,1),end
+    domaine='c';if dom<>'c' then domaine='d',end
+  case 'constant' then
+    if lhs<>3 then
+      error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"),"minreal",3)),
+    end;
+    select rhs
+    case 4 then istol=%f
+    case 5 then istol=T,
+    else        
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"minreal",4,5)),
+    end;
+  else 
+    error(91,1)
   end;
-  [a,b,c,d,x0,dom]=a(2:7);
-  if dom==[] then error(96,1),end
-  domaine='c';if dom<>'c' then domaine='d',end
-case 1
-  if lhs<>3 then
-        error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"),"minreal",3)),
+  //
+  wc=lyap(a',-b*b',domaine);
+  wo=lyap(a,-c'*c,domaine);
+  if ~istol then 
+    [r,n]=equil1(wc,wo);
+  else 
+    [r,n]=equil1(wc,wo,tol);
   end;
-  select rhs
-  case 4 then istol=0
-  case 5 then istol=1,
-  else          error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"minreal",4,5)),
-  end;
-else 
-  error(91,1)
-end;
-//
-wc=lyap(a',-b*b',domaine);
-wo=lyap(a,-c'*c,domaine);
-if istol==0 then 
-  [r,n]=equil1(wc,wo);
-else 
-  [r,n]=equil1(wc,wo,tol);
-end;
-n1=n(1);
-ri=inv(r);r=r(1:n1,:);ri=ri(:,1:n1)
-a=r*a*ri;b=r*b;c=c*ri
-if lhs==1 then a=syslin(dom,a,b,c,d,r*x0),end
+  n1=n(1);
+  ri=inv(r);r=r(1:n1,:);ri=ri(:,1:n1)
+  a=r*a*ri;b=r*b;c=c*ri
+  if lhs==1 then a=syslin(dom,a,b,c,d,r*x0),end
 endfunction
index b4e4ec7..c9c1ffb 100644 (file)
@@ -22,85 +22,122 @@ function z=narsimul(x1,x2,x3,x4,x5,x6,x7,x8)
 //
 // Copyright Enpc
 
-[lhs,rhs]=argn(0)
-// switch to ar representation 
-if type(x1)<>15&type(x1)<>16 then 
-   if rhs < 5, error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"narsimul",5));
-       return;end;
-   ar=armac(x1,x2,x3,size(x1,'r'),size(x5,'r'),x4);
-   if rhs==5,z=narsimul(ar,x5);return;end
-   if rhs==6,z=narsimul(ar,x5,x6);return;end
-   if rhs==7,z=narsimul(ar,x5,x6,x7);return;end;
-   if rhs==8,z=narsimul(ar,x5,x6,x7,x8);return;end;
-end
-// Here the call is always arsimul(ar,....)
-a=x1('a');b=x1('b');d=x1('d');sig=x1('sig');
-u=x2;
-[mmu,Nu]=size(u);
-if mmu<>x1('nu') then 
-    error(msprintf(gettext("%s: Number of rows of %s are incompatible with %s object.\n"),"arsimul","u",'arma"));
-  return;
-end;
-// dimensions 
-   [al,ac]=size(a);adeg=int(ac/al);
-   [dl,dc]=size(d);ddeg=int(dc/dl);
-   [bl,bc]=size(b);[mmu,Nu]=size(u);bdeg=int(bc/mmu);
-// quelques tests a faire : bl=al=dl,
-// <i>deg*<i>l=<i>c, pour i=a,b,d
-//
-// On genere d'abord y(k) solution de : A(z^-1)y(k)=B^(z-1)u(k)
-s=poly(0,'s');
-// Build polynomial matrix A(s)
-mata= a*((s.^[adeg-1:-1:0]).*.eye(al,al))';
-// Build polynomial matrix B(s)
-matb= b*((s.^[bdeg-1:-1:0]).*.eye(mmu,mmu))';
-// 
-num=matb*s**(adeg-1)
-den=mata*s**(bdeg-1);
-// Using past values 
-// yp doit etre de taille (al,(adeg-1))
-// up doit etre de taille (al,(bdeg-1))
-// ep doit etre de taille (al,(adeg-1))
-//
-if rhs <=5,
-   up=0*ones(mmu,(bdeg-1));
-else
-   if size(up)<>[mmu,(bdeg-1)],
-    error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"),"narsimul","up=[u(0),u(-1),..,]",string(mmu),string(bdeg-1)));
-    return;end
-end
-if rhs <=6,
-   yp=0*ones(al,(adeg-1));
-else
-  if size(yp)<>[al,(adeg-1)]
-    error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"),"narsimul","yp=[y(0),y(-1),..,]",string(al),string(adeg-1)));
-    return;end
-end
-if rhs <=7,
-   ep=0*ones(al,(ddeg-1));
-else
-  if size(ep)<>[al,(ddeg-1)]
-    error(msprintf(gettext("%s: %s must be of dimension (%s, %s).\n"),"narsimul","ep=[e(0),e(-1),..,]",string(al),string(ddeg-1)));
-    return;end
-end;
-// 
-degnum=maxi(degree(den));
-yp=[0*ones(al,degnum+1-adeg),yp(:,(adeg-1):-1:1)];
-up=[0*ones(mmu,degnum+1-bdeg),up(:,(bdeg-1):-1:1)];
-y=rtitr(num,den,u,up,yp);
-// truncate the solution to only keep y_1,..y_Nu 
-// (if b0=0 rtitr computes y_{Nu+1})
-y=y(:,1:Nu);
-// Generate bru such that A(z^-1)bru= D(z^-1) sig*e(t)
-// Build polynomial matrix D(s)
-matd= d*((s.^[ddeg-1:-1:0]).*.eye(al,al))';
-num=matd*s**(adeg-1)
-den=mata*s**(ddeg-1);
-degnum=maxi(degree(den));
-ep=[0*ones(al,degnum+1-ddeg),ep(:,(ddeg-1):-1:1)];
-// Normal noise 
-br=sig*rand(al,Nu,'normal')
-bru=rtitr(num,den,br,ep,0*ones(ep));
-// z(k) = y(k) + bru(k)
-z=y+bru(:,1:Nu);
+  [lhs,rhs]=argn(0)
+  // switch to ar representation 
+  if type(x1)==1 then 
+    if rhs < 5 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"narsimul",5,8));
+    end;
+    ar=armac(x1,x2,x3,size(x1,'r'),size(x5,'r'),x4);
+    select rhs
+    case 5 then
+      z=narsimul(ar,x5);
+    case 6 then
+      z=narsimul(ar,x5,x6);
+    case 7 then 
+      z=narsimul(ar,x5,x6,x7);
+    case 8 then
+      z=narsimul(ar,x5,x6,x7,x8);
+    end
+  elseif typeof(x1)== 'ar' then  // Here the call is always arsimul(ar,....)
+    if rhs < 2|rhs>5 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"narsimul",2,5));
+    end;
+
+    a=x1('a');b=x1('b');d=x1('d');sig=x1('sig');
+    u=x2;
+    [mmu,Nu]=size(u);
+    if mmu<>x1('nu') then 
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                            "Number of rows of #%d are incompatible with #%d argument.\n"),..
+                    "narsimul",1,2,2,1));
+    end;
+    // dimensions 
+    [al,ac]=size(a);adeg=int(ac/al);
+    [dl,dc]=size(d);ddeg=int(dc/dl);
+    [bl,bc]=size(b);[mmu,Nu]=size(u);bdeg=int(bc/mmu);
+    // quelques tests a faire : bl=al=dl,
+    // <i>deg*<i>l=<i>c, pour i=a,b,d
+    //
+    // On genere d'abord y(k) solution de : A(z^-1)y(k)=B^(z-1)u(k)
+    s=poly(0,'s');
+    // Build polynomial matrix A(s)
+    mata= a*((s.^[adeg-1:-1:0]).*.eye(al,al))';
+    // Build polynomial matrix B(s)
+    matb= b*((s.^[bdeg-1:-1:0]).*.eye(mmu,mmu))';
+    // 
+    num=matb*s**(adeg-1)
+    den=mata*s**(bdeg-1);
+    // Using past values 
+    // yp doit etre de taille (al,(adeg-1))
+    // up doit etre de taille (al,(bdeg-1))
+    // ep doit etre de taille (al,(adeg-1))
+    //
+    if rhs <=3 then
+      up=0*ones(mmu,(bdeg-1));
+    else
+      up=x3
+      if size(up,1)<>mmu then
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same row dimensions expected.\n"),"narsimul",2,3))
+      end
+      if size(up,2)<>bdeg-1,
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "Number of columns of #%d are incompatible with #%d argument.\n"),..
+                      "narsimul",1,3,3,1));
+      end
+    end
+    if rhs <=4 then
+      yp=0*ones(al,(adeg-1));
+    else
+      yp=x4
+      if size(yp,1)<>al then
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "Number of rows of #%d are incompatible with #%d argument.\n"),..
+                      "narsimul",1,4,4,1));
+      end
+      if size(yp,2)<>(adeg-1)  then
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "Number of columns of #%d are incompatible with #%d argument.\n"),..
+                      "narsimul",1,4,4,1));
+      end
+    end
+    if rhs <=5,
+      ep=0*ones(al,(ddeg-1));
+    else
+      ep=x5
+       if size(ep,1)<>al then
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "Number of rows of #%d are incompatible with #%d argument.\n"),..
+                      "narsimul",1,5,5,1));
+      end
+      if size(ep,2)<>(adeg-1)  then
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "Number of columns of #%d are incompatible with #%d argument.\n"),..
+                      "narsimul",1,5,5,1));
+      end
+    end;
+    // 
+    degnum=maxi(degree(den));
+    yp=[0*ones(al,degnum+1-adeg),yp(:,(adeg-1):-1:1)];
+    up=[0*ones(mmu,degnum+1-bdeg),up(:,(bdeg-1):-1:1)];
+    y=rtitr(num,den,u,up,yp);
+    // truncate the solution to only keep y_1,..y_Nu 
+    // (if b0=0 rtitr computes y_{Nu+1})
+    y=y(:,1:Nu);
+    // Generate bru such that A(z^-1)bru= D(z^-1) sig*e(t)
+    // Build polynomial matrix D(s)
+    matd= d*((s.^[ddeg-1:-1:0]).*.eye(al,al))';
+    num=matd*s**(adeg-1)
+    den=mata*s**(ddeg-1);
+    degnum=maxi(degree(den));
+    ep=[0*ones(al,degnum+1-ddeg),ep(:,(ddeg-1):-1:1)];
+    // Normal noise 
+    br=sig*rand(al,Nu,'normal')
+    bru=rtitr(num,den,br,ep,0*ones(ep));
+    // z(k) = y(k) + bru(k)
+    z=y+bru(:,1:Nu);
+  else
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: %s data structure expected.\n"),"narsimul",1,"arma"));
+  end;
 endfunction
index cb36c49..4607b4e 100644 (file)
@@ -15,41 +15,49 @@ function [x]=nehari(r,tol)
 //                  Y in Hoo
 //!
 
-[lhs,rhs]=argn(0);
-r1=r(1);
-if r1(1)<>'lss' then error(msprintf(gettext("%s: State-space only.\n"),"nehari")),end
-if r(7)=='d' then error(msprintf(gettext("%s: Continuous-time only.\n'),"nehari")),end
-r(7)='c'
-//
-if rhs==1 then tol=1e-6,end,
-//norm of Hankel operator
-//-----------------------
-nk=nophkel(r),nn=nk+tol,
-r(3)=r(3)/nn,
-//best approx.
-//------------
-xo=-obs_gram(r),xc=-ctr_gram(r),
-w=inv(eye()-xo*xc),
-[m,k,n]=size(r),m=m(1),
-[a,b,c]=r(2:4),o=0*ones(a),
-ax=[a,o,o;o,a,-w'*b*b';o,o,-a'-w*xo*b*b'],
-bx=[b;w'*b;w*xo*b],cx=[c,-c,0*ones(m,n)],
-x=syslin('c',ax,bx,cx*nn),
-[y,x]=dtsi(x);
+  [lhs,rhs]=argn(0);
+  if typeof(r)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"nehari",1))
+  end
+  if r.dt==[] then
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"nehari",1));
+    r.dt='c'
+  end
+  if r.dt<>'c' then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Continuous time system expected.\n"),"nehari",1))
+  end
+  //
+  if rhs==1 then tol=1e-6,end,
+  //norm of Hankel operator
+  //-----------------------
+  nk=nophkel(r),nn=nk+tol,
+  r(3)=r(3)/nn,
+  //best approx.
+  //------------
+  xo=-obs_gram(r),xc=-ctr_gram(r),
+  w=inv(eye()-xo*xc),
+  [m,k,n]=size(r),m=m(1),
+  [a,b,c]=r(2:4),o=0*ones(a),
+  ax=[a,o,o;o,a,-w'*b*b';o,o,-a'-w*xo*b*b'],
+  bx=[b;w'*b;w*xo*b],cx=[c,-c,0*ones(m,n)],
+  x=syslin('c',ax,bx,cx*nn),
+  [y,x]=dtsi(x);
 
 
 endfunction
+
 function [nk]=nophkel(sl,tol)
 //[nk]=nophkel(sl,[tol]) : norm of Hankel operator
-[lhs,rhs]=argn(0),
-if rhs==1 then tol=1000*%eps,end,
-if sl==0 then nk=0,return,end,
-lf=spec(sl(2)),
-if mini(abs(lf))<=tol then
-     error(msprintf(gettext("%s: Imaginary axis poles.\n"),"nehari")),end,
-if maxi(real(lf))<tol then nk=0,return,end,
-sl=dtsi(sl);
-lc=ctr_gram(sl),lo=obs_gram(sl),
-vp=spec(lc*lo),vmax=maxi(real(vp)),
-nk=sqrt(vmax)
+  [lhs,rhs]=argn(0),
+  if rhs==1 then tol=1000*%eps,end,
+  if sl==0 then nk=0,return,end,
+  lf=spec(sl(2)),
+  if mini(abs(lf))<=tol then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Pure imaginary  poles unexpected.\n"),"nehari",1))
+  end,
+  if maxi(real(lf))<tol then nk=0,return,end,
+  sl=dtsi(sl);
+  lc=ctr_gram(sl),lo=obs_gram(sl),
+  vp=spec(lc*lo),vmax=maxi(real(vp)),
+  nk=sqrt(vmax)
 endfunction
index 2c7633b..6ea71ec 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) INRIA, Serge Steer
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
@@ -15,24 +15,28 @@ function nyquist(varargin)
   else
     comments=[];
   end
+  fname="nyquist";//for error messages
+  fmax=[];  
   if or(typeof(varargin(1))==['state-space' 'rational']) then 
     //sys,fmin,fmax [,pas] or sys,frq
+    refdim=1 //for error message
     sltyp=varargin(1).dt
     if rhs==1 then
       [frq,repf,splitf]=repfreq(varargin(1),1d-3,1d3)
     elseif rhs==2 then //sys,frq
       if size(varargin(2),2)<2 then
-       error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "nyquist",1,1))
+       error(msprintf(_("%s: Wrong size for input argument #%d: A 1-by-n array expected with n>%d.\n"),..
+                      fname,1,1))
       end
       [frq,repf]=repfreq(varargin(1:rhs))
     elseif or(rhs==(3:4)) then //sys,fmin,fmax [,pas]
       [frq,repf,splitf]=repfreq(varargin(1:rhs))
     else
-      error(msprintf(_("%s : Invalid call: sys,fmin,fmax [,pas] [,com]'),"nyquist"))
+      error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,1,5))
     end
   elseif  type(varargin(1))==1 then 
     //frq,db,phi [,comments] or frq, repf [,comments]
+    refdim=2
     sltyp='x';splitf=[];splitf=1
     select rhs
     case 2 then //frq,repf
@@ -40,32 +44,32 @@ function nyquist(varargin)
       repf=varargin(2)
       if size(frq,2)<2 then
        error(msprintf(_("%s : Invalid argument #%d. It must be a row vector with length > %d"),..
-                    "nyquist",1,1))
+                      fname,1,1))
       end
       if size(frq,2)<>size(varargin(2),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "nyquist",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
  
     case 3 then  //frq,db,phi
       frq=varargin(1);
       if size(frq,2)<>size(varargin(2),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "nyquist",1,2))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,2))
       end
       if size(frq,2)<>size(varargin(3),2) then
-       error(msprintf(_("%s : Incompatible dimensions of arguments #%d and #%d."),..
-                        "nyquist",1,3))
+       error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),..
+                        fname,1,3))
       end
       repf=exp(log(10)*varargin(2)/20 + %pi*%i/180*varargin(3));
       
     else 
-      error(msprintf(_("%s : Invalid call: frq, db,phi [,com] or frq,repf [,com]'),"nyquist"))
+       error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
     end
   else
-    error(msprintf(_("%s : Invalid argument #%d. It must be a linear"+..
-                    " dynamical system (syslin) or a real array"),"nyquist",1))
-  end;
+    error(msprintf(_("%s: Wrong type for input argument #%d:  Linear state space, transfer function "+.. 
+                    " or row vector of floats expected.\n"),fname,1))
+ end;
   if size(frq,1)==1 then
     ilf=0
   else
@@ -74,7 +78,8 @@ function nyquist(varargin)
   
   [mn,n]=size(repf)
   if and(size(comments,'*')<>[0 mn]) then
-    error(msprintf(_("%s : Invalid dimension for argument #%d"),"nyquist",rhs+1))
+    error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"),...
+                  fname,refdim,rhs+1))
   end
   //
 
@@ -182,11 +187,11 @@ function nyquist(varargin)
   end
 
   if sltyp=='c' then
-    xtitle('Nyquist plot ','Re(h(2i*pi*f))','Im(h(2i*pi*f))');
+    xtitle(_("Nyquist plot"),'Re(h(2i*pi*f))','Im(h(2i*pi*f))');
   elseif sltyp=='x' then 
-    xtitle('Nyquist plot ','Re','Im');
+    xtitle(_("Nyquist plot"),'Re','Im');
   else   
-    xtitle('Nyquist plot ',['Re(h(exp(2i*pi*f*dt)))'],'Im(h(exp(2i*pi*f*dt)))');
+    xtitle(_("Nyquist plot"),'Re(h(exp(2i*pi*f*dt)))','Im(h(exp(2i*pi*f*dt)))');
   end
   drawnow()
     //reset format   
index 667775f..c109c1e 100644 (file)
@@ -9,34 +9,53 @@
 
 function [go]=obs_gram(a,c,domaine)
 
-[lhs,rhs]=argn(0)
-select type(a)
-case 1  then
-  if rhs<2 then error(39); end;
-  if rhs==2 then domaine='c'; end;
-  if part(domaine,1)<>'c' then domaine='d',end
-  [m,n]=size(a)
-  if m<>n then error(20,1),end
-  [mb,nb]=size(c);if nb<>n then error(60),end
-case 16 then
-  flag=a(1)
-  if flag(1)=='r' then a=tf2ss(a),end
-  if flag(1)<>'lss' then error(91,1),end
-  [a,c,domaine]=a([2,4,7])
-  if domaine==[] then
-    write(%io(2),msprintf(gettext("%s: By default time-domain = continuous.\n"),"obs_gram"))
-    domaine='c';
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'constant' then
+    if rhs<2 then error(39); end;
+    if rhs==2 then domaine='c'; end;
+    if and(domaine<>['d','c']) then
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "obs_gram",3,"''d'', ''c''"));
+    end
+    [m,n]=size(a)
+    if m<>n then error(20,1),end
+    [mb,nb]=size(c);if nb<>n then error(60),end
+  case 'state-space' then
+    if rhs>1 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"obs_gram",1)),
+    end
+     [a,c,domaine]=a([2,4,7])
+     if domaine==[] then
+       warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"obs_gram",1));
+       domaine='c';
+     elseif type(domaine)==1 then 
+       domaine='d',
+     end
+     [n,n]=size(a)
+  case 'rational' then
+    if rhs>1 then
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"obs_gram",1)),
+    end
+    a=tf2ss(a)
+    [a,c,domaine]=a([2,4,7])
+    if domaine==[] then
+      warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"obs_gram",1));
+      domaine='c';
+     elseif type(domaine)==1 then 
+       domaine='d',
+    end
+    [n,n]=size(a)
+  else 
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"obs_gram",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"obs_gram",1))
+    end
+  end;
+  //
+  s=spec(a)
+  if (domaine=='c'&maxi(real(s))>=0)|(domaine=='d'&maxi(abs(s))>=1) then
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Stable system expected.\n"),"obs_gram",1));
   end
-  [n,n]=size(a)
-else 
-  error(msprintf(gettext("%s: (A,C) pair or syslin list.\n"),"obs_gram"))
-end;
-//
-s=spec(a)
-if part(domaine,1)=='c' then
-  if maxi(real(s))>=0 then error(msprintf(gettext("%s: Unstable system.\n"),"obs_gram")),end
-else
-  if maxi(abs(s))>=1 then error(msprintf(gettext("%s: Unstable system.\n"),"obs_gram")),end
-end
-go=lyap(a,-c'*c,domaine)
+  go=lyap(a,-c'*c,domaine)
 endfunction
index 03e463f..78e2b23 100644 (file)
@@ -42,50 +42,55 @@ function [Obs,U,m]=observer(Sys,flag,alfa)
 // Transfer u-->[u;u]-->w=[u;y=Sys*u]-->Obs*w  i.e. u-->output of Obs
 // this transfer must equal Sys2, the u-->z transfer  (H2=eye).
 
-[nx,nx]=size(Sys(2));
-td=Sys(7);x0=Sys(6);
-[LHS,RHS]=argn(0);
-if RHS<>2 then [m1,m2,U,sl2]=dt_ility(Sys);end
-if RHS==1 then
-  flag='st';alfa=-ones(1,nx);
-end
-if RHS==2 then 
-  //poles are not given-->set to -ones
-  alfa=-ones(1,nx);
-  [A,B,C,D]=abcd(Sys);  //
-  J=flag;
-//  F=A+J*C;G=[B+J*D,-J]; //
-   Obs=syslin(td,A+J*C,[B+J*D,-J],eye(A));U=[];m=[];return;  //Ao
-end
-if RHS==3 then
-  if size(alfa,'*')==1 then alfa=alfa*ones(1,nx);end
-end
-select flag
-case 'pp'
-m=m2;
-no=nx-m;
-alfa=alfa(1:no);
-[A,B,C,D]=abcd(sl2);
-Ao=A(m+1:nx,m+1:nx);
-Bo=B(m+1:nx,:);
-Co=C(:,m+1:nx);
-Do=D;
-  J=-ppol(Ao',Co',alfa);J=J';
-  F=Ao+J*Co;G=[Bo+J*Do,-J];
-  Obs=syslin(td,F,G,eye(Ao));
-  return;
-case 'st'
-m=m1;
-no=nx-m;
-alfa=alfa(1:no);
-[A,B,C,D]=abcd(sl2);
-Ao=A(m+1:nx,m+1:nx);
-Bo=B(m+1:nx,:);
-Co=C(:,m+1:nx);
-Do=D;
-  J=stabil(Ao',Co',alfa);J=J';
-  F=Ao+J*Co;G=[Bo+J*Do,-J];
-  Obs=syslin(td,F,G,eye(Ao));
-  return;
-end
+  [LHS,RHS]=argn(0);
+  if typeof(Sys)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"observer",1))
+  end
+
+  [nx,nx]=size(Sys.A);
+  td=Sys.dt;x0=Sys.X0;
+
+  if RHS<>2 then [m1,m2,U,sl2]=dt_ility(Sys);end
+  if RHS==1 then
+    flag='st';alfa=-ones(1,nx);
+  end
+  if RHS==2 then 
+    //poles are not given-->set to -ones
+    alfa=-ones(1,nx);
+    [A,B,C,D]=abcd(Sys);  //
+    J=flag;
+    //  F=A+J*C;G=[B+J*D,-J]; //
+    Obs=syslin(td,A+J*C,[B+J*D,-J],eye(A));U=[];m=[];return;  //Ao
+  end
+  if RHS==3 then
+    if size(alfa,'*')==1 then alfa=alfa*ones(1,nx);end
+  end
+  select flag
+  case 'pp'
+    m=m2;
+    no=nx-m;
+    alfa=alfa(1:no);
+    [A,B,C,D]=abcd(sl2);
+    Ao=A(m+1:nx,m+1:nx);
+    Bo=B(m+1:nx,:);
+    Co=C(:,m+1:nx);
+    Do=D;
+    J=-ppol(Ao',Co',alfa);J=J';
+    F=Ao+J*Co;G=[Bo+J*Do,-J];
+    Obs=syslin(td,F,G,eye(Ao));
+    return;
+  case 'st'
+    m=m1;
+    no=nx-m;
+    alfa=alfa(1:no);
+    [A,B,C,D]=abcd(sl2);
+    Ao=A(m+1:nx,m+1:nx);
+    Bo=B(m+1:nx,:);
+    Co=C(:,m+1:nx);
+    Do=D;
+    J=stabil(Ao',Co',alfa);J=J';
+    F=Ao+J*Co;G=[Bo+J*Do,-J];
+    Obs=syslin(td,F,G,eye(Ao));
+    return;
+  end
 endfunction
index 8073aaf..c61d78d 100644 (file)
@@ -9,20 +9,24 @@
 
 function o=obsv_mat(a,c)
 
-[lhs,rhs]=argn(0)
-select type(a)
- case 1  then
-    if rhs==1 then error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"obsv_mat",2)),end
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'constant'  then
+    if rhs==1 then 
+      error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"obsv_mat",2)),
+    end
     [m,n]=size(a)
     if m<>n then error(20,1),end
     [mb,nb]=size(c);if nb<>n then error(60),end
-  case 16 then
-    flag=a(1)
-    if flag(1)<>'lss' then error(91,1),end
+  case 'state-space' then
     [a,c]=a([2,4])
     [n,n]=size(a)
-else error(msprintf(gettext("%s: Wrong type of input arguments: %s,%s pair or syslin list.\n"),"obsv_mat","a","c"))
-
-end;
-o=c;for k=1:n-1, o=[c;o*a],end
+  else 
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"obsv_mat",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"obsv_mat",1))
+    end
+  end;
+  o=c;for k=1:n-1, o=[c;o*a],end
 endfunction
index e53de55..7727c95 100644 (file)
@@ -9,29 +9,42 @@
 
 function [a,b,c]=obsvss(a,b,c,tol)
 
-[lhs,rhs]=argn(0)
-select type(a)
-case 1
- if lhs<>3 then error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"),"obsvss",3)),end
- select rhs
-   case 3 then tol = 100*%eps
-   case 4 then ,
-   else error(msprintf(gettext("%s Wrong number of input arguments: %d or %d expected.\n"),"obsvss",3,4))
- end;
-case 16
- flag=a(1);
- if flag(1)<>'lss' then error(91,1),end;
- if lhs<>1 then error(msprintf(gettext("%s: Wrong number of output argument: %d expected.\n"),"obsvss",1)),end
- select rhs
-   case 1 then tol=100*%eps
-   case 2 then tol=b
-   else  error(msprintf(gettext("%s Wrong number of input arguments: %d or %d expected.\n"),"obsvss",1,2))
- end;
- [a,b,c,d,x0,dom]=a(2:7)
-end;
-//
-[no,u]=contr(a',c',tol)
-u=u(:,1:no)
-a=u'*a*u;b=u'*b;c=c*u
-if lhs==1 then a=syslin(dom,a,b,c,d,u'*x0),end
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'constant' then
+    if lhs<>3 then 
+      error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"),"obsvss",3)),
+    end
+    select rhs
+    case 3 then 
+      tol = 100*%eps
+    case 4 then ,
+    else 
+      error(msprintf(gettext("%s Wrong number of input arguments: %d or %d expected.\n"),"obsvss",3,4))
+    end;
+  case 'state-space' then
+    if lhs<>1 then 
+      error(msprintf(gettext("%s: Wrong number of output argument: %d expected.\n"),"obsvss",1)),
+    end
+    select rhs
+    case 1 then 
+      tol=100*%eps
+    case 2 then 
+      tol=b
+    else  
+      error(msprintf(gettext("%s Wrong number of input arguments: %d or %d expected.\n"),"obsvss",1,2))
+    end;
+    [a,b,c,d,x0,dom]=a(2:7)
+  else
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space  expected.\n"),"obsvss",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"obsvss",1))
+    end
+  end;
+  //
+  [no,u]=contr(a',c',tol)
+  u=u(:,1:no)
+  a=u'*a*u;b=u'*b;c=c*u
+  if lhs==1 then a=syslin(dom,a,b,c,d,u'*x0),end
 endfunction
index c7cccd0..c579822 100644 (file)
@@ -17,7 +17,7 @@ function [phm,fr]=p_margin(h)
     error(97,1)
   end
   if or(size(h)<>[1 1]) then 
-    error(msprintf(_("%s: input argument must be a SISO system"),"p_margin"))
+   error(msprintf(_("%s: Wrong size for input argument #%d: Single input, single output system expected"),"p_margin",1))
   end
   eps=1.e-7// threshold used for testing if complex numbers are real or pure imaginary
   
index 9adedf7..da7d7f0 100644 (file)
@@ -17,75 +17,87 @@ function elts=pfss(S,rmax,cord)
 // If S is given in transfer form, it is first converted into state-space
 // and each subsystem is then converted in transfer form.
 //!
-flag=0;
-[LHS,RHS]=argn(0);
-FLAG=S(1)
-if FLAG(1)=='r' then flag=1;S=tf2ss(S);end
-if RHS==1 then rmax=[];cord=[];end
-if RHS==2 then 
-  if type(rmax)==10 then cord=rmax;end
-  if type(rmax)==1 then cord=[];end
-end
-if type(S)<>16 then error(91,1),end
-[t,f,g,h,dd,dom]=S([1:5,7]);
-if t(1)<>'lss' then error(91,1),end;
-[n,n]=size(f);
-if rmax==[] then
-[f,x,bs]=bdiag(f);
-else
-[f,x,bs]=bdiag(f,rmax);
-end
-h=h*x;g=x\g;
-k=1;ll=0;
-elts=list();
-for l=bs',
-          ind=k:k+l-1;
-          f1l=f(ind,ind);
-          gl=g(ind,:);
-          hl=h(:,ind);
-          elts(ll+1)=syslin('c',f1l,gl,hl)
-          ll=ll+1;k=k+l;
-end;
-if RHS==2  then
-select cord
-case 'c'
-  nb=size(bs,'*');
-  class=[];
-    for k=1:nb
-     oneortwo=bs(k);ss=elts(k);A=ss(2);
-     if oneortwo==1 then 
-        class=[class,real(spec(A))];end
-     if oneortwo>1 then 
-        class=[class,mini(real(spec(A)))];end
-    end;
-  [cl,indi]=sort(-class);
-  elts1=elts;
-     for k=1:size(elts);
-        elts(k)=elts1(indi(k));end
-case 'd'
-  nb=size(bs,'*');
-  class=[];
-    for k=1:nb
-     oneortwo=bs(k);ss=elts(k);A=ss(2);
-     if oneortwo==1 then 
-        class=[class,abs(spec(A))];end
-     if oneortwo>1 then 
-        class=[class,maxi(abs(spec(A)))];end
-    end;
-  [cl,indi]=sort(-class);
-  elts1=elts;
-     for k=1:size(elts);
-        elts(k)=elts1(indi(k));end
-end
-end
-if type(dd)==1 then
-if norm(dd,'fro')<>0 then elts(ll+1)=dd,end
-end
-if type(dd)==2 then 
-if norm(coeff(dd),1) > %eps then elts(ll+1)=dd,end
-end
-if flag==1 then
-   k=size(elts);
-   for kk=1:k,elts(kk)=ss2tf(elts(kk));end
- end
+  select argn(2)
+  case 1 then
+    rmax=[];cord=[]
+  case 2 the
+    if type(rmax)==10 then cord=rmax;end
+    if type(rmax)==1 then cord=[];end
+  end
+  
+  if and(typeof(S)<>['rational','state-space']) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"pfss",1))
+  end
+  if typeof(S)=='rational' then 
+    S=tf2ss(S),flag=%f
+  else
+    flag=%t
+  end
+
+  [f,g,h,dd,dom]=S([2:5,7]);
+   [n,n]=size(f);
+  if rmax==[] then
+    [f,x,bs]=bdiag(f);
+  else
+    [f,x,bs]=bdiag(f,rmax);
+  end
+  h=h*x;g=x\g;
+  k=1;ll=0;
+  elts=list();
+  for l=bs',
+    ind=k:k+l-1;
+    f1l=f(ind,ind);
+    gl=g(ind,:);
+    hl=h(:,ind);
+    elts(ll+1)=syslin('c',f1l,gl,hl)
+    ll=ll+1;k=k+l;
+  end;
+  if argn(2)==2  then
+    select cord
+    case 'c'
+      nb=size(bs,'*');
+      class=[];
+      for k=1:nb
+       oneortwo=bs(k);ss=elts(k);A=ss(2);
+       if oneortwo==1 then 
+         class=[class,real(spec(A))];
+       end
+       if oneortwo>1 then 
+         class=[class,mini(real(spec(A)))];
+       end
+      end;
+      [cl,indi]=sort(-class);
+      elts1=elts;
+      for k=1:size(elts);
+        elts(k)=elts1(indi(k));
+      end
+    case 'd'
+      nb=size(bs,'*');
+      class=[];
+      for k=1:nb
+       oneortwo=bs(k);ss=elts(k);A=ss(2);
+       if oneortwo==1 then 
+         class=[class,abs(spec(A))];
+       end
+       if oneortwo>1 then 
+         class=[class,maxi(abs(spec(A)))];
+       end
+      end;
+      [cl,indi]=sort(-class);
+      elts1=elts;
+      for k=1:size(elts);
+        elts(k)=elts1(indi(k));
+      end
+    end
+  end
+  if type(dd)==1 then
+    if norm(dd,'fro')<>0 then elts(ll+1)=dd,end
+  end
+  if type(dd)==2 then 
+    if norm(coeff(dd),1) > %eps then elts(ll+1)=dd,end
+  end
+  if flag then
+    k=size(elts);
+    for kk=1:k,elts(kk)=ss2tf(elts(kk));end
+  end
 endfunction
index 84d1478..5e41c97 100644 (file)
@@ -9,62 +9,83 @@
 function plzr(a,b,c,d)
 //
 // Copyright INRIA
-[lhs,rhs]=argn(0)
-if type(a)==16 then
-  if rhs<>1 then error(39),end
-  a1=a(1);
-  select a1(1)
-  case 'lss' then 
-    [a,b,c,d]=a(2:5)
-  case 'r' then 
+  [lhs,rhs]=argn(0)
+  select typeof(a)
+  case 'rational' then
+    if rhs<>1 then 
+      error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"plzr",1)),
+    end
     a=tf2ss(a),
     [a,b,c,d]=a(2:5)
-    if type(d)<>1 then 
-      error(msprintf(gettext("%s: The given transfer fuction is not proper.\n"),"plzr"));
+  case 'state-space' then
+    if rhs<>1 then 
+      error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"plzr",1)),
+    end
+    [a,b,c,d]=a(2:5)
+  case 'constant' then
+    if rhs<>4 then 
+      error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"plzr",4)),
     end
-  else 
-    error(97,1)
-  end;
-end;
 
-dr=spec(a)
-[al,be]=tr_zer(a,b,c,d)
-nr=al./be
-ni=imag(nr);nr=real(nr)
-di=imag(dr);dr=real(dr)
-//
-mxx=maxi([nr;dr;1]*1.1)
-mnx=mini([nr;dr;-1]*1.1)
-my=maxi(abs([ni;di;1])*1.1)
-xselect();
-rect=[mnx, -my, mxx, my];
-wdim=xget('wdim')
-dx=(mxx-mnx)/wdim(1);dy=2*my/wdim(2)
-if dy>dx then 
-  ax=(dy*wdim(1)-mxx+mnx)/2
-  mxx=mxx+ax;mnx=mnx-ax
-elseif dy<dx then
-  ay=(dx*wdim(2)-2*my)/2
-  my=my+ay
-end
-rect=[mnx, -my, mxx, my];
-plot2d(0,0,1,"051"," ",rect);
+  else
+    if rhs==1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"plzr",1))
+    else
+      error(msprintf(gettext("%s: Wrong type of input argument #%d: matrix of floating point numbers expected.\n"),"plzr",1))
+    end
+  end
+  if type(d)<>1 then 
+    error(msprintf(gettext("%s: The given transfer fuction is not proper.\n"),"plzr"));
+  end
 
-xx=xget("mark")
-xset("mark",xx(1),xx(1)+1);
-if prod(size(nr))<>0 then
-  plot2d(nr,ni,[-9,3],"100",gettext("Zeros"))
-  strf='100'
-  pos=6
-else
-  strf='100'
-  pos=3
-end;
-plot2d(dr,di,[-2,pos],strf,gettext("Poles"));
-plot2d([mnx;mxx],[0;0],4,"000",' ')
-plot2d([0;0],[-my;my],4,"000",' ')
 
-xarc(-1,1,2,2,0,360*64)
-xtitle(gettext("Transmission zeros and poles"),gettext("Real axis"),gettext("Imag. axis"));
-xset("mark",xx(1),xx(2));
+  dr=spec(a)
+  [al,be]=tr_zer(a,b,c,d)
+  nr=al./be
+  ni=imag(nr);nr=real(nr)
+  di=imag(dr);dr=real(dr)
+  //
+  mxx=maxi([nr;dr;1]*1.1)
+  mnx=mini([nr;dr;-1]*1.1)
+  my=maxi(abs([ni;di;1])*1.1)
+  rect=[mnx, -my, mxx, my];
+
+  wdim=get(gcf(),'axes_size')
+  dx=(mxx-mnx)/wdim(1);dy=2*my/wdim(2)
+  if dy>dx then 
+    ax=(dy*wdim(1)-mxx+mnx)/2
+    mxx=mxx+ax;mnx=mnx-ax
+  elseif dy<dx then
+    ay=(dx*wdim(2)-2*my)/2
+    my=my+ay
+  end
+  rect=[mnx, -my, mxx, my];
+  drawlater()
+  ax=gca();
+  ax.data_bounds=[mnx, -my; mxx, my];
+  ax.axes_visible='on';
+  legs=[],lhandle=[]
+  if size(nr,'*')<>0 then
+    xpoly(nr,ni)
+    e=gce();e.line_mode='off';e.mark_mode='on';
+    e.mark_size_unit="point";e.mark_size=7;e.mark_style=5;
+    legs=[legs;gettext("Zeros")]
+    lhandle=[lhandle;e]
+  end;
+  if size(dr,'*')<>0 then
+    xpoly(dr,di)
+    e=gce();e.line_mode='off';e.mark_mode='on';
+    e.mark_size_unit="point";e.mark_size=7;e.mark_style=2;
+    legs=[legs;gettext("Poles")]
+    lhandle=[lhandle;e]
+  end
+  ax.grid=ones(1,3)*color('gray')
+  xarc(-1,1,2,2,0,360*64)
+  xtitle(gettext("Transmission zeros and poles"),gettext("Real axis"), ...
+        gettext("Imaginary. axis"));
+  if legs<>[] then legend(lhandle,legs,1),end
+  drawnow()
+  xselect();
 endfunction
index 481a67b..332810d 100644 (file)
@@ -15,20 +15,20 @@ function [a,b,sig]=reglin(x,y,dflag)
 // dflag is optional if 1 a display of the result is done 
 //!
 
-[lhs,rhs]=argn(0);
-if rhs <=2;dflag=0;end
-[n1,n2]=size(x)
-[p1,p2]=size(y)
-if n2<>p2 then 
-  error(msprintf(gettext("%s: Wrong value for input arguments: %s equal to %s expected.\n"),"reglin","[n1,n2]=size(x),[p1,p2]=size(y), n2","p2"));
-end;
+  [lhs,rhs]=argn(0);
+  if rhs <=2;dflag=0;end
+  [n1,n2]=size(x)
+  [p1,p2]=size(y)
+  if n2<>p2 then 
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),"reglin",1,2));
+  end;
 
-xmoy=sum(x,2)/n2
-ymoy=sum(y,2)/n2
-// We use armax for apropriate orders which will perform 
-// nothing but a least square 
-// We could directly call pinv or \
-[arc,la,lb,sig]=armax(0,0,y-ymoy*ones(1,n2),x-xmoy*ones(1,n2),0,dflag);
-if typeof(la)=='list' then a=lb(1);else a=lb;end
-b=ymoy-a*xmoy;
+  xmoy=sum(x,2)/n2
+  ymoy=sum(y,2)/n2
+  // We use armax for apropriate orders which will perform 
+  // nothing but a least square 
+  // We could directly call pinv or \
+  [arc,la,lb,sig]=armax(0,0,y-ymoy*ones(1,n2),x-xmoy*ones(1,n2),0,dflag);
+  if typeof(la)=='list' then a=lb(1);else a=lb;end
+  b=ymoy-a*xmoy;
 endfunction
index ffee2cf..d68cbb7 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - 
+// Copyright (C) INRIA - Serge Steer
 // 
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -9,90 +9,90 @@
 
 function [frq,rep,splitf]=repfreq(sys,fmin,fmax,pas)
 
-pas_def='auto';
-l10=log(10);
-[lhs,rhs]=argn(0)
-//discretization 
-
-if type(sys)<>16 then  error(97,1),end;
-flag=sys(1);
-dom=sys('dt')
-if dom==[]|dom==0 then error(96,1),end
-if dom=='d' then dom=1;end
+  pas_def='auto';
+  l10=log(10);
+  [lhs,rhs]=argn(0)
+  //discretization 
+  if and(typeof(sys)<>[ 'rational' 'state-space' ]) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"repfreq",1))
+  end
+  dom=sys.dt
+  if dom==[]|dom==0 then error(96,1),end
+  if dom=='d' then dom=1;end
 
-select  rhs
-case 1 then
-  pas=pas_def
-  if dom=='c' then fmax=1.d3; else fmax=1/(2*dom),end
-  fmin=0
-case 2 then
-  if type(fmin)==10 then
-    rhs=1
+  select  rhs
+  case 1 then
     pas=pas_def
     if dom=='c' then fmax=1.d3; else fmax=1/(2*dom),end
-    if fmin=='sym' then
-      fmin=-fmax
-    else
-      fmin=0
-    end
-  else
-    frq=fmin
-  end
-case 3 then
-  pas=pas_def
-case 4 then ,
-else 
-  error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "repfreq",1,4))
-end;
-splitf=1
-if rhs<>2 then
-  if type(pas)==1 then
-    splitf=1
-    eps=1.e-14
-    if fmin<0&fmax>=0 then
-      frq=- [exp(l10*((log(eps)/l10):pas:(log(-fmin)/l10))) -fmin];
-      if fmax>eps then
-        frq1=[exp(l10*((log(eps)/l10):pas:(log(fmax)/l10))) fmax];
-        frq=[frq($:-1:1) frq1]
+    fmin=0
+  case 2 then
+    if type(fmin)==10 then
+      rhs=1
+      pas=pas_def
+      if dom=='c' then fmax=1.d3; else fmax=1/(2*dom),end
+      if fmin=='sym' then
+       fmin=-fmax
       else
-        frq=frq($:-1:1);
+       fmin=0
       end
-    elseif fmin<0&fmax<0 then
-      frq= [exp(l10*((log(-fmax)/l10):pas:(log(-fmin)/l10))) -fmin];
-      frq=-frq($:-1:1);
-    elseif fmin >= fmax then
-         error(msprintf(gettext("%s: Wrong value for input argument: %s < %s expected.\"),"reqfreq","fmin","fmax"));
     else
-      fmin=max(eps,fmin);
-      frq=[exp(l10*((log(fmin)/l10):pas:(log(fmax)/l10))) fmax];
+      frq=fmin
     end
-  else
-    [frq,bnds,splitf]=calfrq(sys,fmin,fmax)
-  end;
-end
-//
-typ=sys(1)
-select typ(1)
-case 'r' then
-  [n,d]=sys(['num','den']),
-  [mn,nn]=size(n)
-  if nn<>1 then error(95,1),end
-  if dom=='c' then 
-    rep=freq(n,d,2*%pi*%i*frq),
+  case 3 then
+    pas=pas_def
+  case 4 then ,
   else 
-    rep=freq(n,d,exp(2*%pi*%i*dom*frq)),
+    error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "repfreq",1,4))
   end;
-case 'lss' then
-  [a,b,c,d,x0]=sys(2:6),
-  [mn,nn]=size(b)
-  if nn<>1 then error(95,1),end
-  if dom=='c' then 
-    rep=freq(a,b,c,d,2*%pi*%i*frq)
-  else 
-    rep=freq(a,b,c,d,exp(2*%pi*%i*dom*frq))
+  splitf=1
+  if rhs<>2 then
+    if type(pas)==1 then
+      splitf=1
+      eps=1.e-14
+      if fmin<0&fmax>=0 then
+       frq=- [exp(l10*((log(eps)/l10):pas:(log(-fmin)/l10))) -fmin];
+       if fmax>eps then
+         frq1=[exp(l10*((log(eps)/l10):pas:(log(fmax)/l10))) fmax];
+         frq=[frq($:-1:1) frq1]
+       else
+         frq=frq($:-1:1);
+       end
+      elseif fmin<0&fmax<0 then
+       frq= [exp(l10*((log(-fmax)/l10):pas:(log(-fmin)/l10))) -fmin];
+       frq=-frq($:-1:1);
+      elseif fmin >= fmax then
+       error(msprintf(gettext("%s: Wrong value for input arguments: %s < %s expected.\n"),"reqfreq","fmin","fmax"));
+      else
+       fmin=max(eps,fmin);
+       frq=[exp(l10*((log(fmin)/l10):pas:(log(fmax)/l10))) fmax];
+      end
+    else
+      [frq,bnds,splitf]=calfrq(sys,fmin,fmax)
+    end;
+  end
+  //
+  typ=sys(1)
+  select typ(1)
+  case 'r' then
+    [n,d]=sys(['num','den']),
+    [mn,nn]=size(n)
+    if nn<>1 then error(95,1),end
+    if dom=='c' then 
+      rep=freq(n,d,2*%pi*%i*frq),
+    else 
+      rep=freq(n,d,exp(2*%pi*%i*dom*frq)),
+    end;
+  case 'lss' then
+    [a,b,c,d,x0]=sys(2:6),
+    [mn,nn]=size(b)
+    if nn<>1 then error(95,1),end
+    if dom=='c' then 
+      rep=freq(a,b,c,d,2*%pi*%i*frq)
+    else 
+      rep=freq(a,b,c,d,exp(2*%pi*%i*dom*frq))
+    end;
+  else error(97,1),
   end;
-else error(97,1),
-end;
-//representation
-if lhs==1 then frq=rep,end
+  //representation
+  if lhs==1 then frq=rep,end
 endfunction
index ca648d5..76bfc48 100644 (file)
@@ -22,35 +22,35 @@ function [x1,x2]=riccati(a,b,c,dom,typ)
 // See also ric_desc
 //!
 
-[lhs,rhs]=argn(0),
-      if rhs==4 then typ='eigen',end,
-      ham=[a -b;-c -a'],
-      [n,n]=size(a),
-      if part(dom,1)=='c' then
-         select  typ,
-           case 'schur' then
-                [s,d]=schur(ham,'c'),
-               if d<>n then 
-                error(msprintf(gettext("%s: Wrong dimension (%s) of stable subspace -expecting %s.\n"),"riccati",string(d), string(n)))
-                end
-                s=s(:,1:n),
-           case 'eigen' then
-                [hb,u1]=bdiag(ham),
-                [u2,d]=schur(hb,'c'),
-                u=u1*u2,
-               if d<>n then 
-                 error(msprintf(gettext("%s: Wrong dimension (%s) of stable subspace -expecting %s.\n"),"riccati",string(d), string(n)))
-                end
-                s=u(:,1:n),
-         end,
-      else
-         aa=[eye(n,n) b;0*ones(n,n) a'],bb=[a  0*ones(n,n);-c eye(n,n)],
-         [bs,as,s,n1]=schur(bb,aa,'d');
-         if n1<>n then 
-                  error(msprintf(gettext("%s: Wrong dimension (%s) of stable subspace -expecting %s.\n"),"riccati",string(n1), string(n)))
-         end
-         s=s(:,1:n1);
-      end,
-      x1=s(n+1:2*n,:),x2=s(1:n,:),
-      if lhs==1 then x1=x1/x2,end
+  [lhs,rhs]=argn(0),
+  if rhs==4 then typ='eigen',end,
+  ham=[a -b;-c -a'],
+  [n,n]=size(a),
+  if part(dom,1)=='c' then
+    select  typ,
+    case 'schur' then
+      [s,d]=schur(ham,'c'),
+      if d<>n then 
+       error(msprintf(gettext("%s: Wrong dimension (%d) of stable subspace: %d expected.\n"),"riccati",d, n))
+      end
+      s=s(:,1:n),
+    case 'eigen' then
+      [hb,u1]=bdiag(ham),
+      [u2,d]=schur(hb,'c'),
+      u=u1*u2,
+      if d<>n then 
+       error(msprintf(gettext("%s: Wrong dimension (%d) of stable subspace: %d expected.\n"),"riccati",d, n))
+      end
+      s=u(:,1:n),
+    end,
+  else
+    aa=[eye(n,n) b;0*ones(n,n) a'],bb=[a  0*ones(n,n);-c eye(n,n)],
+    [bs,as,s,n1]=schur(bb,aa,'d');
+    if n1<>n then 
+      error(msprintf(gettext("%s: Wrong dimension (%d) of stable subspace: %d expected.\n"),"riccati",n1, n))
+    end
+    s=s(:,1:n1);
+  end,
+  x1=s(n+1:2*n,:),x2=s(1:n,:),
+  if lhs==1 then x1=x1/x2,end
 endfunction
index a8c3e36..9c89a9f 100644 (file)
@@ -1,5 +1,5 @@
 function r=routh_t(h,k)
-// Copyright INRIA
+// Copyright INRIA - Serge Steer
 //r=routh_t(h,k) computes routh table of denominator of the
 //system described by transfer matrix SISO continue h with the
 //feedback by the gain k
@@ -11,27 +11,33 @@ function r=routh_t(h,k)
 [lhs,rhs]=argn(0);
 h1=h(1);
 if rhs==2 then
-  if type(h)<>16 then
-    error('first argument must be rational')
-  end;
-  if h1(1)<>'r' then
-    error('first argument must be rational')
-  end;
+  if typeof(h)<>'rational' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Rational array expected.\n"),"routh_t",1));
+  end
   [n,d]=h(2:3)
+  if size(n,'*')<>1 then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"routh_t",1))
+  end
   nd=maxi([degree(d) degree(n)])+1;
   cod=coeff(d,0:nd-1);//coeff du denominateur
   con=coeff(n,0:nd-1);//coeff du numerateur
   cobf=cod+k*con //coeff de la boucle fermee
 else
-  if type(h)>2 then error('argument must be polynomial'),end
+  if type(h)>2 then 
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial array expected.\n"),"routh_t",1));
+  end
+  if size(h,'*')<>1 then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"routh_t",1))
+  end
+
   nd=degree(h)+1;
   cobf=coeff(h,0:nd-1)
 end;
 //
 r1=cobf(nd:-2:1);
 r2=cobf(nd-1:-2:1);
-ncol=length(r1);
-if length(r2)<>ncol then r2=[r2,0],end
+ncol=size(r1,'*');
+if size(r2,'*')<>ncol then r2=[r2,0],end
 r=[r1;r2]
 
 if ncol<2 then r=[],return,end;
index f43a166..9a2ab3f 100644 (file)
@@ -13,69 +13,67 @@ function [] = sgrid(zeta,wn,col)
 // sgrid()
 // sgrid(Z,Wn)
 // sgrid('new') 
-[lhs,rhs]=argn(0)
-if rhs < 3 ; col=3;end
-if rhs==0 then 
-       [a,limits]=xgetech()
-       wmax = 10 .^(floor(log10(max(abs(limits)))));
-       wn= 0:1:10;
-       zeta = linspace(0,1,10);
-end
-if rhs==1 then 
-       if type(zeta)<>10 then 
-               write(%io(2),'sgrid with one argument : sgrid(''new'')')
-               error(999)
-               return
-       end
-       wn = 0:1:10;
-        zeta = [ 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 ];
-       wmax = 10;
-       xbasc();
-       plot2d(0,0,0,"011"," ",[-20,-20,20,20]);
-end
-if rhs>= 2 then 
-       [a,limits]=xgetech()
-       wmax = 10 .^(floor(log10(max(abs(limits)))));
-end 
-       // building a grid 
-       zx = 0:.01:1;
-       [rx,cx]=size(wn);[ry,cy]=size(zx);
-       w=wn.*.ones(cy,1);z=zx'.*.ones(1,cx);
+  [lhs,rhs]=argn(0)
+  axes=gca();
+  select rhs
+  case 0 then 
+    wn= 0:1:10;
+    zeta = linspace(0,1,10);
+    col=3;
+  case 1 then
+    if type(zeta)<>10 then
+      error(msprintf(_("%s: Wrong type for input argument #%d: String array expected.\n"),"sgrid",1))
+    end
+    if size(zeta,'*')<>1 then
+      error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"sgrid",1))
+    end
+    wn = 0:1:10;
+    zeta = [ 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 ];
+    col=3;
+    clf()
+    axes.data_bounds=[-20,-20;20,20];axes.axes_visible='on';
+  case 2 then
+    col=3;
+  end 
+  wmax = 10 .^(floor(log10(max(abs(axes.data_bounds)))));
+  // building a grid 
+  zx = 0:.01:1;
+  [rx,cx]=size(wn);[ry,cy]=size(zx);
+  w=wn.*.ones(cy,1);z=zx'.*.ones(1,cx);
 
-       // plot : part I 
-       re = - w .* z;
-       [zr,zc] = size(z);
-       im = w .* sqrt( 1 - z .* z );
-       plot2d(re,im,col*ones(1,zc),"000");
-       plot2d(re,-im,col*ones(1,zc),"000");
-       
-       // info on curves 
+  // plot : part I 
+  re = - w .* z;
+  [zr,zc] = size(z);
+  im = w .* sqrt( 1 - z .* z );
+  plot2d(re,im,style=col*ones(1,zc));
+  plot2d(re,-im,style=col*ones(1,zc));
+  
+  // info on curves 
 
-       [rer,rec] = size(re)
+  [rer,rec] = size(re)
 
-        axes = gca();
-        axes.clip_state = "clipgrf";
-       xnumb(re(1,:),im(1,:),wn);
-        axes.clip_state = "off";
+  axes.clip_state = "clipgrf";
+  xnumb(re(1,:),im(1,:),wn);
+  axes.clip_state = "off";
 
-       // building an other grid 
+  // building an other grid 
 
-       wn = [0,wn,2*wmax];
-       [rx,cx]=size(wn);[ry,cy]=size(zeta);
-       w=wn.*.ones(cy,1);z=zeta'.*.ones(1,cx);
+  wn = [0,wn,2*wmax];
+  [rx,cx]=size(wn);[ry,cy]=size(zeta);
+  w=wn.*.ones(cy,1);z=zeta'.*.ones(1,cx);
 
-       // plot part II  
+  // plot part II  
 
-       [zr,zc] = size(z);
-       re = -w .* z;
-       im = w .* sqrt( 1 - z .* z );
-       plot2d(re',im',col*ones(1,zr),"000");
-       plot2d(re',-im',col*ones(1,zr),"000");
+  [zr,zc] = size(z);
+  re = -w .* z;
+  im = w .* sqrt( 1 - z .* z );
+  plot2d(re',im',style=col*ones(1,zr));
+  plot2d(re',-im',style=col*ones(1,zr));
 
-       // info on each curve ( straight lines )
-       [rer,rec] = size(re)
-        axes.clip_state = "clipgrf";
-       xnumb(re(:,$)',im(:,$)',zeta);
-        axes.clip_state = "off";
-       
+  // info on each curve ( straight lines )
+  [rer,rec] = size(re)
+  axes.clip_state = "clipgrf";
+  xnumb(re(:,$)',im(:,$)',zeta);
+  axes.clip_state = "off";
+  
 endfunction
index dc5b56d..a9e37f5 100644 (file)
@@ -10,7 +10,7 @@
 function show_margins(h,typ)
   if argn(2)<2 then typ='bode',end
   if and(typ<>['nyquist','bode']) then
-    error(msprintf(_("%s: invalid input argument #%d. Value must be in {%s}"),..
+    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
                   "show_margins",2,'""nyquist"", ""bode""'))
   end
   drawlater();clf();
index 73e073c..2ffbecd 100644 (file)
@@ -12,25 +12,30 @@ function des=sm2ss(sysmat)
 // sysmat=[-s I + A , B; C , D]
 // [n,n]=size(A) 
 
-[LHS,RHS]=argn(0)
-[nl,nc]=size(sysmat);
-E=-coeff(sysmat,1);
-if RHS==1 then
-     k=nc;
-     while E(:,k)==0*E(:,k)
-     k=k-1;n=k;
-     end
-     l=nl;
-     while E(l,:)==0*E(l,:)
-     l=l-1;n1=l;
-     end
-end
-if n1<>n then warning(msprintf(gettext("%s: Cannot find %s.\n"),"sm2ss","n"));end
-E=E(1:n,1:n);
-if E<>eye(n,n) then error(msprintf(gettext("%s: Not state-space system?.\n"),"sm2ss"));end
-A=coeff(sysmat(1:n,1:n),0);
-B=coeff(sysmat(1:n,n+1:nc),0);
-C=coeff(sysmat(n+1:nl,1:n),0);
-D=coeff(sysmat(n+1:nl,n+1:nc),0);
-des=syslin([],A,B,C,D);
+  if typeof(sysmat)<>'polynomial' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial array expected.\n"),"sm2ss",1))
+  end
+  [nl,nc]=size(sysmat);
+  E=-coeff(sysmat,1);
+  k=nc;
+  while and(E(:,k)==0*E(:,k))
+    k=k-1;n=k;
+  end
+  l=nl;
+  while and(E(l,:)==0*E(l,:))
+    l=l-1;n1=l;
+  end
+
+  if n1<>n then 
+    warning(msprintf(gettext("%s: Cannot find %s.\n"),"sm2ss","n"));
+  end
+  E=E(1:n,1:n);
+  if E<>eye(n,n) then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: Not a state-space system.\n"),"sm2ss",1));
+  end
+  A=coeff(sysmat(1:n,1:n),0);
+  B=coeff(sysmat(1:n,n+1:nc),0);
+  C=coeff(sysmat(n+1:nl,1:n),0);
+  D=coeff(sysmat(n+1:nl,n+1:nc),0);
+  des=syslin([],A,B,C,D);
 endfunction
index 53d3d2d..a3948b1 100644 (file)
@@ -33,7 +33,7 @@ function [h,num,den]=ss2tf(sl,rmax)
     return
   end
   flag=sl(1);
-  if (type(sl)<>16)|flag(1)<>'lss' then
+  if typeof(sl)<>'state-space' then
     error(msprintf(gettext("%s: Wrong type for input argument #%d: State-space form expected.\n"),"ss2tf",1));
   end
   if sl(3)==[] then h=sl(5);num=sl(5);den=eye(sl(5));return;end
index 1fccb41..c473b35 100644 (file)
@@ -189,7 +189,9 @@ case 'on'
   b21=b21d1(1:nstate-nv,:);d1=b21d1(nstate-nv+1:nstate-nv+nout,:);
   a21=a21c1(1:nstate-nv,:);c1=a21c1(nstate-nv+1:nstate-nv+nout,:);
 
-  if rk>=nout then error('ssrand: you must choose rk<nout!');end
+  if rk>=nout then 
+    error(msprintf(gettext("%s: Wrong values for input argument #%d: you must choose rk<nout.\n"),"ssrand",4))
+  end
 //  if rk>=nout then j=-b21*pinv(d1);a22=-j*c2;end
   [pp,qq]=size(a21);a21(p1+1:pp,1:nv)=0*a21(p1+1:pp,1:nv);
   b21(p1+1:pp,:)=0*b21(p1+1:pp,:);
index 29b1b55..82db891 100644 (file)
@@ -11,21 +11,26 @@ function [n,nc,u,sl,v]=st_ility(sl,tol)
 //stabilizability test
 
   [lhs,rhs]=argn(0)
-if type(sl)==1 then
-//[n,nc,u,A,B]=st_ility(A,B,tol)
-if rhs==2 
-sl=syslin('c',sl,tol,[]);rhs=1;
-end
-end
+  if type(sl)==1 then
+    //[n,nc,u,A,B]=st_ility(A,B,tol)
+    if rhs==2 
+      sl=syslin('c',sl,tol,[]);rhs=1;
+    end
+  end
+  if typeof(sl)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"st_ility",1))
+  end
+  
   [a,b,c,d,x0,dom]=sl(2:7);
   if dom==[] then 
-    dom='c';warning(msprintf(gettext("%s: time domain not given => sl assumed continuous!"),"st_ility"));
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"st_ility",1)); 
+    dom='c';
   end
   typ='c';if dom<>'c' then typ='d',end
   [na,na]=size(a);
   [nw,nb]=size(b);
   if nb==0 then
-  b=zeros(na,1);
+    b=zeros(na,1);
   end
   // controllable part
   if rhs==1 then 
@@ -34,7 +39,7 @@ end
     [n,u,ind,V,a,b]=contr(a,b,tol);
   end;
   if nb==0 then
-  b=[];
+    b=[];
   end;
   n=sum(n);nc=n;
   if lhs==4 then c=c*u;x0=u'*x0;end
index 8a2471c..802caa6 100644 (file)
@@ -9,28 +9,30 @@
 
 function st=statgain(sl)
 
-
-if type(sl)<>16 then error(97,1),end
-flag=sl(1);
-select flag(1)
-case 'lss'
-  dom=sl(7);
-  [m,p]=size(sl(2));
-  if dom=='c' then
-    if rank(sl(2)) <> m then error(msprintf(gettext("%s: Singular A matrix.\n"),"statgain")),end
-    st=sl(5)-sl(4)*inv(sl(2))*sl(3);
-  else
-    if rank(eye(m,m)-sl(2))<>m then error(msprintf(gettext("%s: Singular eye-a matrix.\n"),"statgain")),end
-    st=sl(5)+sl(4)*inv(eye(m,m)-sl(2))*sl(3);
-  end;
-case 'r' then
-  dom=sl('dt')
-  if dom=='c' then
-    st=freq(sl('num'),sl('den'),0)
+  select typeof(sl)
+  case 'rational' then
+    dom=sl('dt')
+    if dom=='c' then
+      st=freq(sl('num'),sl('den'),0)
+    else
+      st=freq(sl('num'),sl('den'),1)
+    end;
+  case 'state-space' then
+    dom=sl.dt;
+    [m,p]=size(sl(2));
+    if dom=='c' then
+      if rank(sl(2)) <> m then 
+       error(msprintf(gettext("%s: Wrong values for input argument #%d: Singular A matrix.\n"),"statgain",1)),
+      end
+      st=sl(5)-sl(4)*inv(sl(2))*sl(3);
+    else
+      if rank(eye(m,m)-sl(2))<>m then 
+       error(msprintf(gettext("%s: Wrong values for input argument #%d: Singular eye-A matrix.\n"),"statgain",1))
+      end
+      st=sl(5)+sl(4)*inv(eye(m,m)-sl(2))*sl(3);
+    end;
   else
-    st=freq(sl('num'),sl('den'),1)
-  end;
-else  
-  error(97,1)
-end
+    error(97,1)
+  end
 endfunction
index a8b5fa5..81d739e 100644 (file)
@@ -7,71 +7,69 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function [svm] = svplot(Sl,w)
-//SVPLOT singular-value sigma-plot.
-// SVM = SVPLOT(SL,W) computes for the system
-// SL=(A,B,C,D), the singular values of its transfer function matrix:
+function svm = svplot(Sl,w)
+//svplot singular-value sigma-plot.
+// svm = svplot(sl,w) computes for the linear dynamical system
+// sl, the singular values of its transfer function matrix:
 //                              -1
-//             G(jw) = C(jw*I-A)  B+D
+//             g(jw) = c(jw*i-a)  b+d
 //
 //           or
 //                                        -1
-//             G(exp(jw)) = C(exp(jw)*I-A)  B+D
+//             g(exp(jw)) = c(exp(jw)*i-a)  b+d
 //
-// evaluated over the frequency range specified by W.
-// SL is a sylin list (see syslin) representing the system
-// [A,B,C,D] in state-space form.
-// The i-th column of the output matrix SVM contains the singular
-// values of G(exp(jw)) for the i-th frequency value.
-// SVM = SVPLOT(Sl) is equivalent to
-// SVM = SVPLOT(Sl,LOGSPACE(-3,3))  (continuous) or
-// SVM = SVPLOT(Sl,LOGSPACE(-3,PI)) (discrete).
+// evaluated over the frequency range specified by w.
+// sl is a sylin list (see syslin) representing the system
+// [a,b,c,d] in state-space form.
+// the i-th column of the output matrix svm contains the singular
+// values of g(exp(jw)) for the i-th frequency value.
+// svm = svplot(sl) is equivalent to
+// svm = svplot(sl,logspace(-3,3))  (continuous) or
+// svm = svplot(sl,logspace(-3,pi)) (discrete).
 //!
 
-[nargout,nargin]=argn(0);
-//
-[a,b,c,d]=abcd(Sl);
-// Reduce a to Hessenberg form
-[q,a] = hess(a); b = q'*b; c = c*q;
-// Compute the singular values of the frequency response
-select Sl(7)
-case []
-   warning(msprintf(gettext("%s: Time domain not defined: Assumed continuous.\n."),"svplot"));
-if nargin == 1
-   w = logspace(-3,3);
-end
-nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
-svm(nsv,nf) = 0;
-for i = 1:nf
-    svm(:,i) = svd(c*((j*w(i)*eye()-a)\b)+d);
-end
-case 'c'
-if nargin == 1
-   w = logspace(-3,3);
-end
-nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
-svm(nsv,nf) = 0;
-for i = 1:nf
-    svm(:,i) = svd(c*((j*w(i)*eye()-a)\b)+d);
-end
-case 'd'
-if nargin == 1
-   w = logspace(-3,%pi);
-end
-nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
-svm(nsv,nf) = 0;
-for i = 1:nf
-    svm(:,i) = svd(c*((exp(j*w(i))*eye()-a)\b)+d);
-  end
-else T=Sl('dt');
-if nargin == 1
-   w = logspace(-3,%pi);
-end
-nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
-svm(nsv,nf) = 0;
-for i = 1:nf
-    svm(:,i) = svd(c*((exp(j*w(i)*T)*eye()-a)\b)+d);
+  [a,b,c,d]=abcd(Sl);
+  // Reduce a to Hessenberg form
+  [q,a] = hess(a); b = q'*b; c = c*q;
+  // Compute the singular values of the frequency response
+  select Sl.dt
+  case []
+    warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"svplot",1)); 
+    if argn(2) == 1
+      w = logspace(-3,3);
+    end
+    nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
+    svm(nsv,nf) = 0;
+    for i = 1:nf
+      svm(:,i) = svd(c*((j*w(i)*eye()-a)\b)+d);
+    end
+  case 'c'
+    if argn(2) == 1
+      w = logspace(-3,3);
+    end
+    nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
+    svm(nsv,nf) = 0;
+    for i = 1:nf
+      svm(:,i) = svd(c*((j*w(i)*eye()-a)\b)+d);
+    end
+  case 'd'
+    if argn(2) == 1
+      w = logspace(-3,%pi);
+    end
+    nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
+    svm(nsv,nf) = 0;
+    for i = 1:nf
+      svm(:,i) = svd(c*((exp(j*w(i))*eye()-a)\b)+d);
+    end
+  else T=Sl('dt');
+    if argn(2) == 1
+      w = logspace(-3,%pi);
+    end
+    nf = maxi(size(w)); nsv = mini(size(d)); j = sqrt(-1);
+    svm(nsv,nf) = 0;
+    for i = 1:nf
+      svm(:,i) = svd(c*((exp(j*w(i)*T)*eye()-a)\b)+d);
+    end
+    
   end
-  
-end
 endfunction
index 6af6554..8def4b5 100644 (file)
@@ -13,10 +13,10 @@ function X = sylv(A,B,C,flag)
   if size(A,1)<> size(A,2) then error(20,1),end
   if size(B,1)<> size(B,2) then error(20,2),end
   if size(C,1)<> size(A,1) then 
-    error(msprintf(gettext("%s: Wrong values for input arguments #%d and #%d: Incompatible number of rows.\n"),"sylv",1,3))
+    error(msprintf(gettext("%s: Wrong values for input arguments #%d and #%d: Same row dimensions expected.\n"),"sylv",1,3))
   end
   if size(C,2)<> size(B,2) then 
-       error(msprintf(gettext("%s: Wrong values for input arguments #%d and #%d: Incompatible number of columns.\n"),"sylv",2,3))
+    error(msprintf(gettext("%s: Wrong values for input arguments #%d and #%d:Same column dimensions expected.\n"),"sylv",2,3))
   end
     
   if flag=='c' then 
index 59864a5..c16b1c3 100644 (file)
 
 function [sl]=syslin(domain,a,b,c,d,x0)
 
-[lhs,rhs]=argn(0)
-//
-// check domain 
-select type(domain)
-case 1 then  //sampled system
-  if size(domain,'*')<=2 then
-    tp=domain
-  else
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"),"syslin",1))
-  end
-  z='z'
-case 10 //continuous or discrete
-  if size(domain,'*')<>1 then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"syslin",1))
-  end
-  domain=part(domain,1)
-  select domain
-  case 'c' then 
-    z='s'
-  case 'd' then 
+  [lhs,rhs]=argn(0)
+  //
+  // check domain 
+  select type(domain)
+  case 1 then  //sampled system
+    if size(domain,'*')<=2 then
+      tp=domain
+    else
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: A real expected.\n"),"syslin",1))
+    end
     z='z'
+  case 10 //continuous or discrete
+    if size(domain,'*')<>1 then
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"syslin",1))
+    end
+    
+    domain=part(domain,1)
+    select domain
+    case 'c' then 
+      z='s'
+    case 'd' then 
+      z='z'
+    else 
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "syslin",1,"''c'',''d''"))
+    end;
   else 
-    error(msprintf(gettext("%s: %s: Unknown time domain.\n"), "syslin",domain))
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: String, Scalar or empty matrix expected.\n"),"syslin",1))
   end;
-else 
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: Single, Scalar or [] matrix expected.\n"),"syslin",1))
-end;
-//============================================================================
-if rhs==2 then //syslin(domaine,sys)
+  //============================================================================
+  if rhs==2 then //syslin(domaine,sys)
 
-  if type(a)<>16 then 
-    error()
-  else
-    if a(1)(1)=='r'|a(1)(1)=='lss' then
-      sl=a;
-      sl('dt')=domain
-       else
-         error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"syslin",2))
+    if type(a)<>16 then 
+      error()
+    else
+      if a(1)(1)=='r'|a(1)(1)=='lss' then
+       sl=a;
+       sl('dt')=domain
+      else
+       error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"syslin",2))
+      end
     end
-  end
-//============================================================================
-elseif rhs==3 then // syslin(domaine,num,den)
-  num=a;den=b
-  if type(num)>2 | type(den)>2 then
-    error(msprintf(gettext("%s: %s and %s must be matrix of numbers or of polynomials.\n"),"syslin","N","D"))
-  end
-  if or(size(num)<>size(den)) then
-    error(msprintf(gettext("%s: %s and %s have inconsistent dimensions.\n"),"syslin","N","D"))
-  end
-
-  if type(num)==2 & type(den)==2 then
-    if varn(num)<>varn(den) then 
-         error(msprintf(gettext("%s: %s and %s have inconsistent formal variable names.\n"),"syslin","N","D"))
+    //============================================================================
+  elseif rhs==3 then // syslin(domaine,num,den)
+    num=a;den=b
+    if type(num)>2 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial array expected.\n"),"syslin",2))
     end
-  end
-  if type(num)==1 then
-    num=num*poly(1,z,'c')
-  end
-   if type(den)==1 then
-    den=den*poly(1,z,'c')
-  end
-  
-  sl=rlist(varn(num,z),varn(den,z),domain)
-//============================================================================
-elseif rhs>3 then // syslin(domaine,A,B,C [,D [X0]])
-  if type(a)<>1 then
-    error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of real expected.\n"),"syslin",2))
-  end
-  [ma,na]=size(a);
-  if ma<>na then 
-       error(msprintf(gettext("%s: Wrong type for input argument #%d: Square Matrix of real expected.\n"),"syslin",2))
-  end
-  if type(b)<>1 then
-       error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of real expected.\n"),"syslin",3))
-  end
-  [mb,nb]=size(b);
-  if na<>mb&mb<>0 then 
-    error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d (row dimension).\n"),"syslin",2,3));
-  end
-  if type(c)<>1 then
-       error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of real expected.\n"),"syslin",4))
-  end
-  [mc,nc]=size(c);
-  if na<>nc&nc<>0 then 
-       error(msprintf(gettext("%s: Wrong size for input arguments #%d and #%d (column dimension).\n"),"syslin",2,4));
-  end
-  if rhs<6 then
-    x0=0*ones(na,1)
-  else
-    if type(x0)>1 then
-         error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of real expected.\n"),"syslin",6))
+    if  type(den)>2 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial array expected.\n"),"syslin",3))
     end
-    [mx,nx]=size(x0);
-    if mx<>na|nx<>min(na,1) then 
-         error(msprintf(gettext("%s: Wrong size for input argument #%d.\n"),"syslin",6));
+    
+    if or(size(num)<>size(den)) then
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"syslin",2,3))
     end
-  end
-  if rhs<5  then
-    d=0*ones(mc,nb)
-  else
-    if type(d)>2 then
-         error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of real and polynomials expected.\n"),"syslin",5))
-    end
-    [md,nd]=size(d);
-    if c*b<>[] then
-      if mc<>md|nb<>nd then 
-               error(msprintf(gettext("%s: Wrong size for input argument #%d, #%d and #%d.\n"),"syslin",3,4,5));
 
+    if type(num)==2 & type(den)==2 then
+      if varn(num)<>varn(den) then 
+       error(msprintf(gettext("%s: Incompatible input arguments #%d² and #%d: Same formal variable names expected.\n"),"syslin",2,3))
       end
     end
+    if type(num)==1 then
+      num=num*poly(1,z,'c')
+    end
+    if type(den)==1 then
+      den=den*poly(1,z,'c')
+    end
+    
+    sl=rlist(varn(num,z),varn(den,z),domain)
+    //============================================================================
+  elseif rhs>3 then // syslin(domaine,A,B,C [,D [X0]])
+    if type(a)<>1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of floating point numbers expected.\n"),"syslin",2))
+    end
+    [ma,na]=size(a);
+    if ma<>na then 
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: Square matrix expected.\n"),"syslin",2))
+    end
+    if type(b)<>1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of floating point numbers expected.\n"),"syslin",3))
+    end
+    [mb,nb]=size(b);
+    if na<>mb&mb<>0 then 
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same row dimensions expected.\n"),"syslin",2,3));
+    end
+    if type(c)<>1 then
+      error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of floating point numbers expected.\n"),"syslin",4))
+    end
+    [mc,nc]=size(c);
+    if na<>nc&nc<>0 then 
+      error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),"syslin",2,4));
+    end
+    if rhs<6 then
+      x0=0*ones(na,1)
+    else
+      if type(x0)>1 then
+       error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of floating point numbers expected.\n"),"syslin",6))
+      end
+      [mx,nx]=size(x0);
+      if mx<>na|nx<>min(na,1) then 
+       error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                              "number of elements of #%d must match the column dimension of #%d\n"),"syslin",6,1,6,1));
+      end
+    end
+    if rhs<5  then
+      d=0*ones(mc,nb)
+    else
+      if type(d)>2 then
+       error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial array expected.\n"),"syslin",5))
+      end
+      [md,nd]=size(d);
+      if c*b<>[] then
+       if mc<>md then 
+         error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same row dimensions expected.\n"),"syslin",2,5));
+       end
+       if nb<>nd then 
+         error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"),"syslin",3,5));
+       end
+       
+      end
+    end
+    sl=lsslist(a,b,c,d,x0,domain)
   end
-  sl=lsslist(a,b,c,d,x0,domain)
-end
+  
 endfunction
index 7cbe190..9703305 100644 (file)
@@ -9,41 +9,41 @@
 
 function [h,err]=time_id(n,u,y)
 
-[lhs,rhs]=argn(0)
-y=y(:)
-npt=size(y,'*');
-select type(u)
-case 1 then
-  u=u(:)
-case 10 then
-  select part(u,1)
-  case 'i' then 
-   u=eye(npt,1)
-  case 's' then
-    u=ones(npt,1)
+  [lhs,rhs]=argn(0)
+  y=y(:)
+  npt=size(y,'*');
+  select type(u)
+  case 1 then
+    u=u(:)
+  case 10 then
+    select part(u,1)
+    case 'i' then 
+      u=eye(npt,1)
+    case 's' then
+      u=ones(npt,1)
+    else
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"time_id",2,"""i"",""s"""))
+    end
   else
-    error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"time_id",2,"i","s"))
+    error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"time_id",2,"""i"",""s"""))
+  end
+  if y(1)==0 then // strictly proper case
+    m(npt-1,2*n)=0;
+    for k=1:n,m(k:npt-1,[k k+n])=[-y(1:npt-k) u(1:npt-k)];end
+    coef=m\y(2:npt);
+    num=poly(coef(2*n:-1:n+1),'z','c');
+    den=poly([coef(n:-1:1);1],'z','c');
+  else
+    m(npt,2*n+2)=0;
+    for k=1:n+1,m(k:npt,[k k+n+1])=[-y(1:npt-k+1) u(1:npt-k+1)];end
+    coef=-m(:,2:$)\m(:,1)
+    num=poly(coef(2*n+1:-1:n+1),'z','c');
+    den=poly([coef(n:-1:1);1],'z','c');
   end
-else
-  error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"time_id",2,"i","s"))
-end
-if y(1)==0 then // strictly proper case
-  m(npt-1,2*n)=0;
-  for k=1:n,m(k:npt-1,[k k+n])=[-y(1:npt-k) u(1:npt-k)];end
-  coef=m\y(2:npt);
-  num=poly(coef(2*n:-1:n+1),'z','c');
-  den=poly([coef(n:-1:1);1],'z','c');
-else
-  m(npt,2*n+2)=0;
-  for k=1:n+1,m(k:npt,[k k+n+1])=[-y(1:npt-k+1) u(1:npt-k+1)];end
-  coef=-m(:,2:$)\m(:,1)
-  num=poly(coef(2*n+1:-1:n+1),'z','c');
-  den=poly([coef(n:-1:1);1],'z','c');
-end
 
-h=syslin('d',num,den)
+  h=syslin('d',num,den)
 
-if lhs==2 then 
-  err=norm(y-rtitr(num,den,u')',2)
-end
+  if lhs==2 then 
+    err=norm(y-rtitr(num,den,u')',2)
+  end
 endfunction
index 5b32f4a..26ac491 100644 (file)
@@ -14,166 +14,164 @@ function h=trfmod(h,job)
 //     job='f' : visualization of natural frequencies and damping
 //
 //!
-
-
-
-typ=type(h);h1=h(1);
-
-if typ==16&h1(1)=='r' then
-  if size(h('num'))<>[1 1] then
-    error(msprintf(gettext("%s: SISO plant only"),"trfmod"))
-  end
-  flag='r'
-elseif typ==16&h1(1)=='lss' then
-  if size(h('D'))<>[1 1] then
-       error(msprintf(gettext("%s: SISO plant only"),"trfmod"))
-  end
-  flag='lss'
-  den=real(poly(h('A'),'s'))
-  na=degree(den)
-  c=h(4)
-  [m,i]=maxi(abs(c))
-  ci=c(i)
-  t=eye(h(2))*ci;t(i,:)=[-c(1:i-1), 1, -c(i+1:na)]
-  al=h(2)*t;
-  t=eye(h(2))/ci;t(i,:)=[c(1:i-1)/ci, 1, c(i+1:na)/ci]
-  al=t*al;ai=al(:,i),
-  b=t*h(3)
-  al(:,i)=ai+b
-  num=-(real(poly(al,'s'))-den)*ci
-  h=syslin(h(7),num+h(5)*den,den);
-else
-  error(msprintf(gettext("%s: Waiting for a transfer function as argument.\n"),"trfmod"))
-end
-//
-format('v',15)
-[lhs,rhs]=argn(0)
-if rhs==1 then job='p',end
-//
-if type(h('num'))==1 then h('num')=poly(h('num'),varn(h('den')),'c'),end
-if type(h('den'))==1 then h('den')=poly(h('den'),varn(h('num')),'c'),end
-var=varn(h('num')),nv=length(var);
-while part(var,nv)==' ' then nv=nv-1,end;var=part(var,1:nv);
-fnum=polfact(h('num'))
-fden=polfact(h('den'))
-g=coeff(fnum(1))/coeff(fden(1))
-nn=prod(size(fnum))
-nd=prod(size(fden))
-//
-num=[]
-for in=2:nn
-  p=fnum(in)
-  if job=='p' then
-    num=[num;pol2str(p)]
+  select typeof(h)
+  case 'rational' then
+    if size(h('num'))<>[1 1] then
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"trfmod",1))
+    end
+    flag='r'
+  case 'state-space' then
+    if size(h('D'))<>[1 1] then
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"trfmod",1))
+    end
+    flag='lss'
+    den=real(poly(h('A'),'s'))
+    na=degree(den)
+    c=h(4)
+    [m,i]=maxi(abs(c))
+    ci=c(i)
+    t=eye(h(2))*ci;t(i,:)=[-c(1:i-1), 1, -c(i+1:na)]
+    al=h(2)*t;
+    t=eye(h(2))/ci;t(i,:)=[c(1:i-1)/ci, 1, c(i+1:na)/ci]
+    al=t*al;ai=al(:,i),
+    b=t*h(3)
+    al(:,i)=ai+b
+    num=-(real(poly(al,'s'))-den)*ci
+    h=syslin(h(7),num+h(5)*den,den);
   else
-    if degree(p)==2 then
-      p=coeff(p)
-      omeg=sqrt(p(1))
-      xsi=p(2)/(2*omeg)
-      num=[num;string(omeg)+'    '+string(xsi)]
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"trfmod",1))
+  end
+  
+  
+  //
+  format('v',15)
+  [lhs,rhs]=argn(0)
+  if rhs==1 then job='p',end
+  //
+  if type(h('num'))==1 then h('num')=poly(h('num'),varn(h('den')),'c'),end
+  if type(h('den'))==1 then h('den')=poly(h('den'),varn(h('num')),'c'),end
+  
+  var=varn(h('num')),nv=length(var);
+  while part(var,nv)==' ' then nv=nv-1,end;var=part(var,1:nv);
+  
+  fnum=polfact(h('num'))
+  fden=polfact(h('den'))
+  g=coeff(fnum(1))/coeff(fden(1))
+  nn=prod(size(fnum))
+  nd=prod(size(fden))
+  //
+  num=[]
+  for in=2:nn
+    p=fnum(in)
+    if job=='p' then
+      num=[num;pol2str(p)]
     else
-      num=[num;string(-coeff(p,0))]
+      if degree(p)==2 then
+       p=coeff(p)
+       omeg=sqrt(p(1))
+       xsi=p(2)/(2*omeg)
+       num=[num;string(omeg)+'    '+string(xsi)]
+      else
+       num=[num;string(-coeff(p,0))]
+      end
     end
   end
-end
-//
-den=[];
-for id=2:nd
-  p=fden(id)
-  if job=='p' then
-    den=[den;pol2str(p)]
-  else
-    if degree(p)==2 then
-      p=coeff(p)
-      omeg=sqrt(p(1))
-      xsi=p(2)/(2*omeg)
-      den=[den;string(omeg)+'    '+string(xsi)]
+  //
+  den=[];
+  for id=2:nd
+    p=fden(id)
+    if job=='p' then
+      den=[den;pol2str(p)]
     else
-      den=[den;string(-coeff(p,0))]
+      if degree(p)==2 then
+       p=coeff(p)
+       omeg=sqrt(p(1))
+       xsi=p(2)/(2*omeg)
+       den=[den;string(omeg)+'    '+string(xsi)]
+      else
+       den=[den;string(-coeff(p,0))]
+      end
     end
   end
-end
-txt=['Gain :';string(g);'Numerator :';num;'Denominator : ';den]
-id=[]
-if job=='p' then
-  tit=[gettext("Irreducible Factors of transfer function (click below)")]
-else
-  tit=[gettext("Irreducible Factors of transfer function natural frequency and damping factor (click below)")]
-end
-while id==[] then
-  t=x_dialog(tit,txt)
-  id=find(t=='Denominator : ')
-end
-txt=t;
-tgain=txt(2)
-tnum=txt(4:id-1)
-tden=txt(id+1:prod(size(txt)))
-execstr(var+'=poly(0,'''+var+''')')
-num=1
-for in=1:prod(size(tnum))
-  txt=tnum(in)
-  if length(txt)==0 then txt=' ',end
+  
+  txt=[_("Gain :");string(g);_("Numerator :");num;_("Denominator :");den]
+  
+  id=[]
   if job=='p' then
-    t=' ';
-    for k=1:length(txt),
-      tk=part(txt,k),
-      if tk<>' ' then t=t+tk,end
-    end
-    f=1;if t<>' ' then f=evstr(t),end
+    tit=[gettext("Irreducible Factors of transfer function (click below)")]
   else
-    if txt==part(' ',1:length(txt)) then
-      f=1
+    tit=[gettext("Irreducible Factors of transfer function natural frequency and damping factor (click below)")]
+  end
+  while id==[] then
+    t=x_dialog(tit,txt)
+    id=find(t==_("Denominator : "))
+  end
+  txt=t;
+  
+  tgain=txt(2)
+  tnum=txt(4:id-1)
+  tden=txt(id+1:prod(size(txt)))
+  execstr(var+'=poly(0,'''+var+''')')
+  num=1
+  for in=1:prod(size(tnum))
+    txt=tnum(in)
+    if length(txt)==0 then txt=' ',end
+    if job=='p' then
+      t=' ';
+      for k=1:length(txt),
+       tk=part(txt,k),
+       if tk<>' ' then t=t+tk,end
+      end
+      f=1;if t<>' ' then f=evstr(t),end
     else
-      f=evstr(txt)
-      select prod(size(f))
-      case 1 then
-        f=poly(f,var)
-      case 2 then
-        f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
-      else error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+      if txt==part(' ',1:length(txt)) then
+       f=1
+      else
+       f=evstr(txt)
+       select prod(size(f))
+       case 1 then
+         f=poly(f,var)
+       case 2 then
+         f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
+       else 
+         error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+       end
       end
     end
+    num=num*f
   end
-  num=num*f
-end
-//
-den=1
-for id=1:prod(size(tden))
-  txt=tden(id);
-  if length(txt)==0 then txt=' ',end
-  if job=='p' then
-    t=' ';
-    for k=1:length(txt),
-      tk=part(txt,k),
-      if tk<>' ' then t=t+tk,end
-    end
-    f=1;if t<>' ' then f=evstr(t),end
-  else
-    if txt==part(' ',1:length(txt)) then
-      f=1
+  //
+  den=1
+  for id=1:prod(size(tden))
+    txt=tden(id);
+    if length(txt)==0 then txt=' ',end
+    if job=='p' then
+      t=' ';
+      for k=1:length(txt),
+       tk=part(txt,k),
+       if tk<>' ' then t=t+tk,end
+      end
+      f=1;if t<>' ' then f=evstr(t),end
     else
-      f=evstr(txt)
-      select prod(size(f))
-      case 1 then
-        f=poly(f,var)
-      case 2 then
-        f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
-      else error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+      if txt==part(' ',1:length(txt)) then
+       f=1
+      else
+       f=evstr(txt)
+       select prod(size(f))
+       case 1 then
+         f=poly(f,var)
+       case 2 then
+         f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
+       else 
+         error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+       end
       end
     end
+    den=den*f
   end
-  den=den*f
-end
-x=evstr(tgain)/coeff(den,degree(den))
-h('num')=num*x
-h('den')=den/coeff(den,degree(den))
-format(10)
-if flag=='lss' then h=tf2ss(h),end
+  x=evstr(tgain)/coeff(den,degree(den))
+  h('num')=num*x
+  h('den')=den/coeff(den,degree(den))
+  format(10)
+  if flag=='lss' then h=tf2ss(h),end
 endfunction
index 94db9e7..87667a7 100644 (file)
@@ -12,79 +12,91 @@ function [nt,dt,rk]=trzeros(Sl)
 // Syntax : [nt,dt]=trzeros(Sl)
 //!
 
-[LHS,RHS]=argn(0);
-if type(Sl)==2 then 
-  D=Sl;
-  [m,n]=size(D);
-  if m<>n then 
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: Square polynomial matrix expected.\n"),"trzeros",1));
+  [LHS,RHS]=argn(0);
+  sltyp=typeof(Sl)
+
+  if sltyp == 'polynomial' then
+    D=Sl;
+    [m,n]=size(D);
+    if m<>n then 
+      error(msprintf(gettext("%s: Wrong size for input argument #%d: Square matrix expected.\n"),"trzeros",1));
+      return;
+    end
+    chis=det(D);nt=roots(chis);dt=ones(nt);
+    if LHS==1 then 
+      nt=nt./dt;dt=[];rk=[];
+    end
     return;
   end
-  chis=det(D);nt=roots(chis);dt=ones(nt);
-  if LHS==1 then 
-    nt=nt./dt;dt=[];rk=[];
+  
+  if sltyp == 'rational' then
+    if size(Sl)==1 then 
+      nt=roots(Sl('num'));dt=[];rk=1;
+      return;
+    end
+    Sl=tf2ss(Sl);
+  end
+  
+  if typeof(Sl)<>'state-space' then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial, linear state space or transfer function expected.\n"),"trzeros",1))
   end
-  return;
-end
-flag=Sl(1);
-if flag(1)<>'lss'&flag(1)<>'r' then 
-  error(msprintf(gettext("%s: Wrong type for input argument: Linear system or polynomial matrix expected.\n"),"trzeros"));
-end
-if flag(1)=='r' then 
-   if size(Sl)==1 then nt=roots(Sl('num'));dt=[];rk=1;return;end
-   Sl=tf2ss(Sl);
-end
-//Sl=minss(Sl);
-[A,B,C,D]=Sl(2:5);
-if type(D)==2 then 
-  [m,n]=size(D);
-  if m<>n then error(msprintf(gettext("%s: Wrong value for input argument %s: Square matrix expected.\n'),"trzeros","D"));return;end
-   chis=det(systmat(Sl));nt=roots(chis);dt=ones(nt);
-   if LHS==1 then nt=nt./dt;dt=[];rk=[];end
-   return;
-end
-if size(A,'*')==0 then 
+  
+  //Sl=minss(Sl);
+  [A,B,C,D]=Sl(2:5);
+  if type(D)==2 then 
+    [m,n]=size(D);
+    if m<>n then 
+      error(msprintf(gettext("%s: Wrong value for input argument #%d: Square system expected.\n'),"trzeros",1));
+    end
+    chis=det(systmat(Sl));nt=roots(chis);dt=ones(nt);
+    if LHS==1 then nt=nt./dt;dt=[];rk=[];end
+    return;
+  end
+  
+  if size(A,'*')==0 then 
     if type(D)==1 then nt=[];dt=[];return;end;
     if type(D)==2 then 
-       [m,n]=size(D);
-       if m<>n then error(msprintf(gettext("%s: Wrong value for input argument %s: Square expected.\n"),"trzeros","D(s)"));return;end
-       chis=det(D);nt=roots(chis);dt=ones(nt);
-       if LHS==1 then nt=nt./dt;dt=[];rk=[];end
-    return;
+      [m,n]=size(D);
+      if m<>n then 
+       error(msprintf(gettext("%s: Wrong value for input argument #%d: Square system expected.\n"),"trzeros",1));
+      end
+      chis=det(D);nt=roots(chis);dt=ones(nt);
+      if LHS==1 then nt=nt./dt;dt=[];rk=[];end
+      return;
     end;
-end;
-[ld,kd]=size(D);
-if norm(D,1)<sqrt(%eps)|ld==kd then
- [nt,dt,rk]=tr_zer(A,B,C,D);
- if norm(dt,1) > 1.d-10 then
- if LHS==1 then nt=nt./dt;dt=[];rk=[];end
- return;
- end
-end
-if ld < kd & norm(D*pinv(D)-eye(),1)< 1.d-10
- //nt=spec(A-B*pinv(D)*C);dt=ones(nt);
- [nt,dt]=tr_zer(A,B,C,D);
- rk=ld;
- if LHS==1 then nt=nt./dt;end;
- return;
-end
-if ld > kd & norm(pinv(D)*D-eye(),1)< 1.d-10
- //nt=spec(A-B*pinv(D)*C);dt=ones(nt);
- [nt,dt]=tr_zer(A,B,C,D);
- rk=kd;
- if norm(dt,1) > 1.d-10 then
-   if LHS==1 then nt=nt./dt;dt=[];rk=[];end;return;
- end
-end
-//warning('Trzeros:non-square system with D non zero and not full')
-//By kronecker form
-s=poly(0,'s');
-syst_matrix=systmat(Sl); //form system matrix
-[Q,Z,Qd,Zd,numbeps,numbeta]=kroneck(syst_matrix);
-ix=Qd(1)+Qd(2)+1:Qd(1)+Qd(2)+Qd(3);
-iy=Zd(1)+Zd(2)+1:Zd(1)+Zd(2)+Zd(3);
-finitepencil=Q(ix,:)*syst_matrix*Z(:,iy);
-[E,A]=pen2ea(finitepencil);
-[nt,dt]=spec(A,E);rk=[];
-if LHS==1 then nt=nt./dt;dt=[];rk=[];end;
+  end;
+  [ld,kd]=size(D);
+  if norm(D,1)<sqrt(%eps)|ld==kd then
+    [nt,dt,rk]=tr_zer(A,B,C,D);
+    if norm(dt,1) > 1.d-10 then
+      if LHS==1 then nt=nt./dt;dt=[];rk=[];end
+      return;
+    end
+  end
+  if ld < kd & norm(D*pinv(D)-eye(),1)< 1.d-10
+    //nt=spec(A-B*pinv(D)*C);dt=ones(nt);
+    [nt,dt]=tr_zer(A,B,C,D);
+    rk=ld;
+    if LHS==1 then nt=nt./dt;end;
+    return;
+  end
+  if ld > kd & norm(pinv(D)*D-eye(),1)< 1.d-10
+    //nt=spec(A-B*pinv(D)*C);dt=ones(nt);
+    [nt,dt]=tr_zer(A,B,C,D);
+    rk=kd;
+    if norm(dt,1) > 1.d-10 then
+      if LHS==1 then nt=nt./dt;dt=[];rk=[];end;return;
+    end
+  end
+  //warning('Trzeros:non-square system with D non zero and not full')
+  //By kronecker form
+  s=poly(0,'s');
+  syst_matrix=systmat(Sl); //form system matrix
+  [Q,Z,Qd,Zd,numbeps,numbeta]=kroneck(syst_matrix);
+  ix=Qd(1)+Qd(2)+1:Qd(1)+Qd(2)+Qd(3);
+  iy=Zd(1)+Zd(2)+1:Zd(1)+Zd(2)+Zd(3);
+  finitepencil=Q(ix,:)*syst_matrix*Z(:,iy);
+  [E,A]=pen2ea(finitepencil);
+  [nt,dt]=spec(A,E);rk=[];
+  if LHS==1 then nt=nt./dt;dt=[];rk=[];end;
 endfunction
index 409dd6d..b10283f 100644 (file)
@@ -62,48 +62,58 @@ function [UIobs,J,N]=ui_observer(Sys,reject,C1,D1,flag,Alfa,Beta)
 //2nd ex: nx=2;ny=3;nwu=2;Sys=ssrand(ny,nwu,nx);
 //        C1=rand(1,nx);D1=[0,1];
 //        UIobs=ui_observer(Sys,1,C1,D1);
-[LHS,RHS]=argn(0);
-if RHS==6 then Beta=-1;end
-if RHS==5 then Beta=-1;Alfa=-1;end
-if RHS==4 then Beta=-1;Alfa=-1;flag='st';end
-if RHS==3 then Beta=-1;Alfa=-1;flag='st';D1=[];end
-if size(C1,2) ~= size(Sys('A'),1) then error(msprintf(gettext("%s: ''%s'' and ''%s'' have incompatible dimensions.\n"),"ui_observer","C1","A"));end
-if size(D1,2) ~= size(Sys('B'),2) then error(msprintf(gettext("%s: ''%s'' and ''%s'' have incompatible dimensions.\n"),"ui_observer","D1","B"));end
-not_reject=1:size(Sys,'c');not_reject(reject)=[];
-Sys1=Sys(:,reject);      //A,B1,C2,D21
-[X,dims,J,Y,k,Z]=cainv(Sys1,Alfa,Beta,flag);
-Sys_new=ss2ss(Sys,X);
-ns=dims(3);Jnew=X'*J;J2=Jnew(ns+1:$,:);
-[Anew,Bnew,Cnew,Dnew]=abcd(Sys_new);
-A22=Anew(ns+1:$,ns+1:$);C22=Cnew(:,ns+1:$);
-B22=Bnew(ns+1:$,not_reject);D22=Dnew(:,not_reject);
-Sys22=syslin(Sys('dt'),A22,B22,C22,D22);
-UIobs=observer(Sys22,J2);
-//
-C1new=C1*X;
-D11=D1(:,reject);D21=Dnew(:,reject);
-C11=C1new(:,1:ns);C21=Cnew(:,1:ns);
-//N s.t. [I,N]*[C11 D11;C21 D21]=[0,0] 
-N=lowlevel();
-mprintf(gettext("%s: Residual norm = "),"ui_observer");
-mprintf(norm([eye(size(N,1),size(N,1)),N]*[C11,D11;C21,D21]));
-D12=D1(:,not_reject);C12=C1new(:,ns+1:$);
-UIobs('C')=[C12+N*C22];UIobs('D')=[D12+N*D22,-N];
+  [LHS,RHS]=argn(0);
+  if RHS==6 then Beta=-1;end
+  if RHS==5 then Beta=-1;Alfa=-1;end
+  if RHS==4 then Beta=-1;Alfa=-1;flag='st';end
+  if RHS==3 then Beta=-1;Alfa=-1;flag='st';D1=[];end
+  if size(C1,2) ~= size(Sys('A'),1) then 
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                          "state dimension of #%d must be equal to the column dimension of #%d.\n"),..
+                  "ui_observer",1,3,1,3))
+  end
+  if size(D1,2) ~= size(Sys('B'),2) then 
+    error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: "+..
+                          "input dimension of #%d must be equal to the column dimension of #%d.\n"),..
+                  "ui_observer",4,1,4,1))
+  end
+  not_reject=1:size(Sys,'c');not_reject(reject)=[];
+  Sys1=Sys(:,reject);      //A,B1,C2,D21
+  [X,dims,J,Y,k,Z]=cainv(Sys1,Alfa,Beta,flag);
+  Sys_new=ss2ss(Sys,X);
+  ns=dims(3);Jnew=X'*J;J2=Jnew(ns+1:$,:);
+  [Anew,Bnew,Cnew,Dnew]=abcd(Sys_new);
+  A22=Anew(ns+1:$,ns+1:$);C22=Cnew(:,ns+1:$);
+  B22=Bnew(ns+1:$,not_reject);D22=Dnew(:,not_reject);
+  Sys22=syslin(Sys('dt'),A22,B22,C22,D22);
+  UIobs=observer(Sys22,J2);
+  //
+  C1new=C1*X;
+  D11=D1(:,reject);D21=Dnew(:,reject);
+  C11=C1new(:,1:ns);C21=Cnew(:,1:ns);
+  //N s.t. [I,N]*[C11 D11;C21 D21]=[0,0] 
+  N=lowlevel();
+  mprintf(gettext("%s: Residual norm = %g\n"),"ui_observer",norm([eye(size(N,1),size(N,1)),N]*[C11,D11;C21,D21]));
+  D12=D1(:,not_reject);C12=C1new(:,ns+1:$);
+  UIobs('C')=[C12+N*C22];UIobs('D')=[D12+N*D22,-N];
 
 endfunction
+
 function N=lowlevel()
-ww=[C11 D11;C21 D21];
-[xx,dd]=rowcomp(ww);
-K=xx(dd+1:$,:);
-colN=size(C21,1);rowN=size(C11,1);
-if size(K,1) > rowN then K=K(1:rowN,:);end
-Kleft=K(:,1:size(K,1))
-if size(Kleft,'*')==1 & abs(Kleft) <1.d-8 then 
-N=[];error(msprintf(gettext("%s: Bad conditionning.\n"),"ui_observer"));return;end
-if rcond(Kleft) <= 1.d-10 then 
-       warning(msprintf(gettext("%s: Bad conditionning.\n"),"ui_observer"));
-       K1=pinv(Kleft)*K;N=K1(:,size(K,1)+1:$);return
-end
-K1=inv(Kleft)*K;   //test conditioning here!
-N=K1(:,size(K,1)+1:$)
+  ww=[C11 D11;C21 D21];
+  [xx,dd]=rowcomp(ww);
+  K=xx(dd+1:$,:);
+  colN=size(C21,1);rowN=size(C11,1);
+  if size(K,1) > rowN then K=K(1:rowN,:);end
+  Kleft=K(:,1:size(K,1))
+  if size(Kleft,'*')==1 & abs(Kleft) <1.d-8 then 
+    N=[];
+    error(msprintf(gettext("%s: Bad conditionning.\n"),"ui_observer"));
+  end
+  if rcond(Kleft) <= 1.d-10 then 
+    warning(msprintf(gettext("%s: Bad conditionning.\n"),"ui_observer"));
+    K1=pinv(Kleft)*K;N=K1(:,size(K,1)+1:$);return
+  end
+  K1=inv(Kleft)*K;   //test conditioning here!
+  N=K1(:,size(K,1)+1:$)
 endfunction