How can I use the Matlab function ziegler() in m-file?

I have run the given program which include a function named ziegler(key,vars) as shown below-
s=tf('s');
G=10/(s+1)/(s+2)/(s+3)/(s+4)
step(G);
k=dcgain(G)
L=0.76; T=2.72-L;
[Gc1,Kp1]=ziegler(1,[k,L,T,10])
G_c1=feedback(G*Gc1,1);
As I try to run this program an error is showing as-
??? Undefined function or method 'ziegler' for input arguments of type 'double'.
Can anyone solve this problem...
Thanks!

 Réponse acceptée

Wayne King
Wayne King le 28 Nov 2012
Modifié(e) : Wayne King le 28 Nov 2012
You need to save that file, zeigler.m, in a folder that is on the MATLAB path, or just add the folder you have the M-file saved in to the path.
For example, assume you have the file saved in c:\mfiles, then use
>>addpath 'c:\mfiles'
to add that to the MATLAB path, or use
>>pathtool
Once you have added it, you should be able to enter
>>which ziegler
and see that MATLAB recognizes where the M-file is.

4 commentaires

ALOKE
ALOKE le 29 Nov 2012
I have this method but it is still showing error as
*??? Attempt to execute SCRIPT ziegler as a function:
C:\Users\Aloke\Documents\MATLAB\ziegler.m*
can you please tell me that ziegler() belongs to which toolbox?
ziegler.m is not a MathWorks' function. How are you trying to call it from the command line?? Make sure it is on the path as you have done and then call it as you have done above
>>[Gc1,Kp1]=ziegler(1,[k,L,T,10]);
Where did you obtain your ziegler.m from ?
ALOKE
ALOKE le 29 Nov 2012
I understand the your solution. Thanks

Connectez-vous pour commenter.

Plus de réponses (2)

Shahzeb Awan
Shahzeb Awan le 11 Jan 2023
Modifié(e) : Walter Roberson le 12 Jan 2023
add following two function in your path:-
function [Gc,Kp,Ti,Td,H]=ziegler(key,vars)
Ti=[]; Td=[]; H=1;
if length(vars)==4,
K=vars(1); L=vars(2); T=vars(3); N=vars(4); a=K*L/T;
if key==1, Kp=1/a;
elseif key==2, Kp=0.9/a; Ti=3.33*L;
elseif key==3 || key==4, Kp=1.2/a; Ti=2*L; Td=L/2; end
elseif length(vars)==3,
K=vars(1); Tc=vars(2); N=vars(3);
if key==1, Kp=0.5*K;
elseif key==2, Kp=0.4*K; Ti=0.8*Tc;
elseif key==3 || key==4, Kp=0.6*K; Ti=0.5*Tc; Td=0.12*Tc;
end
elseif length(vars)==5,
K=vars(1); Tc=vars(2); rb=vars(3); N=vars(5);
pb=pi*vars(4)/180; Kp=K*rb*cos(pb);
if key==2, Ti=-Tc/(2*pi*tan(pb));
elseif key==3||key==4, Ti=Tc*(1+sin(pb))/(pi*cos(pb)); Td=Ti/4;
end
end
[Gc,H]=writepid(Kp,Ti,Td,N,key);
end
function [Gc,H]=writepid(Kp,Ti,Td,N,key)
switch key
case 1, Gc=Kp;
case 2, Gc=tf(Kp*[Ti,1],[Ti,0]); H=1;
case 3, nn=[Kp*Ti*Td*(N+1)/N,Kp*(Ti+Td/N),Kp];
dd=Ti*[Td/N,1,0]; Gc=tf(nn,dd); H=1;
case 4, d0=sqrt(Ti*(Ti-4*Td)); Ti0=Ti; Kp=0.5*(Ti+d0)*Kp/Ti;
Ti=0.5*(Ti+d0); Td=Ti0-Ti; Gc=tf(Kp*[Ti,1],[Ti,0]);
nH=[(1+Kp/N)*Ti*Td, Kp*(Ti+Td/N), Kp];
H=tf(nH,Kp*conv([Ti,1],[Td/N,1]));
case 5, Gc=tf(Kp*[Td*(N+1)/N,1],[Td/N,1]); H=1;
end
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by